Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: How to make a ship bank or tilt towards center of rotation along a spline path  (Read 1410 times)
willyg
Community Member
*
Posts: 31


« on: November 07, 2010, 11:07:33 PM »

 Huh   I know this is probably something really simple that I'm overlooking but I am at a standstill and I need some help.  What I've managed to do is to create some random path nodes and I use a spline path to make a spaceship move smoothly along the new path that is created.  As soon as the ship comes within 50 units of the last node a new set of random nodes is generated.  That's working pretty good.  But what I would like to do is have the spaceship bank or tilt (increasing the banking angle with a sharper curve and less bank with a less sharp turn) a certain amount of degrees towards the center of the radius of curvature.  I'm thinking that the rotation will need to be around the local axes of the forward facing vector of the ship.  Seems like the amount of bank angle will depend upon the sharpness of the turn and its radius.  Any suggestions or books that may cover this topic is appreciated.
Logged
micmanos
Customers
Community Member
*****
Posts: 526


WWW
« Reply #1 on: November 10, 2010, 10:18:01 AM »

Search for 3D CatmulRom spline in the math class. The problem is simply how to calculate the roll angle relative to the forward vector your ship is moving. This math method will do it for you.

If you have a 4 point 3D CatMullRom spline (ABCD) and you move from point B to C (A and D are only direction vectors) you'll find that this method not only returns the position but it also rolls your ship accordingly. This effectivelly eliminates the yawing axis which is very realistic.

Don't have time to explain, .... search it. Good luck.
Logged

jviper
Community Member
*
Posts: 2130

Discipline in training


« Reply #2 on: November 10, 2010, 05:01:57 PM »

Sounds like you want to calculate curvature. Yeah there is no reason to try and explain that here. That involves calculus. You would use the parametrization of the CatmulRom Spline formula (There is a formula that gives you any point in between two points given their tangent vectors), then use calculus to calculate curvature.

Fortunately there may be an alternative. This might be a physics scenario, so look up centripetal/centrifugal forces. That should give you an idea on how to emulate this.
Logged

JAbstract.....Don't just imagine, make it happen!
willyg
Community Member
*
Posts: 31


« Reply #3 on: November 11, 2010, 11:31:14 PM »

Thanks micmanos and jviper for your helpful suggestions.

I tried to use the 3d catmullrom function but I'm not doing something right.  I keep getting the "only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions" error in VB6.

According to the TV3D 6.1 documentation you define the math function as below:

TVMathLibrary.TVVec3CatmullRom(result As D3DVECTOR, V1 As D3DVECTOR, V2 As D3DVECTOR, v3 As D3DVECTOR, v4 As D3DVECTOR, s As Single)

I basically defined a D3DVECTOR (newvec) and set it equal to the above.

Example... newvec = mTVMath.TVVec3CatmullRom(result, v1, v2, v3, v4, s)

Would anyone have an example code snippet just to show how to correctly use this math function (i'm using VB6 and TV3D 6.3)? 

Logged
micmanos
Customers
Community Member
*****
Posts: 526


WWW
« Reply #4 on: November 12, 2010, 02:00:25 AM »

It's probably in your declarations of TV3DVEC, tvMATH or somewhere else.

A little rusty on vb6 ...

dim tvMATH as TV.TVMATHLIBRARY
tvMATH = new TV.TVMATHLIBRARY

dim vOUT as TV3DVECTOR
dim v1 as TV3DVECTOR
dim v2 as TV3DVECTOR
dim v3 as TV3DVECTOR
dim v4 as TV3DVECTOR

vOUT = new TV.TV3DVECTOR
v1 = new TV.TV3DVECTOR
v2 = new TV.TV3DVECTOR
v3 = new TV.TV3DVECTOR
v4 = new TV.TV3DVECTOR

v1.x =...
v1.y= ..
.
.
.

'The "step" normally ranges from 0 to 1 (returns point between v2 and v3).
'It can however take values from -1 to 2 which covers between v1 and v4.
tvMATH.TVVec3CatmullRom(vOUT, v1, v2, v3, v4, step)

NOTE: Can't remember if you have to use VARPTR(vOUT) to pass the vOUT by reference !!! (Please switch to .NET, it's a rather painful transition with moments of intense suicidal desire, but it's well worth it as it will bring you to the wonderful nightmare of real OOP).


ALSO ... Don't forget or overlook the tvPATH class. I didn't give it too much attention but it's proven to be a real gem for new people as it literally solves many moving problems with just a few lines of code.
« Last Edit: November 12, 2010, 02:03:55 AM by micmanos » Logged

willyg
Community Member
*
Posts: 31


« Reply #5 on: November 14, 2010, 11:48:26 PM »

Thanks Micmanos, I'll give it another try this upcoming weekend.

If I'm successful, would anyone be interested in some type of wiki tutorial on creating a 3d catmullrom spline path?  For now it would be in VB6, but someone could convert it to VB.Net or some other programming languge later on. 
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks