如何使用 glm::rotate 围绕原点以外的点旋转对象?

how can I rotate an object around a point other than the origin point with glm::rotate?

我试图让我的世界围绕我的相机旋转,无论我的相机在哪里。我还没有做任何疯狂的数学,今年我要离开中学了,我不知道什么是四元数。我的问题是,每次我对任何东西使用 glm::rotate 函数时,它只允许我在原点绕轴旋转,我找不到解决这个问题的方法。如果对我遇到的这个问题有任何简单的答案,请告诉我如何围绕任何给定点旋转我的世界。谢谢

glm::mat4 look(1.0f);
float Rrotation;
Rrotation = 20.0f;
glm::vec3 the_axis_not_orientation(0.0f, 1.0f, 0.0f);

look = glm::rotate(look, Rrotation, the_axis_not_orientation);

你实际上做的是旋转模型:

model_view = look * rotate

如果要旋转视图,则必须交换矩阵的顺序。注意,矩阵乘法不是 Commutative:

model_view = rotate * look

对于你的代码,menas:

glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Rrotation, the_axis_not_orientation)
look = rotate * look;