简体   繁体   English

如何在3D中围绕相同的轴心/点旋转多个对象?

[英]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. 基本上,我有一个3D关卡,我想绕同一旋转点旋转关卡及其中的所有对象。

How could I do this? 我该怎么办?

This is typically done by the concatenation (ie multiplication) of three matrices: 这通常是通过三个矩阵的级联(即乘法)完成的:

  1. T : Translate the desired pivot to the origin (0, 0, 0). T :将所需的轴心平移到原点(0,0,0)。
  2. R : Apply the rotation. R :进行旋转。
  3. Tinv : Translate back. Tinv :翻译回去。

Because of the way OpenGL matrices are structured, the right order is Tinv * R * T . 由于OpenGL矩阵的构造方式,正确的顺序为Tinv * R * T Premultiply your view matrix by that. 以此乘以您的视图矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM