Sign in to follow this  

Rotation problems

This topic is 3456 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 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 this post


Link to post
Share on other sites
Quote:
Original post by hury
i 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 hury
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.

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.

Share this post


Link to post
Share on other sites

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