Jump to content
  • Advertisement
Sign in to follow this  
MarkB

OpenGL multiple rotations in a single glRotatef()

This topic is 4707 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 would like to accumulate multiple rotations on a game object somehow and send it in a single glRotate() call. It should be feasable, but I'm not sure if I have to use matrix math to do it. I've been kind of designing a simple rendering engine as I learn about openGL, and have discovered that its way more efficient to call glTranslatef(), glRotatef(), and glScalef() than doing your own matrix math, which uses CPU instead of GPU. After I learned that, I decided to store the transformation states in my game object struct and when I render each object to call glTranslatef(), glRotatef(), and glScalef() and pass the appropriate state info. Translation and scaling is easy, I just sum the coordinates, but I don't have a grasp on how to do it for rotation. So I reach this delima, if I don't use matrix math, which means sending my own transformation matrix, then how do I accumulate multiple rotations on a game object so I can send it in a single glRotatef() call? One way (a bad way) would be store every rotation in a container and then when i rendered the object call glRoatef() for each rotation, but that would be terrible as it wastes memory and CPU. What is my solution? How do they do it in the big game engines? Do they use CPU matrix math here instead of GPU? If you want an example: lets say I want to rotate a game object: 30deg around the X axis 5 deg around the Y axis 20deg around the X axis 50deg around the Z axis What is my resultant rotation vector and angle? How do I accumulate that info so that I don't have to store the info for every rotation? Is there a way to do it other than matrix math on the CPU?

Share this post


Link to post
Share on other sites
Advertisement
Simple calls like glRotatef are still done by the CPU, even on GPUs with hardware TCL. The best solution really is to just call glRotatef multiple times. I very highly doubt that it will be a performance problem.

If you do want to concatenate the rotations, you need to use matrix math and do the matrix multiplication yourself. You would then pass that into OpenGL using glMultMatrix or glLoadMatrix.

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!