/// <summary> /// Transforms a vector by the given matrix. /// </summary> /// <param name="position">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <returns>The transformed vector.</returns> #region public static JVector Transform(JVector position, JMatrix matrix) public static TSVector Transform(TSVector position, TSMatrix matrix) { TSVector result; TSVector.Transform(ref position, ref matrix, out result); return(result); }
/// <summary> /// Creates a quaternion from a matrix. /// </summary> /// <param name="matrix">A matrix representing an orientation.</param> /// <returns>JQuaternion representing an orientation.</returns> #region public static JQuaternion CreateFromMatrix(JMatrix matrix) public static TSQuaternion CreateFromMatrix(TSMatrix matrix) { TSQuaternion result; TSQuaternion.CreateFromMatrix(ref matrix, out result); return(result); }
/// <summary> /// Transforms a vector by the transposed of the given Matrix. /// </summary> /// <param name="position">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <param name="result">The transformed vector.</param> public static void TransposedTransform(ref TSVector position, ref TSMatrix matrix, out TSVector result) { FP num0 = ((position.x * matrix.M11) + (position.y * matrix.M12)) + (position.z * matrix.M13); FP num1 = ((position.x * matrix.M21) + (position.y * matrix.M22)) + (position.z * matrix.M23); FP num2 = ((position.x * matrix.M31) + (position.y * matrix.M32)) + (position.z * matrix.M33); result.x = num0; result.y = num1; result.z = num2; }
/** * @brief Rotates game object based on provided axis, point and angle of rotation. **/ public void RotateAround(TSVector point, TSVector axis, FP angle) { TSVector vector = this.position; TSVector vector2 = vector - point; vector2 = TSVector.Transform(vector2, TSMatrix.AngleAxis(angle * FP.Deg2Rad, axis)); vector = point + vector2; this.position = vector; Rotate(axis, angle); }
/// <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; } }
/** * @brief Moves game object based on provided translation vector and a relative {@link TSTransform}. * * The game object will move based on TSTransform's forward vector. **/ public void Translate(TSVector translation, TSTransform relativeTo) { this.position += TSVector.Transform(translation, TSMatrix.CreateFromQuaternion(relativeTo.rotation)); }
/** * @brief Rotates game object to point forward vector to a target position. * * @param target Target position. **/ public void LookAt(TSVector target) { this.rotation = TSQuaternion.CreateFromMatrix(TSMatrix.CreateFromLookAt(position, target)); }
public static TSQuaternion LookRotation(TSVector forward, TSVector upwards) { return(CreateFromMatrix(TSMatrix.LookAt(forward, upwards))); }