在 OpenGL 中获取 X、Y 和 Z 轴上以弧度为单位的相机旋转?
我试图在 OpenGL 中获取相机在各个轴上的旋转(但专门使用 Java、LWJGL 和 jME)。 相机对象允许我获得 Vector3f 的方向,但这似乎无法获得组件化旋转; 每个轴似乎都与另一个轴相关联。 我发现带有偏移量的角度分量的 toAngleAxis 是一种快速破解,但在大多数情况下无法正常工作。 不幸的是,我的数学不太好,否则我可能能够解决这个问题:)同样,我只需要 X、Y 和 Z 轴分量化并以弧度为单位,从 0 弧度到 2 PI 弧度。
有人可以帮忙吗?
提前欢呼和感谢, 克里斯
I'm trying to obtain the camera rotation on various axis in OpenGL (but using Java, LWJGL, and jME specifically). The camera object allows me to get the direction as a Vector3f, but this doesn't seem to work to get the componentised rotation; each axis appears tied to another axis. I found that toAngleAxis with the angle component with offset was a quick hack, but doesn't work properly in most situations. I'm not so good at maths unfortunately, otherwise I may have been able to work out this problem :) Again, I just need the X, Y and Z axes componentised and in radians, from 0 radians to 2 PI radians.
Can anyone help?
Cheers and thanks in advance,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议阅读有关欧拉角、偏航/俯仰/滚动和四元数方向的内容。 这些主题将帮助您了解所涉及的一切。 如果我理解正确,您正在尝试从指定方向构造欧拉角。
请参阅此一些算法的代码来使用欧拉角。 特别是,我相信您想要的是 setDirection 方法。
这将为您提供来自方向矢量的偏航和俯仰。 但请注意,您只需要 2 次旋转,因为“滚动”需要围绕方向向量(或指定为单个四元数旋转的方向)旋转。
I'd recommend reading about Euler Angles, yaw/pitch/roll, and quaternion orientation. These topics will help you understand everything involved. If I understand correctly, you're trying to construct Euler angles from a specified orientation.
See this code for some algorithms for working with Euler angles. In particular, I believe what you want is the setDirection method.
This will give you a yaw and pitch from a directional vector. Note that you only need 2 rotations, though, since "roll" would require a rotation about the directional vector (or your direction specified as a single quaternion rotation).
获得旋转角度只需将笛卡尔坐标中给出的视图向量转换为球坐标即可。 您可以在 wikipedia 中找到公式。
请注意,您只能从视图向量中获得两个旋转角度。 获得第三旋转角度需要知道投影平面x或y轴。
Obtaining the rotation angels requires just transforming the view vector given in cartesian coordinates into spherical coordinates. You can find the formulas in wikipedia.
Note that you can only obtain two rotation angels form the view vector. Obtaining the third rotation angle requires knowing the projection plane x or y axis.