My goal is to make an object controls like a spaceship, what I understand is that I need to use quaternions to achieve this goal. For start I'm trying to make my cube to start rotating to left as I press A key, this is the code for that:
if(controls.pressingA === true)
{
//var pLocal = new THREE.Vector3( 0, 0, -1 );
//var pWorld = pLocal.applyMatrix4( me.matrixWorld );
//var dir = pWorld.sub( me.position ).normalize();
var dir = me.getWorldDirection();
var quaternion = new THREE.Quaternion().setFromAxisAngle( dir, 0.05 );
me.rotation.setFromQuaternion( quaternion );
}
As I understand this code the the me.getWorldDirection()
gets the axis that the object is facing, then I create quaternion on the axis that I got before and rotate given object by 0.05 degrees in rad, and finally with the last line of code I just apply to quaternion to my object. The problem I got is that it doesn't increase the rotation, it just sets my object to given rotation, how can I make it increase rotation instead of setting it?