2
0
Эх сурвалжийг харах

Merge pull request #20901 from KellyThomas/mono-consts

mono: add constants to transform and vector structs
Ignacio Etcheverry 7 жил өмнө
parent
commit
ecd5d0ad12

+ 12 - 1
modules/mono/glue/cs_files/Transform.cs

@@ -102,7 +102,18 @@ namespace Godot
                 basis[0, 2] * vInv.x + basis[1, 2] * vInv.y + basis[2, 2] * vInv.z
             );
         }
-        
+
+        // Constants
+        private static readonly Transform _identity = new Transform(Basis.Identity, Vector3.Zero);
+        private static readonly Transform _flipX = new Transform(new Basis(new Vector3(-1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1)), Vector3.Zero);
+        private static readonly Transform _flipY = new Transform(new Basis(new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1)), Vector3.Zero);
+        private static readonly Transform _flipZ = new Transform(new Basis(new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, -1)), Vector3.Zero);
+
+        public static Transform Identity { get { return _identity; } }
+        public static Transform FlipX { get { return _flipX; } }
+        public static Transform FlipY { get { return _flipY; } }
+        public static Transform FlipZ { get { return _flipZ; } }
+
         // Constructors 
         public Transform(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 origin)
         {

+ 9 - 12
modules/mono/glue/cs_files/Transform2D.cs

@@ -11,22 +11,10 @@ namespace Godot
     [StructLayout(LayoutKind.Sequential)]
     public struct Transform2D : IEquatable<Transform2D>
     {
-        private static readonly Transform2D identity = new Transform2D
-        (
-            new Vector2(1f, 0f),
-            new Vector2(0f, 1f),
-            new Vector2(0f, 0f)
-        );
-
         public Vector2 x;
         public Vector2 y;
         public Vector2 o;
 
-        public static Transform2D Identity
-        {
-            get { return identity; }
-        }
-
         public Vector2 Origin
         {
             get { return o; }
@@ -264,6 +252,15 @@ namespace Godot
             Vector2 vInv = v - o;
             return new Vector2(x.Dot(vInv), y.Dot(vInv));
         }
+
+        // Constants
+        private static readonly Transform2D _identity = new Transform2D(new Vector2(1f, 0f), new Vector2(0f, 1f), Vector2.Zero);
+        private static readonly Transform2D _flipX = new Transform2D(new Vector2(-1f, 0f), new Vector2(0f, 1f), Vector2.Zero);
+        private static readonly Transform2D _flipY = new Transform2D(new Vector2(1f, 0f), new Vector2(0f, -1f), Vector2.Zero);
+
+        public static Transform2D Identity { get { return _identity; } }
+        public static Transform2D FlipX { get { return _flipX; } }
+        public static Transform2D FlipY { get { return _flipY; } }
         
         // Constructors 
         public Transform2D(Vector2 xAxis, Vector2 yAxis, Vector2 origin)

+ 1 - 1
modules/mono/glue/cs_files/VERSION.txt

@@ -1 +1 @@
-8
+9

+ 21 - 18
modules/mono/glue/cs_files/Vector2.cs

@@ -231,24 +231,27 @@ namespace Godot
         {
             return new Vector2(y, -x);
         }
-        
-        private static readonly Vector2 zero   = new Vector2 (0, 0);
-        private static readonly Vector2 one    = new Vector2 (1, 1);
-        private static readonly Vector2 negOne = new Vector2 (-1, -1);
-    
-        private static readonly Vector2 up     = new Vector2 (0, 1);
-        private static readonly Vector2 down   = new Vector2 (0, -1);
-        private static readonly Vector2 right  = new Vector2 (1, 0);
-        private static readonly Vector2 left   = new Vector2 (-1, 0);
-
-        public static Vector2 Zero   { get { return zero;    } }
-        public static Vector2 One    { get { return one;     } }
-        public static Vector2 NegOne { get { return negOne;  } }
-        
-        public static Vector2 Up     { get { return up;      } }
-        public static Vector2 Down   { get { return down;    } }
-        public static Vector2 Right  { get { return right;   } }
-        public static Vector2 Left   { get { return left;    } }
+
+        // Constants
+        private static readonly Vector2 _zero = new Vector2(0, 0);
+        private static readonly Vector2 _one = new Vector2(1, 1);
+        private static readonly Vector2 _negOne = new Vector2(-1, -1);
+        private static readonly Vector2 _inf = new Vector2(Mathf.Inf, Mathf.Inf);
+      
+        private static readonly Vector2 _up = new Vector2(0, -1);
+        private static readonly Vector2 _down = new Vector2(0, 1);
+        private static readonly Vector2 _right  = new Vector2(1, 0);
+        private static readonly Vector2 _left = new Vector2(-1, 0);
+
+        public static Vector2 Zero { get { return _zero; } }
+        public static Vector2 NegOne { get { return _negOne; } }
+        public static Vector2 One { get { return _one; } }
+        public static Vector2 Inf { get { return _inf; } }
+
+        public static Vector2 Up { get { return _up; } }
+        public static Vector2 Down { get { return _down; } }
+        public static Vector2 Right { get { return _right; } }
+        public static Vector2 Left { get { return _left; } }
 
         // Constructors
         public Vector2(real_t x, real_t y)

+ 22 - 19
modules/mono/glue/cs_files/Vector3.cs

@@ -272,27 +272,30 @@ namespace Godot
             );
         }
         
-        private static readonly Vector3 zero    = new Vector3 (0, 0, 0);
-        private static readonly Vector3 one     = new Vector3 (1, 1, 1);
-        private static readonly Vector3 negOne  = new Vector3 (-1, -1, -1);
+        // Constants
+        private static readonly Vector3 _zero = new Vector3(0, 0, 0);
+        private static readonly Vector3 _one = new Vector3(1, 1, 1);
+        private static readonly Vector3 _negOne = new Vector3(-1, -1, -1);
+        private static readonly Vector3 _inf = new Vector3(Mathf.Inf, Mathf.Inf, Mathf.Inf);
     
-        private static readonly Vector3 up      = new Vector3 (0, 1, 0);
-        private static readonly Vector3 down    = new Vector3 (0, -1, 0);
-        private static readonly Vector3 right   = new Vector3 (1, 0, 0);
-        private static readonly Vector3 left    = new Vector3 (-1, 0, 0);
-        private static readonly Vector3 forward = new Vector3 (0, 0, -1);
-        private static readonly Vector3 back    = new Vector3 (0, 0, 1);
-
-        public static Vector3 Zero    { get { return zero;    } }
-        public static Vector3 One     { get { return one;     } }
-        public static Vector3 NegOne  { get { return negOne;  } }
+        private static readonly Vector3 _up = new Vector3(0, 1, 0);
+        private static readonly Vector3 _down = new Vector3(0, -1, 0);
+        private static readonly Vector3 _right = new Vector3(1, 0, 0);
+        private static readonly Vector3 _left = new Vector3(-1, 0, 0);
+        private static readonly Vector3 _forward = new Vector3(0, 0, -1);
+        private static readonly Vector3 _back = new Vector3(0, 0, 1);
+
+        public static Vector3 Zero { get { return _zero; } }
+        public static Vector3 One { get { return _one; } }
+        public static Vector3 NegOne { get { return _negOne; } }
+        public static Vector3 Inf { get { return _inf; } }
         
-        public static Vector3 Up      { get { return up;      } }
-        public static Vector3 Down    { get { return down;    } }
-        public static Vector3 Right   { get { return right;   } }
-        public static Vector3 Left    { get { return left;    } }
-        public static Vector3 Forward { get { return forward; } }
-        public static Vector3 Back    { get { return back;    } }
+        public static Vector3 Up { get { return _up; } }
+        public static Vector3 Down { get { return _down; } }
+        public static Vector3 Right { get { return _right; } }
+        public static Vector3 Left { get { return _left; } }
+        public static Vector3 Forward { get { return _forward; } }
+        public static Vector3 Back { get { return _back; } }
 
         // Constructors
         public Vector3(real_t x, real_t y, real_t z)