LWJGL - Problems implementing 'roll' in a 6DOF Camera using quaternions and a translation matrix

限于喜欢 提交于 2019-12-04 08:39:25

You're doing the multiplications in the wrong order.

For two rotations q1 and q2, if q2 is to follow q1 (since rotations are generally non-communitive) you multiply q2*q1.

In a gimbal style system such as controls for a FPS, the priority order is always yaw, pitch, roll. This would suggest the following math:

roll * pitch * yaw

As a java point, I would suggest not creating new Quaternions for every update but anyway

change = Quaternion.mul(Quaternion.mul(roll, pitch, change), yaw, change);

If you look at the code, the third Quaternion will just be overwritten with the result, so no need to reset it or recreate it each frame / update.

This rotational order thing is confusing, but if you look at the Wiki page on Quaternions, it's the general rule.

I know this is old, but allow me a guess anyway. The problem is exactly what you said yourself:

When ever I "roll" the camera, it seems to roll around the global Z axis instead of the local camera direction axis.

It does so because you asked it to roll around vector (0,0,1), that is, the global Z axis.

This is what unit quaternions do: they rotate a vector (here a set of vectors, your rotation matrix) around an axis specified by their imaginary vectorial part (x,y,z) by some angle function of the w scalar (w = cos(angle/2)).

If I understand what you are trying to do, that is rolling your camera as when tilting your head from left to right, then you should build a roll quaternion around your direction vector:

 roll.setFromAxisAngle(new Vector4f(direction.x, direction.y, direction.z, rollAngle * DEGTORAD));

I'm assuming your direction vector is normalized, or that LWJGL knows what to do with a non-unitary axis vector when calling setFromAxisAngle.

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