/// <summary>Transform a Vector by the given Matrix</summary> /// <param name="vec">The vector to transform</param> /// <param name="mat">The desired transformation</param> /// <param name="result">The transformed vector</param> public static void Transform(ref Vector3d vec, ref Matrix4d mat, out Vector3d result) { Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0); Vector4d.Transform(ref v4, ref mat, out v4); result = v4.Xyz; }
/// <summary>Transform a Vector3d by the given Matrix, and project the resulting Vector4d back to a Vector3d</summary> /// <param name="vec">The vector to transform</param> /// <param name="mat">The desired transformation</param> /// <param name="result">The transformed vector</param> public static void TransformPerspective(ref Vector3d vec, ref Matrix4d mat, out Vector3d result) { Vector4d v = new Vector4d(vec, 1); Vector4d.Transform(ref v, ref mat, out v); result.X = v.X / v.W; result.Y = v.Y / v.W; result.Z = v.Z / v.W; }