PDA

View Full Version : Rotation and Translation woes..



dan81
10-18-2005, 12:14 AM
Hi everyone,

I have this problem.. hope u guys can provide me with some insights:

I have a 3D model, which must be able to be rotated, translated and scaled on mouse movement. I have added into my code the necessary interaction code. whenever i scale and rotate my model, there is no problem. whenever i translate and scale my model, there is no problem. But whenever i try to rotate my model after i translate it, my model will rotate not about its object coordinates, but about some arbitary world coordinates. I want it to rotate about its own object coordinates after translation. my partial code is as follows:

Translate * Rotate * Scale, or -->

/*translate*/
glTranslated(m_XTranslate,m_YTranslate,0);

/*rotate*/
if(firsttime==0)
{
glRotated(m_AngleX, 1, 0, 0);
glRotated(m_AngleZ, 0, 0, 1);
glRotated(m_AngleY, 0, 1, 0);

glGetFloatv(GL_MODELVIEW_MATRIX, tempMatrix);
}

firsttime = 1;

if(firsttime==1)
{
glRotated(m_AngleX, 1, 0, 0);
glRotated(m_AngleZ, 0, 0, 1);
glRotated(m_AngleY, 0, 1, 0);
m_AngleX = m_AngleY = m_AngleZ= 0;
glMultMatrixf(tempMatrix);
glGetFloatv(GL_MODELVIEW_MATRIX, tempMatrix);
}
/*scale*/
glScaled(m_scale, m_scale, m_scale);

This is really gettin on my nerves.. I hope someone out there can help me? thanks a lot..

dan81
10-18-2005, 12:16 AM
to add to the above, i have tried various transformation orders, but nothing seems to work.

Any insights?
Thanks!

Relic
10-18-2005, 12:59 AM
Hardly an advanced topic.
Read the OpenGL Programming Guide (redbook.pdf to be found on the internet) chapter "Thinking about Transformations".
Search for glPushMatrix and glPopMatrix.
Examples using it in the book explain how to rotate about an arbitrary point in space.