I have done a lot of reading into quaternion and matrix rotation but I cant work it out. I've tried 100 different things but they all come back to the fact that: I have a euler vector, created from the joystick and I dont know of a way that I can convert that into either quaternions or matrix rotatrion without creating gimble lock.
This is what I do to get a euler angle to a quaternion:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| private Quat4f createQuaternionFromEuler(float angleX, float angleY, float angleZ ) { Quat4f qx = createQuaternionFromAxisAndAngle( 1f,0f,0f, angleX ); Quat4f qy = createQuaternionFromAxisAndAngle( 0f,1f,0f, angleY ); Quat4f qz = createQuaternionFromAxisAndAngle( 0f,0f,1f, angleZ ); qx.mul( qy ); qx.mul( qz ); return qx; } public final Quat4f createQuaternionFromAxisAndAngle( float x, float y, float z, float angle ) { float sin_a = (float) Math.sin( angle * 0.5f ); float cos_a = (float) Math.cos( angle * 0.5f ); x = (float) (x * sin_a); y = (float) (y * sin_a); z = (float) (z * sin_a); float w = (float) cos_a; return new Quat4f(x,y,z,w); } |
I then multiply the 3 quaternion created from eluer angles x, y and z and I just get gimble lock.