8000 Added support for standing space to VRControls · LikeABossProgrammer/three.js@e4e5db4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4e5db4

Browse files
committed
Added support for standing space to VRControls
1 parent a3c4f15 commit e4e5db4

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

examples/js/controls/VRControls.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ THREE.VRControls = function ( object, onError ) {
99

1010
var vrInput;
1111

12+
var standingMatrix = new THREE.Matrix4();
13+
1214
function gotVRDevices( devices ) {
1315

1416
for ( var i = 0; i < devices.length; i ++ ) {
@@ -48,6 +50,14 @@ THREE.VRControls = function ( object, onError ) {
4850

4951
this.scale = 1;
5052

53+
// If true will use "standing space" coordinate system where y=0 is the
54+
// floor and x=0, z=0 is the center of the room.
55+
this.standing = false;
56+
57+
// Distance from the users eyes to the floor in meters. Used when
58+
// standing=true but the VRDisplay doesn't provide stageParameters.
59+
this.userHeight = 1.6;
60+
5161
this.update = function () {
5262

5363
if ( vrInput ) {
@@ -64,7 +74,11 @@ THREE.VRControls = function ( object, onError ) {
6474

6575
if ( pose.position !== null ) {
6676

67-
object.position.fromArray( pose.position ).multiplyScalar( scope.scale );
77+
object.position.fromArray( pose.position );
78+
79+
} else {
80+
81+
object.position.set( 0, 0, 0 );
6882

6983
}
7084

@@ -81,12 +95,35 @@ THREE.VRControls = function ( object, onError ) {
8195

8296
if ( state.position !== null ) {
8397

84-
object.position.copy( state.position ).multiplyScalar( scope.scale );
98+
object.position.copy( state.position );
99+
100+
} else {
101+
102+
object.position.set( 0, 0, 0 );
103+
104+
}
105+
106+
}
107+
108+
if ( this.standing ) {
109+
110+
if ( vrInput.stageParameters ) {
111+
112+
object.updateMatrix();
113+
114+
standingMatrix.fromArray(vrInput.stageParameters.sittingToStandingTransform);
115+
object.applyMatrix( standingMatrix );
116+
117+
} else {
118+
119+
object.position.setY( object.position.y + this.userHeight );
85120

86121
}
87122

88123
}
89124

125+
object.position.multiplyScalar( scope.scale );
126+
90127
}
91128

92129
};

0 commit comments

Comments
 (0)
0