瀏覽代碼

Make sure that we teleport where the target was defined

Trevor Baron 7 年之前
父節點
當前提交
3a76b1ce92
共有 1 個文件被更改,包括 14 次插入2 次删除
  1. 14 2
      src/Cameras/VR/babylon.vrExperienceHelper.ts

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

@@ -35,6 +35,7 @@ module BABYLON {
         public onExitingVR: () => void;
         public onExitingVR: () => void;
         public onControllerMeshLoaded: (controller: WebVRController) => void;
         public onControllerMeshLoaded: (controller: WebVRController) => void;
 
 
+        private _hmdOffsetFromPosition = new Vector3(0,0,0);
         private _rayLength: number;
         private _rayLength: number;
         private _useCustomVRButton: boolean = false;
         private _useCustomVRButton: boolean = false;
         private _teleportationRequested: boolean = false;
         private _teleportationRequested: boolean = false;
@@ -817,8 +818,19 @@ module BABYLON {
             }
             }
         }
         }
 
 
+        // webVRCamera.devicePosition is not the actual offset from webVRCamera.position so this function computes
+        // the actual global offset. Left eye is used instead of center to avoid additional computation on each call.
+        private _updateHmdOffsetFromPosition(){
+            if(this.webVRCamera.leftCamera){
+                this._hmdOffsetFromPosition.copyFrom(this.webVRCamera.leftCamera.globalPosition).subtractInPlace(this.webVRCamera.position);
+            }else{
+                this._hmdOffsetFromPosition.copyFrom(this.webVRCamera.devicePosition);
+            }
+        }
+
         private _teleportCamera() {
         private _teleportCamera() {
             this.currentVRCamera.animations = [];
             this.currentVRCamera.animations = [];
+            this._updateHmdOffsetFromPosition();
         
         
             var animationCameraTeleportationX = new BABYLON.Animation("animationCameraTeleportationX", "position.x", 90, BABYLON.Animation.ANIMATIONTYPE_FLOAT,
             var animationCameraTeleportationX = new BABYLON.Animation("animationCameraTeleportationX", "position.x", 90, BABYLON.Animation.ANIMATIONTYPE_FLOAT,
                 BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
                 BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
@@ -830,7 +842,7 @@ module BABYLON {
             });
             });
             animationCameraTeleportationXKeys.push({
             animationCameraTeleportationXKeys.push({
                 frame: 11,
                 frame: 11,
-                value: this._haloCenter.x
+                value: this._haloCenter.x-this._hmdOffsetFromPosition.x
             });
             });
         
         
             var easingFunction = new BABYLON.CircleEase();
             var easingFunction = new BABYLON.CircleEase();
@@ -867,7 +879,7 @@ module BABYLON {
             });
             });
             animationCameraTeleportationZKeys.push({
             animationCameraTeleportationZKeys.push({
                 frame: 11,
                 frame: 11,
-                value: this._haloCenter.z
+                value: this._haloCenter.z-this._hmdOffsetFromPosition.z
             });
             });
         
         
             animationCameraTeleportationZ.setKeys(animationCameraTeleportationZKeys);
             animationCameraTeleportationZ.setKeys(animationCameraTeleportationZKeys);