Browse Source

Transform forward/up/right directions

Borut 7 years ago
parent
commit
0885d4f39a
1 changed files with 36 additions and 1 deletions
  1. 36 1
      src/Mesh/babylon.transformNode.ts

+ 36 - 1
src/Mesh/babylon.transformNode.ts

@@ -6,6 +6,11 @@ module BABYLON {
         public static BILLBOARDMODE_Y = 2;
         public static BILLBOARDMODE_Z = 4;
         public static BILLBOARDMODE_ALL = 7;
+        
+        private _forward = new Vector3(0, 0, 1);
+        private _up = new Vector3(0, 1, 0);
+        private _right = new Vector3(0, 1, 0);
+        private _rightInverted = new Vector3(0, -1, 0);
 
         // Properties
         @serializeAsVector3()
@@ -112,6 +117,36 @@ module BABYLON {
         }
 
         /**
+         * The forward direction of that transform in world space.
+         */
+        public get forward(): Vector3 {
+            return Vector3.Normalize(Vector3.TransformNormal(
+                this._forward,
+                this.getWorldMatrix()
+            ));
+        }
+
+        /**
+         * The up direction of that transform in world space.
+         */
+        public get up(): Vector3 {
+            return Vector3.Normalize(Vector3.TransformNormal(
+                this._up,
+                this.getWorldMatrix()
+            ));
+        }
+
+        /**
+         * The up direction of that transform in world space.
+         */
+        public get right(): Vector3 {
+            return Vector3.Normalize(Vector3.TransformNormal(
+                this.getScene().useRightHandedSystem ? this._rightInverted : this._right,
+                this.getWorldMatrix()
+            ));
+        }
+
+        /**
          * Returns the latest update of the World matrix
          * Returns a Matrix.  
          */
@@ -990,4 +1025,4 @@ module BABYLON {
         }
 
     }
-}
+}