1
votes

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?

2
Get rotation on that axis and + 0.05 (don't know code right nowRush2112

2 Answers

0
votes

Why don't you use one or combination of:

mesh.rotation.x += 0.05;
mesh.rotation.y += 0.05;
mesh.rotation.z += 0.05;

JSFiddle

0
votes

If you are setting all of them, you can do this

mesh.rotation.set(9, 7, 3)