浏览代码

Merge pull request #1847 from RaananW/webvr-getTarget-fix

getTarget stopped working - now fixed
Raanan Weber 8 年之前
父节点
当前提交
9a9dd7c8ba
共有 3 个文件被更改,包括 13 次插入5 次删除
  1. 11 3
      src/Cameras/VR/babylon.webVRCamera.ts
  2. 1 1
      src/Cameras/babylon.targetCamera.ts
  3. 1 1
      src/Tools/babylon.extendedGamepad.ts

+ 11 - 3
src/Cameras/VR/babylon.webVRCamera.ts

@@ -64,9 +64,6 @@ module BABYLON {
             this.rotationQuaternion = new Quaternion();
             this.deviceRotationQuaternion = new Quaternion();
 
-            //using the position provided as the current position offset
-            this._positionOffset = position;
-
             if (this.webVROptions && this.webVROptions.positionScale) {
                 this.deviceScaleFactor = this.webVROptions.positionScale;
             }
@@ -240,9 +237,20 @@ module BABYLON {
                 this._tempMatrix.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             }
 
+            this._updateCameraRotationMatrix();
+            Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
+
+            // Computing target for getTarget()
+            this._webvrViewMatrix.getTranslationToRef(this._positionOffset);
+            this._positionOffset.addToRef(this._transformedReferencePoint, this._currentTarget);
+
             return this._webvrViewMatrix;
         }
 
+        protected _updateCameraRotationMatrix() {
+            this._webvrViewMatrix.getRotationMatrixToRef(this._cameraRotationMatrix);
+        }
+
         public _isSynchronizedViewMatrix() {
             return false;
         }

+ 1 - 1
src/Cameras/babylon.targetCamera.ts

@@ -219,7 +219,7 @@ module BABYLON {
             super._checkInputs();
         }
 
-        private _updateCameraRotationMatrix() {
+        protected _updateCameraRotationMatrix() {
             if (this.rotationQuaternion) {
                 this.rotationQuaternion.toRotationMatrix(this._cameraRotationMatrix);
                 //update the up vector!

+ 1 - 1
src/Tools/babylon.extendedGamepad.ts

@@ -57,7 +57,7 @@ module BABYLON {
         public update() {
             super.update();
             // update this device's offset position from the attached camera, if provided
-            if (this._poseControlledCamera) {
+            if (this._poseControlledCamera && this._poseControlledCamera.deviceScaleFactor) {
                 //this.position.copyFrom(this._poseControlledCamera.position);
                 //this.rotationQuaternion.copyFrom(this._poseControlledCamera.rotationQuaternion);
                 this.deviceScaleFactor = this._poseControlledCamera.deviceScaleFactor;