diff --git a/src/components/look-controls.js b/src/components/look-controls.js index 9e779414b10..517e97f3271 100644 --- a/src/components/look-controls.js +++ b/src/components/look-controls.js @@ -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 @@ -56,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 el = this.el; + var userHeight = el.hasAttribute('camera') && el.getAttribute('camera').userHeight || DEFAULT_CAMERA_HEIGHT; + return userHeight; + }, + play: function () { this.addEventListeners(); }, diff --git a/tests/components/look-controls.test.js b/tests/components/look-controls.test.js index 609a996c025..098bc9ac905 100644 --- a/tests/components/look-controls.test.js +++ b/tests/components/look-controls.test.js @@ -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) { @@ -52,4 +53,27 @@ suite('look-controls', function () { window.dispatchEvent(new Event('mouseup')); }); }); + + suite('head-height', function () { + 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(); + }); + }); });