Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotating a cube

Started by w166um Sep 17, 2006 at 8:43 AM 1 replies 1.2k views
Original Post
w166um
w166um
I'm working on a simple OpenGL app. I have a cube drawn at the origin. Now I want to implement rotation using the mouse. However i'm having trouble trying to get a fixed coordinate system. For example if I flip the cube upside down and i try to rotate left it rotates right. Could someone please point me in the right direction? I'm fairly new to all this. Thanks in advance.
supervlad
supervlad
I'm new to opengl as well, so I'm experienced. But I know that opengl translates, rotates, and scales things cumulatively. For instance, if you're at the origin and move 5 units on x, and then move 3 more units on x you'll be 8 units away from the origin. So my guess is that it has something to do with that, because similar things happen to rotation.
GamerYZ
GamerYZ
I would try something like this:

- store the cube matrix somewhere
- load identity
- check for mouse input and do the rotation if necessary
- glPushMatrix()
- apply the cube matrix to the stack
- draw cube
- if there was new rotation from input, set the cube matrix to the matrix that is on top of the stack
- glPopMatrix()

since it's not tested, I'm not 100% sure it'll work, but it's something I'd try first myself.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.