Is threejs always working in local coordinate space?

Im from OpenGL/C++ background and I was wondering on thread like this

why is it that to move an object forward is I need to translate the Z

object.translateZ( 10 );

This confuses a dev like me who came from pure OpenGL background, does this mean threejs is working in local space? so even if the player is rotated in Y axis and is facing in a different direction, to move forward it is always translateZ, why?

In OpenGL, say if the look or forward vector is facing 1,0,0 and I want to move forward 1 step, it is usualy translated in that direction giving us 2, 0, 0, translating the X (not the Z!!)

This is confusing and was my primary reason i decided not to use threejs in one project.
Is this more of a naming thing instead? like Z in translateZ is the look/forward vector, X is the right vector and Y is the up vector?

Is there an option to do this in world space instead to avoid confusion in devs like me who came from a more generic 3D background?

so even if the player is rotated in Y axis and is facing in a different direction, to move forward it is always translateZ, why?

Can not speak for the library but judging by the code alone, the rotation of an object is stored separately in its quaternion. When translateZ is applied, it will first rotate local Z axis (which matches world Z) using that quaternion to make the forward vector and then apply translation along that new local (forward) Z direction, like in this example:

mesh.rotateY(Math.PI/4);
mesh.translateZ(1);

Is there an option to do this in world space

This will move an object in world coordinates:

mesh.rotateY(Math.PI/4);
qmesh.position.x += 1;

DICLAIMER: Not sure about “the right” way to do things, I prefer practical approach, things either work or they don’t :stuck_out_tongue:

1 Like