PDA

View Full Version : how can i get the vertex after rotation?



lichongbin
06-19-2011, 07:08 PM
I set the GL_MODELVIEW matrix:
glMatixMode(GL_MODELVIEW);
and there is a vertex(x1, y1, z1), after some rotation, how can i get the new vertex's coord without extro calculation? Is there an interface which can be used?

vivek vyas
06-19-2011, 09:10 PM
you can do it like in this way
GLfloat mat[16];//Global
make your own function(like MulMat) which multiply matrix with 3 Co-Ordinates with taking care of OpenGL Matrix Order

glPushMatrix();
glLoadIdentity();
Rotatef(same argument as applied for vertex data);
glGetFloatv(GL_MODELVIEW_MATRIX,mat);
glPopMatrix();
glPushMatrix();
//your scene
glPopMatrix();
and then
MulMat(x1,y1,z1,mat);

and also this link if helpful
http://www.gamedev.net/topic/472383-math-library-for-opengl/

lichongbin
06-20-2011, 12:03 AM
"MulMat" is a standard API?
I do it like this:
glRotatef(2.0f, m_fr[0], m_fr[1], m_fr[2]);
glGetFloatv(GL_MODLEVIEW, modalView);
x = modalView[0] * m_fv[0] + modalView[1] * m_fv[1] + modalView[2] * m_fv[2] + modalView[3];
y = modalView[4] * m_fv[0] + modalView[5] * m_fv[1] + modalView[6] * m_fv[2] + modalView[7];
z = modalView[8] * m_fv[0] + modalView[9] * m_fv[1] + modalView[10] * m_fv[2] + modalView[11];

m_fv[0] = x;
m_fv[1] = y;
m_fv[2] = z;

Is it right?

vivek vyas
06-20-2011, 01:40 AM
not it is a function and definition is depends on you
better to say vecXmat
take in this way


void GetCol(float Mat[16],float (&Res)[4],int c)
{
assert(c<=4);
for(int r=0;r<4;r++)
{
Res[r] = Mat[r+4*c];
}
}

void VecxMat(float Mat[16],float Vec[4],float (&amp;Res)[4])
{
float Col[4];
for(int i=0; i<4;i++)
{GetCol(Mat,Col,i);
Res[i] = Vec[0]*Col[0]+Vec[1]*Col[1]+Vec[2]*Col[2]+Vec[3]*Col[3];
}

}


use any algorithm and method
but the output must show
ranging
-x to x
and for y and z
and also as from your code
you are changing m_fv
try to do not put glRotate again
see whether output is of rotating or not