upVector logic in ArcRotateCamera depends on how you define this vector

#1

Hi all,

This is my first time posting a bug, so I might be wrong, and this to belong in questions. Please let me know if that is the case.

I found out that in the ArcRotateCamera, the upVector logic does not behave as one would expect in all the cases. I have created a small demo: https://www.babylonjs-playground.com/#12WBC#459

Before clicking on any mesh, one can see that if you click and drag the mouse up and down, the camera rotates ‘up’ and ‘down’. Same if one drags the mouse left and right. If you change the upVector property of the camera by using camera.upVector = new BABYLON.Vector3(1, 0, 0), the vector that is pointing up is now the X vector. And once again, if one drags up and down, or left and right, the camera behaves as expected, just with a different vector pointing up.

However, if one defines the upVector by operating with camera.upVector.x = 1, (and the same for y and z), the logic of this up-down/left-right is completely modified, and not logical at all. In the example I posted, you can find this by clicking on the arrows. Y and Z arrows (green and blue) have the BABYLON.Vector3 definition, whereas Z arrow (red) can be changed from one definition to another. In addition, the main characteristics of the camera (alpha and beta angles, and upVector) are logged in the console, and it can be that they are the exact same for both configurations. What is happening that the logic is changed, while the main properties remain the same?

Accesing transformation matrices of ArcRotateCamera
#2

In the API ArcRotateCamera - Babylon.js Documentation

it states

The vector the camera should consider as up. (default is Vector3(0, 1, 0) as returned by Vector3.Up()) Setting this will copy the given vector to the camera’s upVector, and set rotation matrices to and from Y up. DO NOT set the up vector using copyFrom or copyFromFloats, as this bypasses setting the above matrices.

So it seems that whilst using camera.upVector = new BABYLON.Vector3(1, 0, 0) then the matrices are updated and setting an individual component as in camera.upVector.x = 1 bypasses setting the matrices so only update the upVector with a full vector.