浏览代码

use standing matrix by default in vr helper, distance from room floor when teleporting when availible

Trevor Baron 7 年之前
父节点
当前提交
39444e0c07
共有 2 个文件被更改,包括 25 次插入4 次删除
  1. 6 2
      src/Cameras/VR/babylon.vrExperienceHelper.ts
  2. 19 2
      src/Cameras/VR/babylon.webVRCamera.ts

+ 6 - 2
src/Cameras/VR/babylon.vrExperienceHelper.ts

@@ -221,7 +221,7 @@ module BABYLON {
             this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
             }
             this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
-
+            this._webVRCamera.useStandingMatrix()
             // Create default button
             if (!this._useCustomVRButton) {
                 this._btnVR = <HTMLButtonElement>document.createElement("BUTTON");
@@ -1119,7 +1119,11 @@ module BABYLON {
                 this._workingVector.copyFrom(location);
             }
             // Add height to account for user's height offset
-            this._workingVector.y += this._defaultHeight;
+            if(this.isInVRMode){
+                this._workingVector.y += this.webVRCamera.deviceDistanceToRoomGround();
+            }else{
+                this._workingVector.y += this._defaultHeight;
+            }
 
             // Create animation from the camera's position to the new location
             this.currentVRCamera.animations = [];

+ 19 - 2
src/Cameras/VR/babylon.webVRCamera.ts

@@ -75,11 +75,13 @@ module BABYLON {
 
         private _lightOnControllers: BABYLON.HemisphericLight;
 
+        private _defaultHeight = 0;
         constructor(name: string, position: Vector3, scene: Scene, private webVROptions: WebVROptions = {}) {
             super(name, position, scene);
             this._cache.position = Vector3.Zero();
             if(webVROptions.defaultHeight){
-                this.position.y = webVROptions.defaultHeight;
+                this._defaultHeight = webVROptions.defaultHeight;
+                this.position.y = this._defaultHeight;
             }
             
             this.minZ = 0.1;
@@ -162,6 +164,16 @@ module BABYLON {
             });
         }
 
+        public deviceDistanceToRoomGround = ()=>{
+            if(this._standingMatrix){
+                // Add standing matrix offset to get real offset from ground in room
+                this._standingMatrix.getTranslationToRef(this._workingVector);
+                return this._deviceRoomPosition.y+this._workingVector.y
+            }else{
+                return this._defaultHeight;
+            }
+        }
+
         public useStandingMatrix = ()=>{
             return new Promise<boolean>((res, rej)=>{
                 // Use standing matrix if availible
@@ -181,9 +193,14 @@ module BABYLON {
                                     }
                                 });
                             }
-    
                             // Move starting headset position by standing matrix
                             this._deviceToWorld.multiplyToRef(this._standingMatrix, this._deviceToWorld);
+
+                            // Correct for default height added originally
+                            var pos =  this._deviceToWorld.getTranslation()
+                            pos.y -= this._defaultHeight;
+                            this._deviceToWorld.setTranslation(pos)
+                            res(true)
                         }
                     })
                 }