PDA

View Full Version : how to use the transform matrix?



jyoung77
04-28-2003, 04:39 PM
Hi,

I want to know the new position of a point after it is rolated (around the origin) and then translated. Can the following code do this job for me? Please help. Thanks.

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

// rotate first and then translate
glTranslatef(...); // reverse the sequence to get the right xform
glRotatef(fAngle, ...);

GLfloat xForm[16];
glGetFloatv(GL_MODELVIEW_MATRIX, xForm);

float v1[4], v2[4]; // v2 is the new position for v1
...
for (i=0; i<4; i++)
{
v2[i] = 0.;
for (j=0; j<4; j++)
v2[i] += xForm[i*4+j]*v1[j];
// or v2[i] += xForm[j*4+i]*v1[j]; ????????
}

...