Confirming coordinate system transformation with scene.useRightHandedSystem

There’s a debate with my team on whether or not Babylon is flipping the x axis or the z axis when switching to a right handed system.

When I use scene.useRightHandedSystem in playground, it seems to flip the x axis. The sphere that was on the right hand side of the screen is now on the left.
https://www.babylonjs-playground.com/#S84MWJ#2

However, I believe this is happening because the camera is always facing down the positive z due to camera.setTarget(new BABYLON.Vector3(0, 0, 1)) and the sphere’s z is positive. This creates the illusion that it was flipped across the x.

The forum mods are saying that it is “effectively reversing Z”, read here: [SOLVED]Coordinates with right hand rule

Help us end this debate. Thanks!

I found these in different locations in the Babylon.js code:

var forward = this._scene.useRightHandedSystem ?
                 new Vector3(0, 0, -1) : new Vector3(0, 0, 1);
...
if (this._mesh && this._mesh.getScene().useRightHandedSystem) {
    this._deviceRoomPosition.z *= -1;
}
...
defines.REFLECTIONMAP_OPPOSITEZ = this.getScene().useRightHandedSystem ? 
            !reflectionTexture.invertZ : reflectionTexture.invertZ;
...
if (!this._scene.useRightHandedSystem) {
    currentRig.position.z *= -1;
    currentRig.rotationQuaternion.z *= -1;
    currentRig.rotationQuaternion.w *= -1;
}

So it seems it is the z axis that is reversed in RHS.

Thanks for the confirmation!

It depends. Note that a flip in Z with a 180° rotation is mathematically equivalent to a flip in X.

The engine itself flips Z (I believe). But for glTF, we flip Z and rotation by 180°.

True, you could flip any coordinate in a LFS to make it RHS. We just want to make sure we understand exactly what Babylon is doing in the LFS to RHS conversion. Thanks Gary.

1 Like