Browse Source

Add ClampedLerp to Vector3

Matt Benic 9 years ago
parent
commit
898c931246
1 changed files with 39 additions and 0 deletions
  1. 39 0
      Script/AtomicNET/AtomicNET/Math/Vector3.cs

+ 39 - 0
Script/AtomicNET/AtomicNET/Math/Vector3.cs

@@ -924,6 +924,45 @@ namespace AtomicEngine
             result.Z = blend * (b.Z - a.Z) + a.Z;
         }
 
+        /// <summary>
+        /// Returns a new Vector that is the linear blend of the 2 given Vectors
+        /// </summary>
+        /// <param name="a">First input vector</param>
+        /// <param name="b">Second input vector</param>
+        /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
+        /// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
+        public static Vector3 ClampedLerp(Vector3 a, Vector3 b, float blend)
+        {
+            if (blend > 1)
+                blend = 1;
+            else if (blend < 0)
+                blend = 0;
+
+            a.X = blend * (b.X - a.X) + a.X;
+            a.Y = blend * (b.Y - a.Y) + a.Y;
+            a.Z = blend * (b.Z - a.Z) + a.Z;
+            return a;
+        }
+
+        /// <summary>
+        /// Returns a new Vector that is the linear blend of the 2 given Vectors
+        /// </summary>
+        /// <param name="a">First input vector</param>
+        /// <param name="b">Second input vector</param>
+        /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
+        /// <param name="result">a when blend=0, b when blend=1, and a linear combination otherwise</param>
+        public static void ClampedLerp(ref Vector3 a, ref Vector3 b, float blend, out Vector3 result)
+        {
+            if (blend > 1)
+                blend = 1;
+            else if (blend < 0)
+                blend = 0;
+
+            result.X = blend * (b.X - a.X) + a.X;
+            result.Y = blend * (b.Y - a.Y) + a.Y;
+            result.Z = blend * (b.Z - a.Z) + a.Z;
+        }
+
         #endregion
 
         #region Barycentric