如何解决围绕局部轴的 OpenGL 旋转无法按设计工作
我想围绕其局部轴旋转对象。首先,我通过 transform.rotation
向量(x - 俯仰,y - 偏航,z - 滚转)计算局部轴。
glm::vec3 front;
front.x = cos(glm::radians(transform.rotation.y)) * cos(glm::radians(transform.rotation.x));
front.y = sin(glm::radians(transform.rotation.x));
front.z = sin(glm::radians(transform.rotation.y)) * cos(glm::radians(transform.rotation.x));
transform.front = glm::normalize(front);
transform.right = glm::normalize(glm::cross(transform.front,glm::vec3(0.0f,1.0f,0.0f)));
transform.up = glm::normalize(glm::cross(transform.right,transform.front));
然后我设置模型矩阵如下。
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model,transform.position);
model = glm::rotate(model,glm::radians(transform.rotation.x),transform.right);
model = glm::rotate(model,glm::radians(transform.rotation.y),transform.up);
model = glm::rotate(model,glm::radians(transform.rotation.z),transform.front);
model = glm::scale(model,transform.scale);
shader.setMat4("model",model);
似乎唯一有效的是偏航旋转,滚动作为俯仰和俯仰作为滚动,几乎任何调整都会使对象向指定方向以外的任何方向旋转。其他人只是没有以预期的方式轮换。
我错过了什么吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。