Skip to content

Commit

Permalink
src/CesiumVR.js: minimal changes. removed dead code, optimized.
Browse files Browse the repository at this point in the history
Just using some of what has been learned from Cesium, but I want to
purge this code and use utilities provided by Cesium on a later stage.
  • Loading branch information
pupitetris committed Jul 26, 2023
1 parent 3c4dda3 commit fe8c5d9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/CesiumVR.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ var CesiumVR = (function() {
* @return {Cesium.Quaternion}
*/
CesiumVR.prototype.getRotation = function(pose) {
// return toQuat(getView(pose, "left").transform.orientation);
return toQuat(pose.transform.orientation);
};

Expand Down Expand Up @@ -322,6 +321,8 @@ var CesiumVR = (function() {
return result;
};

const zeroCameraPosition = new Cesium.Cartesian3(0.0, 0.0, 0.0);

/**
* Given a camera and a rotation quaternion, apply the rotation to the camera.
*
Expand All @@ -333,14 +334,14 @@ var CesiumVR = (function() {
var vrRotationMatrix = Cesium.Matrix3.fromQuaternion(this.getRotationInv(pose));

// Translate camera back to origin
var pos = camera.position;
camera.position = new Cesium.Cartesian3(0.0,0.0,0.0);
const savedPos = camera.position;
camera.position = zeroCameraPosition;

// Get camera rotation matrix
var cameraRotationMatrix = CesiumVR.getCameraRotationMatrix(camera);

// Apply the heading offset to camera
// Cesium.Matrix3.multiply(this.headingOffsetMatrix, cameraRotationMatrix, cameraRotationMatrix);
Cesium.Matrix3.multiply(this.headingOffsetMatrix, cameraRotationMatrix, cameraRotationMatrix);

// Apply VR rotation to offset camera rotation matrix
var newRotation = Cesium.Matrix3.multiply(vrRotationMatrix, cameraRotationMatrix, new Cesium.Matrix3());
Expand All @@ -349,7 +350,7 @@ var CesiumVR = (function() {
CesiumVR.setCameraRotationMatrix(newRotation, camera);

// translate back to position
camera.position = pos;
camera.position = savedPos;
};

/**
Expand Down

0 comments on commit fe8c5d9

Please sign in to comment.