Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix control transform components and rotationOffset
  • Loading branch information
brianpeiris committed Feb 28, 2018
commit e10a9cec359f97e66cf9d1edc8d0684a4d167159
7 changes: 6 additions & 1 deletion src/components/tracked-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ module.exports.Component = registerComponent('tracked-controls', {
object3D.matrixAutoUpdate = false;
object3D.matrix.compose(object3D.position, object3D.quaternion, object3D.scale);
object3D.matrix.multiplyMatrices(standingMatrix, object3D.matrix);
object3D.matrixWorldNeedsUpdate = true;
object3D.matrix.decompose(object3D.position, object3D.quaternion, object3D.scale);
}

object3D.rotateZ(this.data.rotationOffset * THREE.Math.DEG2RAD);

object3D.updateMatrix();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't tested this PR in a Daydream/GearVR with a 3DoF controller yet. We disable matrixAutoUpdate in init, so I'm not sure how this code could have worked for those controllers without an explicit updateMatrix. Perhaps it was actually broken. I'll test with a 3DoF controller when I get a chance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Confirmed. Daydream controller does not update without this.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for testing on it.

object3D.matrixWorldNeedsUpdate = true;
},

/**
Expand Down
23 changes: 22 additions & 1 deletion tests/components/tracked-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ suite('tracked-controls', function () {
var controller;
var el;
var system;
var standingMatrix = new THREE.Matrix4();

setup(function (done) {
standingMatrix.identity();
el = entityFactory();
el.setAttribute('position', '');
el.setAttribute('tracked-controls', '');
el.addEventListener('loaded', function () {
el.parentNode.renderer.vr.getStandingMatrix = function () {
return new THREE.Matrix4();
return standingMatrix;
};
component = el.components['tracked-controls'];
system = component.system;
Expand Down Expand Up @@ -130,6 +132,14 @@ suite('tracked-controls', function () {
component.tick();
assertVec3(el.getAttribute('position'), [2, 4, 6]);
});

test('applies standing matrix transform', function () {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the tests

standingMatrix.makeTranslation(1, 0.5, -3);
controller.pose.position = [1, 2, 3];
el.sceneEl.systems['tracked-controls'].vrDisplay = true;
component.tick();
assertVec3(el.getAttribute('position'), [2, 2.5, 0]);
});
});

suite('updatePose (rotation)', function () {
Expand Down Expand Up @@ -166,6 +176,13 @@ suite('tracked-controls', function () {
component.tick();
assertQuaternion(el.object3D.quaternion, controller.pose.orientation);
});

test('applies rotation Z-offset', function () {
el.setAttribute('tracked-controls', 'rotationOffset', 10);
component.tick();
assertVec3(el.getAttribute('rotation'), [0, 0, 10]);
assertMatrix4(el.object3D.matrix, new THREE.Matrix4().makeRotationZ(10 * THREE.Math.DEG2RAD));
});
});

suite('handleAxes', function () {
Expand Down Expand Up @@ -398,6 +415,10 @@ suite('tracked-controls', function () {
});
});

function assertMatrix4 (matrixA, matrixB) {
assert.ok(matrixA.equals(matrixB), `\n${matrixA.elements}\n${matrixB.elements}`);
}

function assertVec3 (vec3, arr) {
assert.equal(vec3.x, arr[0]);
assert.equal(vec3.y, arr[1]);
Expand Down