Newbie Matrix question

I have built a rotation matrix. When I multiply each vertex by hand and then do my gl.glVertex3f() calls, then it works for a simple test case.

Do I have to do all this work by hand or is there some way to give OpenGL my rotation matrix and tell it to multiply each vertex vector by the rotation matrix? I’ve tried playing around with the gl.glLoadMatrixf( myRotMatrix ) calls but I can’t seem to get it to work.

Code below illustrates what im doing.

// rotate triangle float[] rm = mm.joints[0].rotMatrix; float v11 = (rm[0] * v1[0]) + (rm[4] * v1[1]) + (rm[8] * v1[2] ) + rm[12]; float v12 = (rm[1] * v1[0]) + (rm[5] * v1[1]) + (rm[9] * v1[2] ) + rm[13]; float v13 = (rm[2] * v1[0]) + (rm[6] * v1[1]) + (rm[10] * v1[2] ) + rm[14];
    float v21 = (rm[0] * v2[0]) + (rm[4] * v2[1]) + (rm[8] * v2[2] ) + rm[12];
    float v22 = (rm[1] * v2[0]) + (rm[5] * v2[1]) + (rm[9] * v2[2] ) + rm[13];
    float v23 = (rm[2] * v2[0]) + (rm[6] * v2[1]) + (rm[10] * v2[2] ) + rm[14];

    float v31 = (rm[0] * v3[0]) + (rm[4] * v3[1]) + (rm[8] * v3[2] ) + rm[12];
    float v32 = (rm[1] * v3[0]) + (rm[5] * v3[1]) + (rm[9] * v3[2] ) + rm[13];
    float v33 = (rm[2] * v3[0]) + (rm[6] * v3[1]) + (rm[10] * v3[2] ) + rm[14];

// now do my gl.glVertex3f() calls.

gl.glMultMatrixf adds your matrix to the currently active one, and I think there’s a gl.glLoadMatrix as well to set it.

Anyhoo, you can always use glTranslatef and glRotatef to move and rotate without using a matrix.

Thanks, that put me on the right track.

I tried using gl.glMultMatrixf( rm ). It almost worked, rotated it in the opposite direction. So then I tried gl.glMultTransposeMatrixf( rm ) and it did just what I was doing by hand. I guess I have the indexing of my rotation matrix a little off from what OpenGL is expecting.

The thing is that opengl works with column major matrices, then you have to transpose them. If you want to save cpu time, create matrices directly as column major ones.