Hello!
I may have found a slight vulnerability in this change; sadly, I cannot reproduce it in any playground, but in the previous version, this.rotation.z
was forced to 0, which was a good thing because in the new version, rotationQuaternion.toEulerAnglesToRef(this.rotation);
might not return a perfect 0 (which is what is happening in my project), triggering an update to the upVector
in the getViewMatrix
function as expected.
This means that every time I update the target — i.e. every time I move — the upVector gets updated.
The easiest fix is to add these lines at the end of setTarget:
this.rotation.z = 0;
if (this.rotationQuaternion) {
Quaternion.FromEulerVectorToRef(this.rotation, this.rotationQuaternion);
}
For now, the workaround is to add these lines to my project:
const originalSetTarget = TargetCamera.prototype.setTarget;
// FIXME: Temporary override to fix roll being edited during setTarget...
TargetCamera.prototype.setTarget = function (target: Vector3): void {
originalSetTarget.call(this, target);
this.rotation.z = 0;
if (this.rotationQuaternion) Quaternion.FromEulerVectorToRef(this.rotation, this.rotationQuaternion);
};

Edit: You could also replace the above line to always use a TmpQuaternion
.
From line 275, it would look like something like this:
Quaternion.FromRotationMatrixToRef(TmpMatrix, TmpQuaternion);
TmpQuaternion.toEulerAnglesToRef(this.rotation);
this.rotation.z = 0;
if (this.rotationQuaternion) {
Quaternion.FromEulerVectorToRef(this.rotation, this.rotationQuaternion);
}
or even crazier:
Quaternion.FromRotationMatrixToRef(TmpMatrix, TmpQuaternion).toEulerAnglesToRef(this.rotation);
this.rotation.z = 0; // ensure the roll remains unchanged
if (this.rotationQuaternion) {
Quaternion.FromEulerVectorToRef(this.rotation, this.rotationQuaternion);
}
On a side note, I absolutely love all these high-level functions! <3