Rotations

Hi! i’m have an some objects in the world in Odejava…
how i can convert rotation matrix of body for OpenGL???

first i’m get this matrix:

Matrix3f m = car.getRotations(new Matrix3f());

finally i’m have matrix 3x3 but i’m don’t know or don’t understand how apply it for OpenGL program like:

gl.glRotatef(rotX,1,0,0);
gl.glRotatef(rotY,0,1,0);
gl.glRotatef(rotZ,0,0,1);

You can apply that matrix directly as a general transformation. (don’t know the API method name, though)

Get the matrix-elements and store them in a float array. After that you can apply the transformation using glMultMatrixf(). But be careful to store the array-elements in column major order:


Matrix3f m = car.getRotations(new Matrix3f());
float[] mv= new float[]
{
  m.m00, m.m10,  m.m20,  m.m30,  
  m.m01, m.m11,  m.m21,  m.m31,  
  m.m02, m.m12,  m.m22,  m.m32,  
  m.m03, m.m13,  m.m23,  m.m33  
};
gl.glMultMatrixf(mv);

cylab, thanks but m.m30 does not exist…and matrix3f don’t have third coordinate…they have m00, m10, m20,m01,m11…e.t.c. :-\

Yeh! all done!:slight_smile:
it must be:


Matrix3f m = engine.car.getRotation(new Matrix3f());
Matrix4f mat = new Matrix4f();
mat.set(m);
float[] rot = new float[]{
        mat.m00, mat.m10, mat.m20, mat.m30,
        mat.m01, mat.m11, mat.m21, mat.m31,
        mat.m02, mat.m12, mat.m22, mat.m32,
        mat.m03, mat.m13, mat.m23, mat.m33
};

You don’t need to create a Matrix4f object. It is simple to do the transformation 3f -> 4f for a rotation :

Matrix3f m = car.getRotations(new Matrix3f());
float[] mv= new float[]
{
  m.m00, m.m10,  m.m20,  0.0f,  
  m.m01, m.m11,  m.m21,  0.0f,  
  m.m02, m.m12,  m.m22,  0.0f,  
  0.0f, 0.0f,  0.0f,  1.0f  
};
gl.glMultMatrixf(mv);

and all be ok? ::slight_smile:

Yes should be, see http://www.sjbaker.org/steve/omniv/matrices_can_be_your_friends.html. You can see, that the last row and last column in a 4x4 matrix is not involved in rotation.

thanks! good article;)