0

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/10/

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?

WestLangley
  • 102,557
  • 10
  • 276
  • 276
NicoC
  • 477
  • 1
  • 8
  • 19
  • (1) Here is a simplified version of your fiddle: http://jsfiddle.net/ehsktuj2/14/. (2) Also see http://stackoverflow.com/a/32038265 (3) Getting the green cube to rotate on a world axis when it has a rotating parent is tricky. Is that _really_ what you want to do? – WestLangley Oct 21 '15 at 00:52
  • Thanks for (2), I will have a look, for (3) well, maybe it's a wrong mindset from my mechanical background but using different referentials and transformation matrices between them is the way to go in this field, so i'm trying to apply the same logic in this project. – NicoC Oct 21 '15 at 13:42

0 Answers0