Jump to content
  • Advertisement
Sign in to follow this  
opendep

OpenGL Restricted translation and rotation

This topic is 3761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to display coordinate axes at the top left corner of the window along with the object using openGL, GLUT and GLUI. The coordinate axes should rotate about a fixed point (point of intersection of the three axes) but should not translate along with the object. I am using GLUI for rotation and translation. I used GL_LINES to display the axes but the axes translate too along with the object. can anyone help me with this..!! Thank you.

Share this post


Link to post
Share on other sites
Advertisement
If I have correctly understand you wish to display the XYZ reference axis on a corner of the rendering window and you wish it to rotate accordingly with the object rotation but it must stay at the same place when the object is translated.

If so, it seems to be a problem of pushing / popping the current ModelView matrix.
Can you please post the code you are using?

Share this post


Link to post
Share on other sites
Hi,
Thats exactly what i wish to do.. My code is

if(gui_variables->axes)
{
glPushMatrix();
glMultMatrixf (rotation_matrix);
draw_axes();
glPopMatrix();
}

where draw_axes is the function to display the axes using GL_LINES

void draw_axes()
{

glBegin( GL_LINES );
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( -0.9, 0.9, 0.0 ); glVertex3f( -0.8, 0.9, 0.0 ); // X axis
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( -0.9, 0.9, 0.0 ); glVertex3f( -0.9, 1.0, 0.0 ); // Y axis
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( -0.9, 0.9, 0.0 ); glVertex3f( -0.9, 0.9, 0.1 ); // Z axis
glEnd();
}
gui_variables->axes is the integer associated with a check box in the GLUI user interface. In the above case the axes do not translate but they rotate about the origin along with the object. I need only the axes to rotate about the point (-0.9,0.9,0.0)

My display function is

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gui_interface();
gui_dimensional_filtering();
gui_colour_filtering();
drawObject();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

void drawObject()
{
glPushMatrix();
glTranslatef (gui_variables->translate_xy[0], gui_variables->translate_xy[1], -gui_variables->translate_z);
glMultMatrixf (rotation_matrix);
for (int i=0;i<num_files;i++)
{
if(gui_file_list.file_active)
{
render(scene,gui_file_list.fileSize);
}
}
}

the render function displays the object using GL_POINTS. The rotation_matrix is initialized to 4x4 identity matrix and translate_xy to {0,0}.

Thanks a lot....

Share this post


Link to post
Share on other sites
So you must rotate the axis around the origin and then translate it in place. Try with the following code:

if(gui_variables->axes)
{
glPushMatrix();
glLoadIdentity(); // Reset the modelview matrix
glTranslatef(-0.9,0.9,0.0); // Translation (applied as second).
glMultMatrixf (rotation_matrix); // Rotation (applied first).
draw_axes();
glPopMatrix();
}

this way the axis will be roted around the origin and then translated in place. If it does not work try invert the order of calling of glTranslatef() and glMultMatrixf () (It should be right accordingly to the red book: last transformation command issued is the first one applied).

I hope this can help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!