# Rotation problems

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

## Recommended Posts

Hi, i draw an triangle and want it to rotate on its own x-Axis.
Quote:
 glLoadIdentity(); glRotatef(cursorRotator, 1.0f, 0.0f, 0.0f); glTranslatef(0 , 0, -5); glBegin(GL_TRIANGLES); // Fange an Dreiecke zu zeichnen glColor3f(0.2f,0.2f, 0.2f); glVertex3f( 0, 0.15f, 0); // Punkt1 (oben rechts) glColor3f(0.2f,0.5f, 0.2f); glVertex3f(-0.25f, 0.25f, 0); // Punkt2 (oben links) glColor3f(0.2f,0.2f, 0.7f); glVertex3f(-0.1f, 0.05f, 0); // Punkt3 (unten links) glEnd(); if (rotateCursor) cursorRotator += 0.3f;
My problem is, that the triangle rotates not on its own, but on the World coordinates x-Axis, which is 5 units in front of the triangle, so it flys out of the screen. How can I fix that? Thanks Alex

##### Share on other sites
Quote:
 Original post by huryi draw an triangle and want it to rotate on its own x-Axis.

BTW, a triangle has no x axis by its own.

Quote:
 Original post by huryMy problem is, that the triangle rotates not on its own, but on the World coordinates x-Axis, which is 5 units in front of the triangle, so it flys out of the screen.

You need to transform the space so that the desired axis of rotation appears as the x axis. Then perform the actual transformation, and then undo the formerly space adaption. In summary, it looks like (using column vectors, as is appropriate for OpenGL)
O * R * O-1
where R denotes your rotation, and O-1 the transformation to adapt the space.

If, for example, the desired axis is parallel to the x axis but offsetted by [ 0 0 5 ]T (i.e. 5 units in direction of the z axis) , then O is a translation by that offset
O := T(0,0,5)
and O-1 obviously its inverse
O-1 := T(0,0,-5)

For an explanation, when applying the formula to a point on the desired axis, e.g. [ x 0 5 ]T, then
O * Rx * O-1 = T(0,0,5) * Rx * T(0,0,-5) * [ x 0 5 ]T
== T(0,0,5) * Rx * [ x 0 0 ]T
== T(0,0,5) * [ x 0 0 ]T
== [ x 0 5 ]T
what is clear since a point onto the axis of rotation is mapped onto itself. But you can see that the space is temporarily adapted so that the desired axis is moved onto the x axis.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633370
• Total Posts
3011544
• ### Who's Online (See full list)

There are no registered users currently online

×