/// <summary> /// Creates an orthographic projection matrix. /// </summary> /// <param name="left">The left edge of the projection volume.</param> /// <param name="right">The right edge of the projection volume.</param> /// <param name="bottom">The bottom edge of the projection volume.</param> /// <param name="top">The top edge of the projection volume.</param> /// <param name="zNear">The near edge of the projection volume.</param> /// <param name="zFar">The far edge of the projection volume.</param> /// <param name="result">The resulting Matrix4 instance.</param> public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4D result) { result = new Matrix4D(); float invRL = 1 / (right - left); float invTB = 1 / (top - bottom); float invFN = 1 / (zFar - zNear); result.Row0.X = 2 * invRL; result.Row1.Y = 2 * invTB; result.Row2.Z = -2 * invFN; result.Row3.X = -(right + left) * invRL; result.Row3.Y = -(top + bottom) * invTB; result.Row3.Z = -(zFar + zNear) * invFN; result.Row3.W = 1; }
/// <summary> /// Creates an orthographic projection matrix. /// </summary> /// <param name="width">The width of the projection volume.</param> /// <param name="height">The height of the projection volume.</param> /// <param name="depthNear">The near edge of the projection volume.</param> /// <param name="depthFar">The far edge of the projection volume.</param> /// <param name="result">The resulting Matrix4d instance.</param> public static void CreateOrthographic(double width, double height, double depthNear, double depthFar, out Matrix4D result) { CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, depthNear, depthFar, out result); }
/// <summary>Creates a translation matrix.</summary> /// <param name="vector">The translation vector.</param> /// <param name="result">The resulting Matrix4.</param> public static void CreateTranslation(ref Vector3 vector, out Matrix4D result) { result = Identity; result.Row3 = new Vector4(vector.X, vector.Y, vector.Z, 1); }
/// <summary> /// Calculate the transpose of the given matrix /// </summary> /// <param name="mat">The matrix to transpose</param> /// <returns>The transpose of the given matrix</returns> public static Matrix4D Transpose(Matrix4D mat) { return(new Matrix4D(mat.Column0, mat.Column1, mat.Column2, mat.Column3)); }
/// <summary>Creates a translation matrix.</summary> /// <param name="x">X translation.</param> /// <param name="y">Y translation.</param> /// <param name="z">Z translation.</param> /// <param name="result">The resulting Matrix4.</param> public static void CreateTranslation(double x, double y, double z, out Matrix4D result) { result = Identity; result.Row3 = new Vector4(x, y, z, 1); }