Jump to content
  • Advertisement
Sign in to follow this  
w166um

OpenGL Rotating a cube

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

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!