PDA

View Full Version : How to draw 3d unit axes in opengl while rotati???



mahesh.bhoir
10-31-2009, 12:45 AM
Hi,

I am displaying 3D models using opengl and VC++.
I have implemented code to rotate, move, zoom the model by moving camera (using gluLookAt() )
Now I want to add one set of 3D XYZ unit axes in front of camera view port(at left bottom screen), but when I tried to rotate or zoom the model the unit axes also rotates or zoom along with model.
How I can make xyz unit axes lie at same position while rotating model.

Please help me :((

todayman
10-31-2009, 07:38 AM
You need to put glPushMatrix() and glPopMatrix() around the code that does the rotation, but not around where you draw the axes. glPushMatrix() pushes the current matrix onto the stack, and glPopMatrix() pops from the stack and restores the matrix. So you want to do something like:

drawAxes();
glPushMatrix();
rotate();
drawStuff();
glPopMatrix();

Assuming, of course, that you're usgin OpenGL <3.0. If you're using OpenGL 3, then you implement the same idea, but using your shaders.

mahesh.bhoir
11-02-2009, 09:11 PM
Actually I have written separate functions to rotate and zoom and pan view, and in that after doing the corresponding operation I have called one refresh view function which just uses glcalllist() to draw scene. Then exactly where I should put the draw axes function() ???

Brolingstanz
11-03-2009, 12:02 PM
"Then exactly where I should put the draw axes function() ???"

somewhere between frisby() and dingle() ?

Or perhaps there's more to this question than meets the eye.

todayman
11-03-2009, 12:09 PM
You are applying some transformation to the model. You can store that however you want. For each frame, you need to draw the axes, then apply the transformation to the model and draw the model.

Something like this might work:

glPushMatrix(); // push the transformed matrix onto the stack
glLoadIdentity(); // and make sure the matrix is right for the axes
drawAxes();
glPopMatrix(); // back to the transformed matrix
drawStuff();

mahesh.bhoir
11-03-2009, 08:48 PM
Thanks for ur reply.
I have tried to reset the modelview matrix and projection matrix and I am successful to display axes 90 percent, the remaining problem is that while rotating the 3d model flickers (at start zoom - in and at end at normal size and position).

I have tried this code after finishing of rest 3d model drawing :

glMatrixMode(GL_PROJECTION);
glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
glLoadIdentity(); // reset projection matrix

GLdouble gldAspectRatio = (GLdouble) ViewportSize.right/(GLdouble) ViewportSize.bottom;

glOrtho ( pViewVolumeAxe[0], pViewVolumeAxe[1],
pViewVolumeAxe[2]/gldAspectRatio,
pViewVolumeAxe[3]/gldAspectRatio,
pViewVolumeAxe[4], pViewVolumeAxe[5] );

glMultMatrixd(projMatrix);

glMatrixMode(GL_MODELVIEW);
glGetDoublev (GL_MODELVIEW_MATRIX ,modelMatrix);
glLoadIdentity(); // reset model view matrix

// do reverse translation as to keep axes at same position
glTranslated(-modelMatrix[12], -modelMatrix[13], -modelMatrix[13]);

glMultMatrixd(modelMatrix);

// translate whole setup to model center currently I am // displaying at origin(0,0,0)
glPushMatrix();
glTranslatef(fXTrans, fYTrans, fZTrans);

// then all axes draw stuff

mahesh.bhoir
11-26-2009, 02:16 AM
the above code works fine... when I manually restored the other model view matrix state after finishing of drawing. It's working fine.

mahesh.bhoir
11-26-2009, 02:58 AM
Now I have moved the draw axes stuff in one draw list and then using just call list to draw it. It works in debug mode of program, but it does not works in release mode of program... Please give me solutions for it....

Also I have one question , can we do some arithmetic operation (such as creation local variables, i have created those to fed the relative dimension to draw the axis), the creation of quadratic equation [pObj = gluNewQuadric()], Is all this allowed in opengl drawing lists ??? OR only drawing operations allowed ???