|
Post by kjelle69 on Feb 9, 2005 10:12:24 GMT 1
What does this function do mathematically and for what purpose, transform vector by rotation matrix?
From documentation, (I will change the syntax from translate to transform)
NDB_TranslateVector syntax: NDB_TranslateVector [vec_num] vec_num index of vector (integer 1-4) *optional returns: nothing. Comments: translates the specified vector by the rotation matrix ( the temp matrix is used, setup a rotation matrix with the NDB_BuildMatrix command ).
|
|
|
Post by Kjelle69 on Feb 9, 2005 10:53:37 GMT 1
basically there are 4 commands, which can be put in 2 groups:
(ROTATION) NDB_RotateVector / NDB_UnrotateVector
(TRANSLATION) NDB_TransformVector / NDB_UntransformVector
think about these commands like this....
(ROTATION) the vector you pass in represents a direction in LOCAL space. for example, a velocity of (1,0,0) which means a velocity in the local X direction. now let's say you need to know this in GLOBAL coordinates. you would do this:
NDB_NewtonBodyGetMatrix ShipBody NDB_SetVector 1,0,0 NDB_RotateVector 1 newx# = NDB_GetVector_X() newy# = NDB_GetVector_Y() newz# = NDB_GetVector_Z()
newx,newy,newz are now pointing along the X axis of the body, but in world space.
(TRANSFORMATION) This is similar, but the vector does not represent a direction, but a point in local space. for example, let's say you have a jetpack at the point (0,2,-5) on your model. now your model is somewhere else in space, rotated, moved, etc. what is the global location of the jetpack? do this:
NDB_NewtonBodyGetMatrix PlayerBody NDB_SetVector 0,2,-5 NDB_TransformVector 1 newx# = NDB_GetVector_X() newy# = NDB_GetVector_Y() newz# = NDB_GetVector_Z()
newx,newy,newz are the global location of the jetpack.
in other words, these commands allow you to get from LOCAL to GLOBAL space, and back again. use the "un" versions of the commands to do the exact opposite.
for example say you detected a ray collision on a body. of course the RayCast system returns global coordinates. but you want to know this point in LOCAL coordinates of the body. you use the UntransformVector command.
know you can probably understand how my object dragging system works in the basic Newton demos. I cast a ray, and if it hits a body, I remember the body, and figure out where the user clicked in LOCAL space. then, while the user is dragging, I find the distance between the mouse and the point on the body, and apply a spring force between them. this makes use of the above commands, and would be VERY difficult without it.
hope that helps explain.
|
|
|
Post by kjelle69 on Feb 9, 2005 14:59:26 GMT 1
Those are pretty useful transformations I say ! I think I'll add this description in the Wrapper documentation !
|
|
|
Post by IceNine on Apr 19, 2005 23:28:27 GMT 1
'Lo !
Great physics library/wrapper, thanks much for making it accessible to us DBP'ers. :-)
On topic, it seems that both of these... NDB_RotateVector 1 NDB_RotateVector ...return invalid argument complaints when compiling. This however... NDB_RotateVector 1,1 ...works fine. I'm thinking it needs you to specify which matrix to use as well as which vector, and the alternate fewer arg versions are somenow not kicking in? ( In case it matters, default IDE, 5.8 final )
|
|
|
Post by kjelle69 on Apr 20, 2005 21:51:15 GMT 1
Hi there IceNine! And welcome to the Forum ! ;D You know, you are right about the Rotatevector command, I looked up the wrapper code and found the following: EXPORT void NDB_RotateVector( int src, int dest ) { vector[dest] = matrix.RotateVector( vector[src] ); }
This is the only occurence of the rotatevector command, which means that it is somewhat faulty described in the docs, (I will correct that). Anyway, you have to specify both the source and the destination of the Rotated vector, which means that values of 1,1 will transform Vector 1. Values of 1,2 will transform vector one and put it into vector 2 and Keep vector 1 untouched. Good if you want to keep the initial values aswell.
|
|
|
Post by IceNine on May 2, 2005 4:53:34 GMT 1
Thanks!
Read the just after you posted it, neglected to say thanks though, so I thought I'd fix that. :-)
|
|
Ifi
New Member
Posts: 10
|
Post by Ifi on Mar 7, 2006 15:07:10 GMT 1
Argh, And I calculatet the whole translation/roation matrix over 3 papers for this transformation and now I read this If i'm understanding this rightly: rotate/transfom = LOCAL to GLOBAL vectors/positions unrotate/untransform = GLOBAL to LOCAL vectors/positions If i Have a car ans want to know the drivingspeed i have to unrotate the GetVelocity vector and put the z component, right? Ciao Ifi [Edit] hmpf, i should read all prevous comments *g*
|
|