使用角度矢量的有效3D旋转

问题描述 投票:2回答:1

我想知道是否有更好的方法可以实现以下目标:

ModelMatrix = glm::rotate(ModelMatrix, glm::radians(rotationVec.x), glm::vec3(1.0f, 0.0f, 0.0f));
ModelMatrix = glm::rotate(ModelMatrix, glm::radians(rotationVec.y), glm::vec3(0.0f, 1.0f, 0.0f));
ModelMatrix = glm::rotate(ModelMatrix, glm::radians(rotationVec.z), glm::vec3(0.0f, 0.0f, 1.0f));

是否有可能通过单个函数调用来实现相同计算的更有效方法?rotationVec是角度的向量,类似Unity引擎如何进行游戏对象旋转。

c++ opengl game-engine glm-math
1个回答
2
投票

感谢@meowgoesthedog这可以通过以下方式实现。

ModelMatrix = ModelMatrix * glm::eulerAngleXYZ(glm::radians(rotation.x), glm::radians(rotationVec.y), glm::radians(rotationVec.z));
© www.soinside.com 2019 - 2024. All rights reserved.