[英]OpenGL glm rotate model around a point issue
我有一个模型和一些位于其轴上的辅助立方体,每个轴上三个用于转换,我使用它们围绕其局部轴旋转模型。
我想让这些立方体围绕模型中心旋转,所以我将它们平移到模型中心,在同一轴上以相同的角度旋转它们,然后将它们平移回来。 这是代码:
//Rotation around X axis
GLfloat theta=glm::radians(xoffset);
glm::quat Qx(glm::angleAxis(theta, glm::vec3(1.0f, 0.0f, 0.0f)));
glm::mat4 rotX = glm::mat4_cast(Qx);
pickedObject->Transform(rotX);//Multiply the model matrix by the transformation matrix
glm::vec3 op(pickedObject->getMatrix()[3]);//model position
for(TransformationHelper* h:pickedObject->GetTransformationHelpers()){//the small cubes
glm::mat4 m,it,t;
glm::vec3 hp(h->getMatrix()[3]);//the cube position
t=glm::translate(m,op);//m is a unit matrix
it=glm::translate(m,-op);
m=t*rotX*it;
h->Transform(m);
}
结果出乎意料
更新:更新翻译矩阵后,我得到了这个结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.