getDirection for non-camera object

Currently Im trying to find the direction a physics node is facing but i'm having a hard time figuring out how I can achieve this. With a Camera you can simply do a .getDirection() and you're off, with any other object its a bit more difficult. I tried getting the Quaternion rotation and messed arround with it's values but that didnt give me any insight how it actually works. Converting it to a Matrix3f helped somewhat clarifying how it works but whatever values I give my node with the fromAngleAxis method, I can't relate it to the Matrix3f nor Quaternion.



Since im horrible with math I have no clue if I'm actually on the right track and hope someone (Duenez? :P) could give some tips how to achieve what I want.

My goal is a getDirection method that returns a Vector3f giving me a x,y and z value between -1 and 1, just like the Camera's method.



Any help is appreciated,

thanks!


i think you are looking for


Vector3f direction = spatial.getLocalRotation().getRotationColumn(2);


That is, if your object is in Y-UP coordinate Space, which is default in jME.
But because my math sucks, i can't explain more :)

Well, to further elaborate… transformation matrices are composed of 3 vectors (column vectors) that represent the three new vectors that are obtained from transforming the three canonical ((1,0,0), (0,1,0) and (0,0,1)) vectors to those new vectors. You can represents any linear transformation in this way… That is, take the three canonical vectors and move them to whatever you need the other vectors to be.



Since this matrix will have the 3 new vectors as columns, the first column will be whatever your new (1,0,0) (or UNIT_X) will be after transform, the second the UNIT_Y and the third the UNIT_Z which is the direction the camera is looking at, by definition in a Y up coordinate system.



Hope it helps.

I think I know what you mean… basically Rotationcolumn 0 is UNIT_X, 1 is UNIT_Y and 2 is UNIT_Z and I would be interested in 2 because Z is depth, meaning the direction the object is "looking" so to speak.



It's still a bit hard to comprehend because… what exactly mean the three values inside Vector3f of a given UNIT?



Anyhow, the answers in this topic have been very helpfull!

Thanks!


i knew 2 will give u the object's facing direction, but what will 0 and 1 give u?

neakor said:

i knew 2 will give u the object's facing direction, but what will 0 and 1 give u?

the left and up directions respectively

Darklord said:

what exactly mean the three values inside Vector3f of a given UNIT?


The direction of the transformed corresponding UNIT vector, in terms of the canonical units.