简体   繁体   English

如何在 glm::lookAt 函数中与偏航和俯仰一起实现滚动角度?

[英]How to implement the Roll angle together with Yaw and Pitch in glm::lookAt function?

From this page https://learnopengl.com/Getting-started/Camera I learned how to implement the Yaw and Pitch angle to a glm::lookAt function.从这个页面https://learnopengl.com/Getting-started/Camera我学会了如何实现偏航角和俯仰角到 glm::lookAt 函数。 But sadly I could not find any reference of how to add also the Roll angle to the funcion.但遗憾的是,我找不到任何关于如何向函数添加侧倾角的参考。

When I try to implement it, the x and z axis keep constant, and don't adapt to the Roll rotation.当我尝试实现它时,x 轴和 z 轴保持不变,并且不适应 Roll 旋转。

First make sure you really need to use roll for camera movement, as it's uncommon unless you are making a camera that follows something that flies.首先确保您确实需要使用滚动来移动相机,因为除非您制作的相机跟随飞行的物体,否则这种情况并不常见。 You change roll by rotating the up vector about the front vector (which will be unchanged), so it should look something like您可以通过围绕前向矢量旋转向上矢量来改变滚动(这将保持不变),所以它应该看起来像

up.y = up.y * cos(rollAngle)
up.x = ...
up.z = ...

where x and z will have 2 terms, depending on x and z of the front vector, similar to how the tutorial calculated the front vector depended on yaw and pitch You might want to consider a linear algebra library like Eigen as it will take care of rotations and other things you will probably need pretty easily using their Transform api.其中 x 和 z 将有 2 个项,取决于前向量的 x 和 z,类似于教程计算前向量的方式取决于偏航和俯仰您可能需要考虑像 Eigen 这样的线性代数库,因为它会处理使用他们的 Transform api 可以很容易地完成旋转和其他你可能需要的东西。

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

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