I’m working on a flight simulator and I’ve gone and made all the logic based on trigonometry and Euler Angles, I believe.
Well this has created a lot of unwanted issues with maintaining correct rotations. I’ve learned a lot from looking into the issue.
I’m now intending to use Quaternion Rotations for all the logic, however since I have not used them before I am having a hard time understanding how to Tween/Animate these rotations.
Below is my basic Tweening function with Tween.js. Hypothetically here I am looking to tween the X axis 90 degrees. My camera rotation is set as “YXZ”.
cameraTween(deg, that, camera, time, callback){
const sceneCamera = window.scene.getObjectByName(camera),
cameraTween = new TWEEN.Tween({ rotation: new THREE.Quaternion() })
.to({ rotation: new THREE.Quaternion().setFromAxisAngle( new THREE.Vector3( 0,1,0 ), that.getRadians(deg) ) }, time )
.easing( TWEEN.Easing.Quadratic.Out )
.onUpdate( (tween) => {
console.log(tween.rotation);
const newCamRotation = new THREE.Quaternion().setFromAxisAngle( new THREE.Vector3( 0,1,0 ), tween.rotation );
sceneCamera.quaternion.multiplyQuaternions( newCamRotation, sceneCamera.quaternion )
} )
.onComplete( () => {
callback();
}).start();
}
Any ideas on how to tween these Quaternion rotations?
Thank you!