Advertisement Jump to content
Sign in to follow this  

Cant get rotation to work properly

This topic is 4959 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 try to rotate just a plain line and when I rotate the z-axis the origin isn't in the middle of the line, so I tried to translate it to the center, then rotate it, and the translate it back, all that did was move the pivot point down farther and it still pivots way above the line.

Share this post

Link to post
Share on other sites
try something like this:

glTranslatef(to the rotation point on the line);
glRotatef(degrees, 0, 0, 1);

the pushing and popping of the matrix allows you to save the modelview matrix, do some additional translations and rotations, draw your object, then restore your original matrix

Share this post

Link to post
Share on other sites
I you want to rotate something around the point (x, y, z ) you do something like this:
    D3DXMatrix t, it, r, m;
D3DXMatrixTranslation( &t, x, y, z );
D3DXMatrixTranslation( &it, -x, -y, -z );
D3DXMatrixRotation( &r, ... );

D3DXMatrixIdentity( &m );
D3DXMatrixMultiply( &m, &m, &it );
D3DXMatrixMultiply( &m, &m, &r );
D3DXMatrixMultiply( &m, &m, t );
SetWorldMatrix( &m );

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!