Quaternion rotation axles swaps after 90º of rotation
Unsolved
QML and Qt Quick
-
Hi all!
I have a qml script that rotates an object in 3d space. In order to avoid the gimbal lock I am using quaternions. So when I rotate the object 90 degrees through one axle, lets say roll, the yaw and pitch rotation axles are swaped... Somehow I think the problem is with the rotation instructions I am following, I mean taking the actual quaternion and multiplaying it by the new quaternion...
Here I attach my instructions to show where can be my error. Many thanks in advance!
function paintGL(canvas,q0,q1,q2,q3) { var endQuaternion = new THREE.Quaternion(); var vector = new THREE.Vector3(1, 0, 0); endQuaternion.set( q2, q0, q1, q3 ); //The order is modified to match with the object movements var rotationQuaternion = new THREE.Quaternion(); rotationQuaternion.setFromAxisAngle(new THREE.Vector3( 1, 0, 0 ), -Math.PI / 2); //Rotate the object to the desired starting point endQuaternion.multiply(rotationQuaternion); var qm = new THREE.Quaternion(); THREE.Quaternion.slerp(mesh.quaternion, endQuaternion, qm, 0.5); mesh.quaternion.slerp(qm, 0.5); renderer.render( scene, camera ); }