简体   繁体   English

旋转 3D model 在 opengl

[英]Rotating 3D model in opengl

I am trying to allocate my model a position in scene according to the 9DoF parameters.我正在尝试根据 9DoF 参数在场景中分配我的 model 和 position。 Out of which, the rotations are giving me a hard time.其中,轮换让我很难过。 If I am keeping x and z rotations zero then the roty seems to work fine and model revolve around y axis only.如果我将 x 和 z 旋转保持为零,那么roty似乎工作正常,并且 model 仅围绕 y 轴旋转。 But as soon as I am giving x and y rotations any value, then model moves around other two axis while doing y rotation.但是,一旦我给 x 和 y 旋转任何值,model 在进行 y 旋转的同时围绕其他两个轴移动。

Below is the code I am using to give the rotx , roty , rotz values.下面是我用来给出rotxrotyrotz值的代码。 I feel like there is some problem with matrix multiplication.我觉得矩阵乘法有一些问题。 Because 0 * x + roty * y + 0 * z = roty only but anything * x + roty * y + anything * z = anything .因为0 * x + roty * y + 0 * z = roty only 但任何东西* x + roty * y +任何东西* z = 任何东西

model = glm::translate(model, glm::vec3(transX, transY, transZ));
model = glm::rotate(model, toRadians * rotX, glm::vec3(1, 0, 0));
model = glm::rotate(model, toRadians * rotY, glm::vec3(0, 1, 0));
model = glm::rotate(model, toRadians * rotZ, glm::vec3(0, 0, 1));

For orienting an object, apply the rotation first, only after that think about translation/rotating about another object:为了定位 object,首先应用旋转,然后才考虑平移/旋转另一个 object:

model = glm::rotate(model, toRadians * rotX, glm::vec3(1, 0, 0));
model = glm::rotate(model, toRadians * rotY, glm::vec3(0, 1, 0));
model = glm::rotate(model, toRadians * rotZ, glm::vec3(0, 0, 1));
model = glm::translate(model, glm::vec3(transX, transY, transZ));

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

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