PDA

View Full Version : Another rotation post ;P



Dexter
01-01-2002, 10:45 AM
I've written following code to render in my 3d mesh editor 3 small axis to help artist to know how they are rotating the camera.




void CCAMERA::RenderViewMatrix()
{
//Saves old stuff
float ovMatrix[16];
int oViewport[4];

glGetFloatv(GL_MODELVIEW_MATRIX,ovMatrix);
glGetIntegerv(GL_VIEWPORT,oViewport);

//Creates the viewport (at older_maxs - 50),reset matrix and renders rotation vectors
//glViewport(oViewport[2] - 50,oViewport[3] - 50,oViewport[2],oViewport[3]);
glViewport(0,0,50,50);
gluPerspective(45.0f,50/50,0.1f,100.0f);

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

glBegin(GL_LINES);
glColor3f(0.0f,0.0f,1.0f);
//X
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
//Y
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
//Z
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,1.0f);
glEnd();

//Restores old stuff
glViewport(oViewport[0],oViewport[1],oViewport[2],oViewport[3]);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}



Now, it renders axis ok, but how to render them rotated according to MODELVIEW rotation?
Thx http://www.opengl.org/discussion_boards/ubb/smile.gif))

Dexter

[This message has been edited by Dexter (edited 01-01-2002).]

Tolga Dalman
01-01-2002, 04:43 PM
please specify, what exactly do you mean?
you just have to change into

glMatrixMode(GL_MODELVIEW)

and then you perform your rotation with glRotate().

l8ers,
Tolga.

zed
01-01-2002, 06:47 PM
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
---> do the camera stuff eg gluLookAt(..)

glBegin(GL_LINES);
glColor3f(0.0f,0.0f,1.0f);
//X
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f)

[This message has been edited by zed (edited 01-01-2002).]