Advertisement

problem rotating

Started by April 22, 2002 03:06 PM
3 comments, last by _Titan_ 22 years, 10 months ago
I cant seem to get my square to rotate from the dead center, it rotates from the corver of my square. WTF?
The cube''s rotating around (0,0,0), which is probably also one of the corners of your cube. Personally I''ve also been wondering how you can make a cube rotate around some arbitrary point (like its own centre), instead of around the centre of the world model. Any of you GL gods got the answer ?

_________
"Maybe this world is another planet''''s hell." -- Aldous Huxley
_________"Maybe this world is another planet''s hell." -- Aldous Huxley
Advertisement
See, the square and trianlge in the lesson 4 tutorial rotates like i want mine too, i''m trying to rotate my charactor, but it pivots more or less instead of rotating, or turnign around. Its like the center point is set to my corner instead of the center of my square.

WTF?

You need to translate your object so that it''s centre is at the origin, rotate as required and then translate back to where it was. The reason the shapes in NeHe lesson 4 rotate about their centres is that they are constructed with their centre at the origin, rotated and then moved into place.

So if your square coordinates are something like:

(0, 0), (0, 1), (1, 1), (1, 0)

try changing them to:

(-0.5, -0.5), (-0.5, 0.5), (0.5, 0.5), (0.5, -0.5)
Translate the object after you've rotated it,.. like this: (pseudo)

(ObjectSize being the difference between the highest and lowest vertex positions)
--------------------------------Mid.x = ObjectSize.x / 2;Mid.y = ObjectSize.y / 2;Mid.z = ObjectSize.z / 2;glRotatef( z, 0,0,1 );glTranslatef( Mid.x , Mid.y, Mid.z ); // Draw object here--------------------------------   


glRotatef rotates the model matrix for you and all you have to do is translate it... It works because the object is translated over the already rotated axis......

Hope this makes any sense at all......

EDIT: Added the "at all" part,.... add's drama

-Crawl


[edited by - Crawl on April 22, 2002 6:37:26 PM]
--------<a href="http://www.icarusindie.com/rpc>Reverse Pop Culture

This topic is closed to new replies.

Advertisement