user3783728
user3783728

Reputation: 11

How to rotate muliple objects around the same pivot/point in 3D?

Here is the rotation code when initialising the model matrix:

_model =    translate(_position) *
                    (   rotate(_rotation.data[0], 1.0f, 0.0f, 0.0f) * 
                        rotate(_rotation.data[1], 0.0f, 1.0f, 0.0f) * 
                        rotate(_rotation.data[2], 0.0f, 0.0f, 1.0f)) *
                    scale(_scale);

Basically, I have got a 3D level and I want to rotate the level and all the objects in it around the same pivot point.

How could I do this?

Upvotes: 0

Views: 110

Answers (1)

Thomas
Thomas

Reputation: 181715

This is typically done by the concatenation (i.e. multiplication) of three matrices:

  1. T: Translate the desired pivot to the origin (0, 0, 0).
  2. R: Apply the rotation.
  3. Tinv: Translate back.

Because of the way OpenGL matrices are structured, the right order is Tinv * R * T. Premultiply your view matrix by that.

Upvotes: 1

Related Questions