Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
save object allocation on look-controls.calculateDeltaRotation
  • Loading branch information
ngokevin committed Oct 3, 2017
commit 5cf6429cbc1f0106377dea6aea571f1ebf6577d0
14 changes: 6 additions & 8 deletions src/components/look-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports.Component = registerComponent('look-controls', {
this.hmdEuler = new THREE.Euler();
this.position = new THREE.Vector3();
this.rotation = {};
this.deltaRotation = {};

this.setupMouseControls();
this.setupHMDControls();
Expand Down Expand Up @@ -168,7 +169,7 @@ module.exports.Component = registerComponent('look-controls', {
*/
updateOrientation: function () {
var currentRotation;
var deltaRotation;
var deltaRotation = this.deltaRotation;
var hmdEuler = this.hmdEuler;
var hmdQuaternion = this.hmdQuaternion;
var pitchObject = this.pitchObject;
Expand All @@ -188,7 +189,7 @@ module.exports.Component = registerComponent('look-controls', {
} else if (!sceneEl.is('vr-mode') || isNullVector(hmdEuler) || !this.data.hmdEnabled) {
// Mouse drag if WebVR not active (not connected, no incoming sensor data).
currentRotation = this.el.getAttribute('rotation');
deltaRotation = this.calculateDeltaRotation();
this.calculateDeltaRotation();
if (this.data.reverseMouseDrag) {
rotation.x = currentRotation.x - deltaRotation.x;
rotation.y = currentRotation.y - deltaRotation.y;
Expand All @@ -214,15 +215,12 @@ module.exports.Component = registerComponent('look-controls', {
calculateDeltaRotation: function () {
var currentRotationX = radToDeg(this.pitchObject.rotation.x);
var currentRotationY = radToDeg(this.yawObject.rotation.y);
var deltaRotation;
deltaRotation = {
x: currentRotationX - (this.previousRotationX || 0),
y: currentRotationY - (this.previousRotationY || 0)
};
this.deltaRotation.x = currentRotationX - (this.previousRotationX || 0);
this.deltaRotation.y = currentRotationY - (this.previousRotationY || 0);
// Store current rotation for next tick.
this.previousRotationX = currentRotationX;
this.previousRotationY = currentRotationY;
return deltaRotation;
return this.deltaRotation;
},

/**
Expand Down