Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Quaternion rotation axles swaps after 90º of rotation



  • 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 );
    }
    

Log in to reply