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