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
13 changes: 10 additions & 3 deletions src/components/tracked-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ module.exports.Component = registerComponent('tracked-controls', {
var controllerEuler = new THREE.Euler();
var controllerPosition = new THREE.Vector3();
var controllerQuaternion = new THREE.Quaternion();
var deltaControllerPosition = new THREE.Vector3();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been always kind of crappy. Can we create a closure and initialize and reuse these variables instead instancing once per frame? Like this:

https://github.com/aframevr/aframe/blob/master/src/components/raycaster.js#L142

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're already in a closure

var dolly = new THREE.Object3D();
var standingMatrix = new THREE.Matrix4();
var previousControllerPosition = new THREE.Vector3();
controllerEuler.order = 'YXZ';
return function () {
var controller;
Expand Down Expand Up @@ -74,10 +76,15 @@ module.exports.Component = registerComponent('tracked-controls', {
y: THREE.Math.radToDeg(controllerEuler.y),
z: THREE.Math.radToDeg(controllerEuler.z)
});

deltaControllerPosition.copy(controllerPosition).sub(previousControllerPosition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a good ol' unit test

previousControllerPosition.copy(controllerPosition);
var currentPosition = el.getAttribute('position');

el.setAttribute('position', {
x: controllerPosition.x,
y: controllerPosition.y,
z: controllerPosition.z
x: currentPosition.x + deltaControllerPosition.x,
y: currentPosition.x + deltaControllerPosition.y,
z: currentPosition.x + deltaControllerPosition.z
});
};
})(),
Expand Down