Jump to content
  • Advertisement
Sign in to follow this  
trumsaigon72

Please! How to rotate Object around axis x, y, z?

This topic is 2851 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 all,



Currently, I’m having problem about rotation object around Y Axis, here’s my problem:



Step 1: I try to rotate object with angle and vector (FX, FY, FZ) by using mouse dragging action. Vector (FX, FY, FZ) is directed from original point to the current mouse position. The source code is as the following:



glPushMatrix();

glLoadIdentity();

glRotatef(angle, FX, FY, FZ);

glMultMatrixf( m_objectXform, 0 );

glGetFloatv( gl.GL_MODELVIEW_MATRIX, m_objectXform, 0 );

glPopMatrix();

glMatrixMode( gl.GL_MODELVIEW );

glLoadIdentity();

gluLookAt( 0, 0, 500.0, 0, 0, 0, 0.0, 1.0, 0.0);

glMultMatrixf( m_objectXform, 0 ); //m_objectXform is float[16]



Step 2: Following the step 1, the tilt of object is changed (the Tilt of X, Y, Z Axis is also changed too). And then, I will use a slider to trigger the rotation of this object around Y Axis. However, the result which I see is: Object still rotates around the original Y Axis (vertically), not rotates along the tilted Y axis. Here’s my codes:



glPushMatrix();

glLoadIdentity();

glRotatef(angle, 0, 1, 0);

glMultMatrixf( m_objectXform, 0 );

glGetFloatv( gl.GL_MODELVIEW_MATRIX, m_objectXform, 0 );

glPopMatrix();

glMatrixMode( gl.GL_MODELVIEW );

glLoadIdentity();

gluLookAt( 0, 0, 500.0, 0, 0, 0, 0.0, 1.0, 0.0);

glMultMatrixf( m_objectXform, 0 ); //m_objectXform is float[16]



Please help me to correct my code and find the reason why object still rotate around Y Axis vertically.



Best Regards

Manh Nguyen

Share this post


Link to post
Share on other sites
Advertisement
you want to do a translate, rotate, -translate i believe.

http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm

look at the "Rotation about arbitrary axis"

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!