简体   繁体   English

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

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

I am trying to make my world rotate around my camera no matter where my camera is.无论我的相机在哪里,我都试图让我的世界围绕我的相机旋转。 I am not doing any crazy math yet, I am leaving middle school this year and I don't know what quaternions are.我还没有做任何疯狂的数学,今年我要离开中学,我不知道四元数是什么。 My problem is that every time I use glm::rotate function for anything it only allows me to rotate around an axis at the origin point and I can't find a way to fix this.我的问题是,每次我使用 glm::rotate function 时,它只允许我在原点绕轴旋转,我找不到解决这个问题的方法。 if there is any somewhat simple answer to this problem I am having please let me know how I can rotate my world around any given point.如果我遇到的这个问题有任何简单的答案,请告诉我如何围绕任何给定点旋转我的世界。 thanks谢谢

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);

What you actually do is to rotate the model:您实际上要做的是旋转 model:

model_view = look * rotate

If you want to rotate the view, then you have to swap the order of the matrices.如果要旋转视图,则必须交换矩阵的顺序。 Note, the matrix multiplication is not Commutative :注意,矩阵乘法不是Commutative

model_view = rotate * look

For your code that menas:对于您的代码,意思是:

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

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

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