# OpenGL multiple rotations in a single glRotatef()

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633721
• Total Posts
3013532
×