Skip to content

Commit

Permalink
Merge pull request #6444 from mozilla/prevent-camera-scaling
Browse files Browse the repository at this point in the history
Prevent camera scaling
  • Loading branch information
keianhzo authored Jan 19, 2024
2 parents 73b6f2c + 32cbf34 commit 4804f77
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/systems/camera-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const decompose = (function () {
})();

const IDENTITY = new THREE.Matrix4().identity();
const V_ONE = new THREE.Vector3(1, 1, 1);
const orbit = (function () {
const owq = new THREE.Quaternion();
const owp = new THREE.Vector3();
Expand Down Expand Up @@ -418,7 +419,10 @@ export class CameraSystem {
}

tick = (function () {
const translation = new THREE.Matrix4();
const tmpMat = new THREE.Matrix4();
const position = new THREE.Vector3();
const quat = new THREE.Quaternion();
const scale = new THREE.Vector3();
let uiRoot;
const hoveredQuery = defineQuery([HoveredRemoteRight]);
return function tick(scene, dt) {
Expand All @@ -431,9 +435,6 @@ export class CameraSystem {
const isGhost = !entered && uiRoot && uiRoot.firstChild && uiRoot.firstChild.classList.contains("isGhost");
if (isGhost && this.mode !== CAMERA_MODE_FIRST_PERSON && this.mode !== CAMERA_MODE_INSPECT) {
this.mode = CAMERA_MODE_FIRST_PERSON;
const position = new THREE.Vector3();
const quat = new THREE.Quaternion();
const scale = new THREE.Vector3();
this.viewingRig.object3D.updateMatrices();
this.viewingRig.object3D.matrixWorld.decompose(position, quat, scale);
position.setFromMatrixPosition(this.viewingCamera.matrixWorld);
Expand Down Expand Up @@ -489,16 +490,18 @@ export class CameraSystem {
setMatrixWorld(this.avatarPOV.object3D, this.viewingCamera.matrixWorld);
} else {
this.avatarPOV.object3D.updateMatrices();
setMatrixWorld(this.viewingCamera, this.avatarPOV.object3D.matrixWorld);
this.avatarPOV.object3D.matrixWorld.decompose(position, quat, scale);
tmpMat.compose(position, quat, V_ONE);
setMatrixWorld(this.viewingCamera, tmpMat);
}
} else if (this.mode === CAMERA_MODE_THIRD_PERSON_NEAR || this.mode === CAMERA_MODE_THIRD_PERSON_FAR) {
if (this.mode === CAMERA_MODE_THIRD_PERSON_NEAR) {
translation.makeTranslation(0, 1, 3);
tmpMat.makeTranslation(0, 1, 3);
} else {
translation.makeTranslation(0, 2, 8);
tmpMat.makeTranslation(0, 2, 8);
}
this.avatarRig.object3D.updateMatrices();
this.viewingRig.object3D.matrixWorld.copy(this.avatarRig.object3D.matrixWorld).multiply(translation);
this.viewingRig.object3D.matrixWorld.copy(this.avatarRig.object3D.matrixWorld).multiply(tmpMat);
setMatrixWorld(this.viewingRig.object3D, this.viewingRig.object3D.matrixWorld);
this.avatarPOV.object3D.quaternion.copy(this.viewingCamera.quaternion);
this.avatarPOV.object3D.matrixNeedsUpdate = true;
Expand Down

0 comments on commit 4804f77

Please sign in to comment.