# Cant get rotation to work properly

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

## 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 on other sites
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 on other sites
I am using directx, I dont know what those functions do in opengl.

##### 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 on other sites
Thanks a lot, it took a litte bit to understand, but I got it.

• 23
• 10
• 19
• 15
• 14