@@ -9,6 +9,8 @@ THREE.VRControls = function ( object, onError ) {
9
9
10
10
var vrInput ;
11
11
12
+ var standingMatrix = new THREE . Matrix4 ( ) ;
13
+
12
14
function gotVRDevices ( devices ) {
13
15
14
16
for ( var i = 0 ; i < devices . length ; i ++ ) {
@@ -48,6 +50,14 @@ THREE.VRControls = function ( object, onError ) {
48
50
49
51
this . scale = 1 ;
50
52
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
+
51
61
this . update = function ( ) {
52
62
53
63
if ( vrInput ) {
@@ -64,7 +74,11 @@ THREE.VRControls = function ( object, onError ) {
64
74
65
75
if ( pose . position !== null ) {
66
76
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 ) ;
68
82
69
83
}
70
84
@@ -81,12 +95,35 @@ THREE.VRControls = function ( object, onError ) {
81
95
82
96
if ( state . position !== null ) {
83
97
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 ) ;
85
120
86
121
}
87
122
88
123
}
89
124
125
+ object . position . multiplyScalar ( scope . scale ) ;
126
+
90
127
}
91
128
92
129
} ;
0 commit comments