Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

Cant get rotation to work properly

This topic is 4809 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
Advertisement
try something like this:


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


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 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!