Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/look-controls.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var registerComponent = require('../core/component').registerComponent;
var THREE = require('../lib/three');
var DEFAULT_CAMERA_HEIGHT = require('../constants').DEFAULT_CAMERA_HEIGHT;
var bind = require('../utils/bind');

// To avoid recalculation at every mouse movement tick
Expand All @@ -17,7 +18,9 @@ module.exports.Component = registerComponent('look-controls', {
enabled: {default: true},
hmdEnabled: {default: true},
reverseMouseDrag: {default: false},
standing: {default: true}
standing: {default: true},
userHeight: {default: 0},
Copy link
Member

@dmarcos dmarcos Aug 25, 2017

Choose a reason for hiding this comment

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

Are you using this property anywhere? it seems you are using userHeight from the camera component in getUserHeight

headElement: {type: 'selector'}
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a description for the use cases of this property?

},

init: function () {
Expand Down Expand Up @@ -54,11 +57,21 @@ module.exports.Component = registerComponent('look-controls', {
var data = this.data;
if (!data.enabled) { return; }
this.controls.standing = data.standing;
this.controls.userHeight = this.getUserHeight();
this.controls.update();
this.updateOrientation();
this.updatePosition();
},

/**
* Return user height to use for standing poses, where a device doesn't provide an offset.
*/
getUserHeight: function () {
var headEl = this.data.headElement || this.el.sceneEl.camera.el;
Copy link
Member

Choose a reason for hiding this comment

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

What are the cases where the headElement is not the active camera?

Copy link
Contributor

Choose a reason for hiding this comment

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

(e.g. spectator camera?)

var headCamera = headEl.components.camera;
return (headCamera ? headCamera.data.userHeight : 0) || DEFAULT_CAMERA_HEIGHT;
},

play: function () {
this.addEventListeners();
},
Expand Down
24 changes: 24 additions & 0 deletions tests/components/look-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var CANVAS_GRAB_CLASS = 'a-grab-cursor';
var GRABBING_CLASS = 'a-grabbing';
var DEFAULT_USER_HEIGHT = 1.6;

suite('look-controls', function () {
setup(function (done) {
Expand Down Expand Up @@ -52,4 +53,27 @@ suite('look-controls', function () {
window.dispatchEvent(new Event('mouseup'));
});
});

suite('head-height', 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!

test('Return head height from camera device', function (done) {
var el = this.sceneEl;
var cameraEl = el.camera.el;
var cameraHeight = 2.5;
var lookControls = el.camera.el.components['look-controls'];
cameraEl.setAttribute('camera', 'userHeight', cameraHeight);

assert.shallowDeepEqual(lookControls.getUserHeight(), cameraHeight);
done();
});

test('Return default head height for poses where device does not provide an offset', function (done) {
var el = this.sceneEl;
var lookControls = el.camera.el.components['look-controls'];
var cameraEl = el.camera.el;
cameraEl.components.camera = null;

assert.shallowDeepEqual(lookControls.getUserHeight(), DEFAULT_USER_HEIGHT);
done();
});
});
});