1

For drag function, I'm making objectB follow objectA like:

var positionDeltas = objectA.position.clone();
postitionDeltas.sub(objectAOldPosition);
var newPositon = objectB.position.clone();
objectB.position = newPosition.add(positionDeltas);

Can angle increments be done similarly? Can I subtract/add quaternions in a similar way?:

var rotationDeltas = objectA.quaternion.clone();
rotationDeltas.sub(objectAOldRotation);
var newRotation = objectB.quaternion.clone();
objectB.quaternion = newRotation.add(rotationDeltas);

Clarification: this is what I want to do; however, I do know that eulers can't be subtracted, and subtraction isn't defined for quaternions. So....how would one who knows what they're doing approach this three.js?

user2132190
  • 373
  • 1
  • 2
  • 17

1 Answers1

1

Try this:

 const q = new THREE.Quaternion();

 q.multiply( q2, q1.inverse() );

Quaternion q represents the rotation from quaternion q1 to q2. You can then apply this rotation to your 3D object via .applyQuaternion().

three.js R91

Mugen87
  • 28,829
  • 4
  • 27
  • 50
  • How to get axis of rotation corresponding to q? I would like to use the code in answer of https://stackoverflow.com/questions/11060734/how-to-rotate-a-3d-object-on-axis-three-js/18296348 but I need to find axis and angle somehow – user2132190 Mar 29 '18 at 20:24
  • Your solution works, thank you. But I dont have R91, so how can q be applied to a 3D object manually, i.e. without .applyQuaternion?...thank you – user2132190 Mar 29 '18 at 22:37
  • Yes. It is `object.quaternion.premultiply( q );`. – Mugen87 Mar 30 '18 at 09:39