/// <summary> /// Returns FP precison distanve between two vectors /// </summary> /// <param name="value1"> /// A <see cref="TSVector2"/> /// </param> /// <param name="value2"> /// A <see cref="TSVector2"/> /// </param> /// <returns> /// A <see cref="System.Single"/> /// </returns> public static FP Distance(TSVector2 value1, TSVector2 value2) { FP result; DistanceSquared(ref value1, ref value2, out result); return((FP)FP.Sqrt(result)); }
public static void Normalize(ref TSVector2 value, out TSVector2 result) { FP factor; DistanceSquared(ref value, ref zeroVector, out factor); factor = 1f / (FP)FP.Sqrt(factor); result.x = value.x * factor; result.y = value.y * factor; }
/// <summary> /// Normalizes the given vector. /// </summary> /// <param name="value">The vector which should be normalized.</param> /// <param name="result">A normalized vector.</param> public static void Normalize(ref TSVector value, out TSVector result) { FP num2 = ((value.x * value.x) + (value.y * value.y)) + (value.z * value.z); FP num = FP.One / FP.Sqrt(num2); result.x = value.x * num; result.y = value.y * num; result.z = value.z * num; }
/// <summary> /// Normalizes this vector. /// </summary> public void Normalize() { FP num2 = ((this.x * this.x) + (this.y * this.y)) + (this.z * this.z); FP num = FP.One / FP.Sqrt(num2); this.x *= num; this.y *= num; this.z *= num; }
/// <summary> /// Sets the length of the quaternion to one. /// </summary> #region public void Normalize() public void Normalize() { FP num2 = (((this.x * this.x) + (this.y * this.y)) + (this.z * this.z)) + (this.w * this.w); FP num = 1 / (FP.Sqrt(num2)); this.x *= num; this.y *= num; this.z *= num; this.w *= num; }
public static TSQuaternion FromToRotation(TSVector fromVector, TSVector toVector) { TSVector w = TSVector.Cross(fromVector, toVector); TSQuaternion q = new TSQuaternion(w.x, w.y, w.z, TSVector.Dot(fromVector, toVector)); q.w += FP.Sqrt(fromVector.sqrMagnitude * toVector.sqrMagnitude); q.Normalize(); return(q); }
/// <summary> /// Creates a quaternion from a matrix. /// </summary> /// <param name="matrix">A matrix representing an orientation.</param> /// <param name="result">JQuaternion representing an orientation.</param> public static void CreateFromMatrix(ref TSMatrix matrix, out TSQuaternion result) { FP num8 = (matrix.M11 + matrix.M22) + matrix.M33; if (num8 > FP.Zero) { FP num = FP.Sqrt((num8 + FP.One)); result.w = num * FP.Half; num = FP.Half / num; result.x = (matrix.M23 - matrix.M32) * num; result.y = (matrix.M31 - matrix.M13) * num; result.z = (matrix.M12 - matrix.M21) * num; } else if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) { FP num7 = FP.Sqrt((((FP.One + matrix.M11) - matrix.M22) - matrix.M33)); FP num4 = FP.Half / num7; result.x = FP.Half * num7; result.y = (matrix.M12 + matrix.M21) * num4; result.z = (matrix.M13 + matrix.M31) * num4; result.w = (matrix.M23 - matrix.M32) * num4; } else if (matrix.M22 > matrix.M33) { FP num6 = FP.Sqrt((((FP.One + matrix.M22) - matrix.M11) - matrix.M33)); FP num3 = FP.Half / num6; result.x = (matrix.M21 + matrix.M12) * num3; result.y = FP.Half * num6; result.z = (matrix.M32 + matrix.M23) * num3; result.w = (matrix.M31 - matrix.M13) * num3; } else { FP num5 = FP.Sqrt((((FP.One + matrix.M33) - matrix.M11) - matrix.M22)); FP num2 = FP.Half / num5; result.x = (matrix.M31 + matrix.M13) * num2; result.y = (matrix.M32 + matrix.M23) * num2; result.z = FP.Half * num5; result.w = (matrix.M12 - matrix.M21) * num2; } }
/// <summary> /// Gets the square root. /// </summary> /// <param name="number">The number to get the square root from.</param> /// <returns></returns> #region public static FP Sqrt(FP number) public static FP Sqrt(FP number) { return(FP.Sqrt(number)); }
public static void Distance(ref TSVector2 value1, ref TSVector2 value2, out FP result) { DistanceSquared(ref value1, ref value2, out result); result = (FP)FP.Sqrt(result); }
public static FP Distance(TSVector4 v1, TSVector4 v2) { return(FP.Sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y) + (v1.z - v2.z) * (v1.z - v2.z) + (v1.w - v2.w) * (v1.w - v2.w))); }