Obtaining the camera rotation in radians on the X, Y, and Z axis in OpenGL?

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

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

回答1:

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.



回答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).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!