فهرست منبع

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 6 سال پیش
والد
کامیت
1ddd4db143

+ 1 - 0
dist/preview release/what's new.md

@@ -48,6 +48,7 @@
   - Added an `Vector3.UnprojectRayToRef` static function to avoid computing and inverting the projection matrix twice when updating a Ray.
 - Align `BoundingBox` and `BoundingSphere` API and behavior for clarity and simplicity. As a consequence, the `BoundingBox`'s method `setWorldMatrix` has been removed and the underlying world matrix cannot be modified but by calling `reConstruct` or `update`. ([barroij](https://github.com/barroij))
 - Make sure that `Material.markAsDirty` and all the `markXXXDirty` methods early out when `scene.blockMaterialDirtyMechanism` is true. ([barroij](https://github.com/barroij))
+- Add updateUpVectorFromRotation to target camera to allow the up vector to be computed from rotation ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

+ 1 - 0
src/Cameras/XR/babylon.webXRCamera.ts

@@ -18,6 +18,7 @@ module BABYLON {
             this.minZ = 0;
             this.rotationQuaternion = new BABYLON.Quaternion();
             this.cameraRigMode = BABYLON.Camera.RIG_MODE_CUSTOM;
+            this.updateUpVectorFromRotation = true;
             this._updateNumberOfRigCameras(1);
         }
 

+ 16 - 4
src/Cameras/babylon.targetCamera.ts

@@ -14,6 +14,11 @@ module BABYLON {
          * Define the current rotation the camera is rotating to
          */
         public cameraRotation = new Vector2(0, 0);
+        /**
+         * When set, the up vector of the camera will be updated by the rotation of the camera
+         */
+        public updateUpVectorFromRotation = false;
+        private _tmpQuaternion = new Quaternion();
 
         /**
          * Define the current rotation of the camera
@@ -178,7 +183,7 @@ module BABYLON {
 
             this._cache.rotation.copyFrom(this.rotation);
             if (this.rotationQuaternion) {
-                this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
+                this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion);
             }
         }
 
@@ -294,10 +299,10 @@ module BABYLON {
                     var limit = (Math.PI / 2) * 0.95;
 
                     if (this.rotation.x > limit) {
-                        this.rotation.x = limit;
+                        this.rotation.x = limit;
                     }
                     if (this.rotation.x < -limit) {
-                        this.rotation.x = -limit;
+                        this.rotation.x = -limit;
                     }
                 }
             }
@@ -373,7 +378,14 @@ module BABYLON {
 
             // Computing target and final matrix
             this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
-
+            if (this.updateUpVectorFromRotation) {
+                if (this.rotationQuaternion) {
+                    Axis.Y.rotateByQuaternionToRef(this.rotationQuaternion, this.upVector);
+                } else {
+                    Quaternion.FromEulerVectorToRef(this.rotation, this._tmpQuaternion);
+                    Axis.Y.rotateByQuaternionToRef(this._tmpQuaternion, this.upVector);
+                }
+            }
             this._computeViewMatrix(this.position, this._currentTarget, this.upVector);
             return this._viewMatrix;
         }

+ 1 - 1
tests/validation/config.json

@@ -3,7 +3,7 @@
   "tests": [
     {
       "title": "XR camera container rotation",
-      "playgroundId": "#JV98QW#4",
+      "playgroundId": "#JV98QW#5",
       "referenceImage": "xrCameraContainerRotation.png",
       "excludeFromAutomaticTesting": true
     },