• 12
• 12
• 9
• 10
• 13

# rotations problem

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

## Recommended Posts

Hi, I am making a game where I have several objects and I need each one to rotate around its own center of rotation. Is there a way of setting independent coordinate systems for each object (other than using glPushMatrix() / glPopMatrix) 'cos this seems a bit computationally intensive when there a quite a few objects?

##### Share on other sites
Quote:
 Is there a way of setting independent coordinate systems for each object (other than using glPushMatrix() / glPopMatrix) 'cos this seems a bit computationally intensive when there a quite a few objects?

No, using coordinate system matrices is the only way to do that. And it is not really computationally expensive, even with thousands of objects.

##### Share on other sites
sorry, what do you mean by 'coordinate system matrices'? Do you mean I have to use a separate glPushMatrix() ... glPopMatrix() block for each object I want to rotate?

##### Share on other sites
Quote:
 Original post by andr0clessorry, what do you mean by 'coordinate system matrices'? Do you mean I have to use a separate glPushMatrix() ... glPopMatrix() block for each object I want to rotate?

Yes. You begin rendering the scene by transforming the scene according to the camera position/rotation, preferably using glMultMatrix. Then, for each object in the scene, you do the following:
glPushMatrix();glMultMatrix(this->transformationMatrix);//render object hereglPopMatrix();

Pushing and popping matrices is extremely cheap. Multiplying matrices is also pretty cheap and unavoidable. The alternative to pushing and popping is to construct rotation matrices for each object that are dependent on the rotation matrix of the previously rendered object, which is completely irrational for most applications.