Skip to content

Commit bb747ff

Browse files
Lewis Weaverolga-microsoft
authored andcommitted
Fixed head height on VRDisplays that do not provide the optional stageParameters attribute.
1 parent c067927 commit bb747ff

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

‎src/components/look-controls.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var registerComponent = require('../core/component').registerComponent;
22
var THREE = require('../lib/three');
3+
var DEFAULT_CAMERA_HEIGHT = require('../constants').DEFAULT_CAMERA_HEIGHT;
34
var bind = require('../utils/bind');
45

56
// To avoid recalculation at every mouse movement tick
@@ -17,7 +18,9 @@ module.exports.Component = registerComponent('look-controls', {
1718
enabled: {default: true},
1819
hmdEnabled: {default: true},
1920
reverseMouseDrag: {default: false},
20-
standing: {default: true}
21+
standing: {default: true},
22+
userHeight: {default: 0},
23+
headElement: {type: 'selector'}
2124
},
2225

2326
init: function () {
@@ -54,11 +57,21 @@ module.exports.Component = registerComponent('look-controls', {
5457
var data = this.data;
5558
if (!data.enabled) { return; }
5659
this.controls.standing = data.standing;
60+
this.controls.userHeight = this.getUserHeight();
5761
this.controls.update();
5862
this.updateOrientation();
5963
this.updatePosition();
6064
},
6165

66+
/**
67+
* Return user height to use for standing poses, where a device doesn't provide an offset.
68+
*/
69+
getUserHeight: function () {
70+
var headEl = this.data.headElement || this.el.sceneEl.camera.el;
71+
var headCamera = headEl.components.camera;
72+
return (headCamera ? headCamera.data.userHeight : 0) || DEFAULT_CAMERA_HEIGHT;
73+
},
74+
6275
play: function () {
6376
this.addEventListeners();
6477
},

‎tests/components/look-controls.test.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var CANVAS_GRAB_CLASS = 'a-grab-cursor';
44
var GRABBING_CLASS = 'a-grabbing';
5+
var DEFAULT_USER_HEIGHT = 1.6;
56

67
suite('look-controls', function () {
78
setup(function (done) {
@@ -52,4 +53,27 @@ suite('look-controls', function () {
5253
window.dispatchEvent(new Event('mouseup'));
5354
});
5455
});
56+
57+
suite('head-height', function () {
58+
test('Return head height from camera device', function (done) {
59+
var el = this.sceneEl;
60+
var cameraEl = el.camera.el;
61+
var cameraHeight = 2.5;
62+
var lookControls = el.camera.el.components['look-controls'];
63+
cameraEl.setAttribute('camera', 'userHeight', cameraHeight);
64+
65+
assert.shallowDeepEqual(lookControls.getUserHeight(), cameraHeight);
66+
done();
67+
});
68+
69+
test('Return default head height for poses where device does not provide an offset', function (done) {
70+
var el = this.sceneEl;
71+
var lookControls = el.camera.el.components['look-controls'];
72+
var cameraEl = el.camera.el;
73+
cameraEl.components.camera = null;
74+
75+
assert.shallowDeepEqual(lookControls.getUserHeight(), DEFAULT_USER_HEIGHT);
76+
done();
77+
});
78+
});
5579
});

0 commit comments

Comments
 (0)