matrix4 to quaternion

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Crimson
Gnoblar
Posts: 5
Joined: Sun Aug 24, 2014 6:19 pm

matrix4 to quaternion

Post by Crimson »

hi I am busy integrating newton physics into my
project , I know there is an ogrenewt wrapper available but I want to use this project with my
own integration.

so I am stuck at using quaternions , I have never
used them in my life before ogre ,I do not know
how to go from a quaternion to a matrix of 16 floats
and back from a matrix of 16 floats to a quaternion
I can apply to rotate and move my node .

I have looked at how it was done on ogrenewt ,okay
fine ,I used the functions in the source to go from
thr quaternion to a matrix into newton and found
how to go from newton back to an ogre matrix4

but ,how do I use my matrix4 to adjust my node
position and rotation ?

I do not understand how to apply the matrix to the node position and rotation because they are quaternions .
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: matrix4 to quaternion

Post by madmarx »

Hi!
how do I use my matrix4 to adjust my node position and rotation ?
From the Matrix4x4 you can extract the top left 3x3 matrix. It contains the rotation and scale informations.

If scale is nothing special (scale == 1), then you can create quaternion from this matrix by using :
Quaternion::FromRotationMatrix (const Matrix3 &kRot)

Then you can rotate or setOrientation on your scenenode with the quaternion.

To get the position : take the last column of the 4x4 matrix, and divide it by its 'w'( x/w, y/w, z/w) and you keep only x,y,z to make a position vector.Then use setPosition on the node.

Best regards,

Pierre
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Post Reply