PDA

View Full Version : How do I display a 3D orientation axis (XYZ)



jmikhael
07-18-2003, 12:40 PM
Does anyone know how to display a 3D orientation axis that will rotate with your model but stay in front of the model in a particular corner of the screen? Or know where I can go to find information on doing this?

john
07-18-2003, 04:42 PM
Hello,

the easiest way to get the effect you want is to take a copy of the modelview matrix and put zeros in the first three rows of the fourth column. That will orientate your axis by the world rotation but not translate it, so you can translate the axis indepenendly. Some pseudo-code:



drawAxis()
{
GLdouble mv[16]=getModelviewMatrix();
mv[3]=mv[3+4]=mv[3+8]=0.0;
glPushMatrix();
glLoadIdentity();
glTranslatef(-5.0, -5.0, 0.0); // position on screen
glMultMatrix(mv); // orientation
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glEnd();
glPopMatrix();
}

the alternative way is to draw the orientated vectors by pulling them out of the matrix (whcih is how I do it), but this has the same effect.

cheers
John