Exemple #1
0
 // Multiplies every component of this vector by the same component of /scale/.
 public void Scale(THVector4 scale)
 {
     x *= scale.x;
     y *= scale.y;
     z *= scale.z;
     w *= scale.w;
 }
Exemple #2
0
 /// <summary>
 /// Linearly interpolates between two vectors. <paramref name="t"/> is unclamped
 /// </summary>
 /// <param name="a">First vector</param>
 /// <param name="b">Second vector</param>
 /// <param name="t">Lerp steps</param>
 /// <returns>Lerped vector</returns>
 public static THVector4 LerpUnclamped(THVector4 a, THVector4 b, float t)
 {
     return(new THVector4(
                a.x + (b.x - a.x) * t,
                a.y + (b.y - a.y) * t,
                a.z + (b.z - a.z) * t,
                a.w + (b.w - a.w) * t
                ));
 }
Exemple #3
0
 /// <summary>
 /// Linearly interpolates between two vectors. <paramref name="t"/> is clamped between 0 and 1
 /// </summary>
 /// <param name="a">First vector</param>
 /// <param name="b">Second vector</param>
 /// <param name="t">Lerp steps</param>
 /// <returns>Lerped vector</returns>
 public static THVector4 Lerp(THVector4 a, THVector4 b, float t)
 {
     t = t.Clamp(0, 1);
     return(new THVector4(
                a.x + (b.x - a.x) * t,
                a.y + (b.y - a.y) * t,
                a.z + (b.z - a.z) * t,
                a.w + (b.w - a.w) * t
                ));
 }
Exemple #4
0
        // Moves a point /current/ towards /target/.
        public static THVector4 MoveTowards(THVector4 current, THVector4 target, float maxDistanceDelta)
        {
            THVector4 toVector = target - current;
            float     dist     = toVector.magnitude;

            if (dist <= maxDistanceDelta || dist == 0)
            {
                return(target);
            }
            return(current + toVector / dist * maxDistanceDelta);
        }
Exemple #5
0
        // *undoc* --- we have normalized property now
        public static THVector4 Normalize(THVector4 a)
        {
            float mag = Magnitude(a);

            if (mag > kEpsilon)
            {
                return(a / mag);
            }
            else
            {
                return(zero);
            }
        }
Exemple #6
0
 // *undoc* --- there's a property now
 public static float SqrMagnitude(THVector4 a)
 {
     return(THVector4.Dot(a, a));
 }
Exemple #7
0
 // Returns a vector that is made from the largest components of two vectors.
 public static THVector4 Max(THVector4 lhs, THVector4 rhs)
 {
     return(new THVector4((float)Math.Max(lhs.x, rhs.x), (float)Math.Max(lhs.y, rhs.y), (float)Math.Max(lhs.z, rhs.z), (float)Math.Max(lhs.w, rhs.w)));
 }
Exemple #8
0
 // *undoc* --- there's a property now
 public static float Magnitude(THVector4 a)
 {
     return((float)Sqrt(Dot(a, a)));
 }
Exemple #9
0
 // Returns the distance between /a/ and /b/.
 public static float Distance(THVector4 a, THVector4 b)
 {
     return(Magnitude(a - b));
 }
Exemple #10
0
 // Projects a vector onto another vector.
 public static THVector4 Project(THVector4 a, THVector4 b)
 {
     return(b * Dot(a, b) / Dot(b, b));
 }
Exemple #11
0
 // Dot Product of two vectors.
 public static float Dot(THVector4 a, THVector4 b)
 {
     return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
 }
Exemple #12
0
 public bool Equals(THVector4 other)
 {
     return(x.Equals(other.x) && y.Equals(other.y) && z.Equals(other.z) && w.Equals(other.w));
 }
Exemple #13
0
 // Multiplies two vectors component-wise.
 public static THVector4 Scale(THVector4 a, THVector4 b)
 {
     return(new THVector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w));
 }