Esempio n. 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;
 }
Esempio n. 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
                ));
 }
Esempio n. 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
                ));
 }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 6
0
 // *undoc* --- there's a property now
 public static float SqrMagnitude(THVector4 a)
 {
     return(THVector4.Dot(a, a));
 }
Esempio n. 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)));
 }
Esempio n. 8
0
 // *undoc* --- there's a property now
 public static float Magnitude(THVector4 a)
 {
     return((float)Sqrt(Dot(a, a)));
 }
Esempio n. 9
0
 // Returns the distance between /a/ and /b/.
 public static float Distance(THVector4 a, THVector4 b)
 {
     return(Magnitude(a - b));
 }
Esempio n. 10
0
 // Projects a vector onto another vector.
 public static THVector4 Project(THVector4 a, THVector4 b)
 {
     return(b * Dot(a, b) / Dot(b, b));
 }
Esempio n. 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);
 }
Esempio n. 12
0
 public bool Equals(THVector4 other)
 {
     return(x.Equals(other.x) && y.Equals(other.y) && z.Equals(other.z) && w.Equals(other.w));
 }
Esempio n. 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));
 }