Sign in to follow this  

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

This topic is 2636 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

This topic is 2636 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this