1
\$\begingroup\$

I'm new on Three.js and despite a mechanical background, I can't find how quaternion works: it's like it always refers on local part referential and not the global one.

I've illustrated it here : http://jsfiddle.net/ehsktuj2/13/

function applyRotation(){
    var redRotationQuaternion = new THREE.Quaternion();
    redRotationQuaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), control.rotationSpeedRedY );
    applyQuaternion(_cubeRed, redRotationQuaternion);

    var greenRotationQuaternion = new THREE.Quaternion();
    greenRotationQuaternion.setFromAxisAngle( new THREE.Vector3( 0, 0, 1 ), control.rotationSpeedGreenZ );
    applyQuaternion(_cubeGreen, greenRotationQuaternion);
}

function applyQuaternion(cube, quaternion){
    var cubeQuaternion = cube.quaternion;
    cubeQuaternion.multiplyQuaternions(quaternion, cubeQuaternion);
    cubeQuaternion.normalize();    
}

The rotation quaternion of the green box is via the vector (0,0,1) but it's not in the global referential, it's the one of the projected referential of the green cube.

How can I project the quaternion back on the global referential? So that the green cube rotates via the (0,0,1) vector of the scene?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.