Matrix4X4
Represents a 4x4 Matrix with double-precision components.
Implements: IEquatable<Matrix4X4>
Constructors
public Matrix4X4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3)
matrix4X4 = Matrix4X4(row0, row1, row2, row3)
Constructs a new instance.
- row0
- Top row of the matrix
- row1
- Second row of the matrix
- row2
- Third row of the matrix
- row3
- Bottom row of the matrix
public Matrix4X4(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33)
matrix4X4 = Matrix4X4(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)
Constructs a new instance.
- m00
- First item of the first row.
- m01
- Second item of the first row.
- m02
- Third item of the first row.
- m03
- Fourth item of the first row.
- m10
- First item of the second row.
- m11
- Second item of the second row.
- m12
- Third item of the second row.
- m13
- Fourth item of the second row.
- m20
- First item of the third row.
- m21
- Second item of the third row.
- m22
- Third item of the third row.
- m23
- First item of the third row.
- m30
- Fourth item of the fourth row.
- m31
- Second item of the fourth row.
- m32
- Third item of the fourth row.
- m33
- Fourth item of the fourth row.
Properties
public double Determinant { get; }
value = matrix4X4.Determinant
The determinant of this matrix
public double M11 { get; set; }
value = matrix4X4.M11
matrix4X4.M11 = value
Gets or sets the value at row 1, column 1 of this instance.
public double M12 { get; set; }
value = matrix4X4.M12
matrix4X4.M12 = value
Gets or sets the value at row 1, column 2 of this instance.
public double M13 { get; set; }
value = matrix4X4.M13
matrix4X4.M13 = value
Gets or sets the value at row 1, column 3 of this instance.
public double M14 { get; set; }
value = matrix4X4.M14
matrix4X4.M14 = value
Gets or sets the value at row 1, column 4 of this instance.
public double M21 { get; set; }
value = matrix4X4.M21
matrix4X4.M21 = value
Gets or sets the value at row 2, column 1 of this instance.
public double M22 { get; set; }
value = matrix4X4.M22
matrix4X4.M22 = value
Gets or sets the value at row 2, column 2 of this instance.
public double M23 { get; set; }
value = matrix4X4.M23
matrix4X4.M23 = value
Gets or sets the value at row 2, column 3 of this instance.
public double M24 { get; set; }
value = matrix4X4.M24
matrix4X4.M24 = value
Gets or sets the value at row 2, column 4 of this instance.
public double M31 { get; set; }
value = matrix4X4.M31
matrix4X4.M31 = value
Gets or sets the value at row 3, column 1 of this instance.
public double M32 { get; set; }
value = matrix4X4.M32
matrix4X4.M32 = value
Gets or sets the value at row 3, column 2 of this instance.
public double M33 { get; set; }
value = matrix4X4.M33
matrix4X4.M33 = value
Gets or sets the value at row 3, column 3 of this instance.
public double M34 { get; set; }
value = matrix4X4.M34
matrix4X4.M34 = value
Gets or sets the value at row 3, column 4 of this instance.
public double M41 { get; set; }
value = matrix4X4.M41
matrix4X4.M41 = value
Gets or sets the value at row 4, column 1 of this instance.
public double M42 { get; set; }
value = matrix4X4.M42
matrix4X4.M42 = value
Gets or sets the value at row 4, column 2 of this instance.
public double M43 { get; set; }
value = matrix4X4.M43
matrix4X4.M43 = value
Gets or sets the value at row 4, column 3 of this instance.
public double M44 { get; set; }
value = matrix4X4.M44
matrix4X4.M44 = value
Gets or sets the value at row 4, column 4 of this instance.
public Vector3 Position { get; }
value = matrix4X4.Position
Get just the position out of the matrix.
Methods
public static void CreateFromAxisAngle(Vector3 axis, double angle, Matrix4X4 result)
Matrix4X4.CreateFromAxisAngle(axis, angle, result)
Build a rotation matrix from the specified axis/angle rotation.
- axis
- The axis to rotate about.
- angle
- Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).
- result
- A matrix instance.
public static Matrix4X4 CreateFromAxisAngle(Vector3 axis, double angle)
result = Matrix4X4.CreateFromAxisAngle(axis, angle)
Build a rotation matrix from the specified axis/angle rotation.
- axis
- The axis to rotate about.
- angle
- Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).
Returns: A matrix instance.
public static void CreateOrthographic(double width, double height, double zNear, double zFar, Matrix4X4 result)
Matrix4X4.CreateOrthographic(width, height, zNear, zFar, result)
Creates an orthographic projection matrix.
- width
- The width of the projection volume.
- height
- The height of the projection volume.
- zNear
- The near edge of the projection volume.
- zFar
- The far edge of the projection volume.
- result
- The resulting Matrix4d instance.
public static Matrix4X4 CreateOrthographic(double width, double height, double zNear, double zFar)
result = Matrix4X4.CreateOrthographic(width, height, zNear, zFar)
Creates an orthographic projection matrix.
- width
- The width of the projection volume.
- height
- The height of the projection volume.
- zNear
- The near edge of the projection volume.
- zFar
- The far edge of the projection volume.
public static Matrix4X4 CreateOrthographicOffCenter(double left, double right, double bottom, double top, double zNear, double zFar)
result = Matrix4X4.CreateOrthographicOffCenter(left, right, bottom, top, zNear, zFar)
Creates an orthographic projection matrix.
- left
- The left edge of the projection volume.
- right
- The right edge of the projection volume.
- bottom
- The bottom edge of the projection volume.
- top
- The top edge of the projection volume.
- zNear
- The near edge of the projection volume.
- zFar
- The far edge of the projection volume.
Returns: The resulting Matrix4d instance.
public static void CreateOrthographicOffCenter(double left, double right, double bottom, double top, double zNear, double zFar, Matrix4X4 result)
Matrix4X4.CreateOrthographicOffCenter(left, right, bottom, top, zNear, zFar, result)
Creates an orthographic projection matrix.
- left
- The left edge of the projection volume.
- right
- The right edge of the projection volume.
- bottom
- The bottom edge of the projection volume.
- top
- The top edge of the projection volume.
- zNear
- The near edge of the projection volume.
- zFar
- The far edge of the projection volume.
- result
- The resulting Matrix4d instance.
public static void CreatePerspectiveFieldOfView(double fovYRadians, double aspectWidthOverHeight, double zNear, double zFar, Matrix4X4 result)
Matrix4X4.CreatePerspectiveFieldOfView(fovYRadians, aspectWidthOverHeight, zNear, zFar, result)
Creates a perspective projection matrix.
- fovYRadians
- Angle of the field of view in the y direction (in radians)
- aspectWidthOverHeight
- Aspect ratio of the view (width / height)
- zNear
- Distance to the near clip plane
- zFar
- Distance to the far clip plane
- result
- A projection matrix that transforms camera space to raster space
public static Matrix4X4 CreatePerspectiveFieldOfView(double fovYRadians, double aspectWidthOverHeight, double zNear, double zFar)
result = Matrix4X4.CreatePerspectiveFieldOfView(fovYRadians, aspectWidthOverHeight, zNear, zFar)
Creates a perspective projection matrix.
- fovYRadians
- Angle of the field of view in the y direction (in radians)
- aspectWidthOverHeight
- Aspect ratio of the view (width / height)
- zNear
- Distance to the near clip plane
- zFar
- Distance to the far clip plane
Returns: A projection matrix that transforms camera space to raster space
public static void CreatePerspectiveOffCenter(double left, double right, double bottom, double top, double zNear, double zFar, Matrix4X4 result)
Matrix4X4.CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, result)
Creates an perspective projection matrix.
- left
- Left edge of the view frustum
- right
- Right edge of the view frustum
- bottom
- Bottom edge of the view frustum
- top
- Top edge of the view frustum
- zNear
- Distance to the near clip plane
- zFar
- Distance to the far clip plane
- result
- A projection matrix that transforms camera space to raster space
public static Matrix4X4 CreatePerspectiveOffCenter(double left, double right, double bottom, double top, double zNear, double zFar)
result = Matrix4X4.CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar)
Creates an perspective projection matrix.
- left
- Left edge of the view frustum
- right
- Right edge of the view frustum
- bottom
- Bottom edge of the view frustum
- top
- Top edge of the view frustum
- zNear
- Distance to the near clip plane
- zFar
- Distance to the far clip plane
Returns: A projection matrix that transforms camera space to raster space
public static Matrix4X4 CreateRotation(Vector3 axis, double angle)
result = Matrix4X4.CreateRotation(axis, angle)
Build a rotation matrix to rotate about the given axis
- axis
- the axis to rotate about
- angle
- angle in radians to rotate counter-clockwise (looking in the direction of the given axis)
Returns: A rotation matrix
public static Matrix4X4 CreateRotation(Quaternion q)
result = Matrix4X4.CreateRotation(q)
Build a rotation matrix from a quaternion
- q
- the quaternion
Returns: A rotation matrix
public static void CreateRotationX(double angle, Matrix4X4 result)
Matrix4X4.CreateRotationX(angle, result)
Builds a rotation matrix for a rotation around the x-axis.
- angle
- The counter-clockwise angle in radians.
- result
- The resulting Matrix4 instance.
public static Matrix4X4 CreateRotationX(double angle)
result = Matrix4X4.CreateRotationX(angle)
Builds a rotation matrix for a rotation around the x-axis.
- angle
- The counter-clockwise angle in radians.
Returns: The resulting Matrix4 instance.
public static Matrix4X4 CreateRotationY(double angle)
result = Matrix4X4.CreateRotationY(angle)
Builds a rotation matrix for a rotation around the y-axis.
- angle
- The counter-clockwise angle in radians.
Returns: The resulting Matrix4 instance.
public static void CreateRotationY(double angle, Matrix4X4 result)
Matrix4X4.CreateRotationY(angle, result)
Builds a rotation matrix for a rotation around the y-axis.
- angle
- The counter-clockwise angle in radians.
- result
- The resulting Matrix4 instance.
public static Matrix4X4 CreateRotationZ(double angle)
result = Matrix4X4.CreateRotationZ(angle)
Builds a rotation matrix for a rotation around the z-axis.
- angle
- The counter-clockwise angle in radians.
Returns: The resulting Matrix4 instance.
public static void CreateRotationZ(double angle, Matrix4X4 result)
Matrix4X4.CreateRotationZ(angle, result)
Builds a rotation matrix for a rotation around the z-axis.
- angle
- The counter-clockwise angle in radians.
- result
- The resulting Matrix4 instance.
public static Matrix4X4 CreateScale(double x, double y, double z)
result = Matrix4X4.CreateScale(x, y, z)
Build a scaling matrix
- x
- Scale factor for x-axis
- y
- Scale factor for y-axis
- z
- Scale factor for z-axis
Returns: A scaling matrix
public static Matrix4X4 CreateScale(Vector3 scale)
result = Matrix4X4.CreateScale(scale)
Build a scaling matrix
- scale
- Scale factors for x,y and z axes
Returns: A scaling matrix
public static Matrix4X4 CreateScale(double scale)
result = Matrix4X4.CreateScale(scale)
Build a scaling matrix
- scale
- Single scale factor for x,y and z axes
Returns: A scaling matrix
public static void CreateTranslation(double x, double y, double z, Matrix4X4 result)
Matrix4X4.CreateTranslation(x, y, z, result)
Creates a translation matrix.
- x
- X translation.
- y
- Y translation.
- z
- Z translation.
- result
- The resulting Matrix4d instance.
public static Matrix4X4 CreateTranslation(double x, double y, double z)
result = Matrix4X4.CreateTranslation(x, y, z)
Creates a translation matrix.
- x
- X translation.
- y
- Y translation.
- z
- Z translation.
Returns: The resulting Matrix4d instance.
public static Matrix4X4 CreateTranslation(Vector3 vector)
result = Matrix4X4.CreateTranslation(vector)
Creates a translation matrix.
- vector
- The translation vector.
Returns: The resulting Matrix4d instance.
public static void CreateTranslation(Vector3 vector, Matrix4X4 result)
Matrix4X4.CreateTranslation(vector, result)
Creates a translation matrix.
- vector
- The translation vector.
- result
- The resulting Matrix4d instance.
public override bool Equals(object obj)
result = matrix4X4.Equals(obj)
Indicates whether this instance and a specified object are equal.
- obj
- The object to compare to.
Returns: True if the instances are equal; false otherwise.
public bool Equals(Matrix4X4 other)
result = matrix4X4.Equals(other)
Indicates whether the current matrix is equal to another matrix.
- other
- An matrix to compare with this matrix.
Returns: true if the current matrix is equal to the matrix parameter; otherwise, false.
public static Matrix4X4 Frustum(double left, double right, double bottom, double top, double near, double far)
result = Matrix4X4.Frustum(left, right, bottom, top, near, far)
Build a projection matrix
- left
- Left edge of the view frustum
- right
- Right edge of the view frustum
- bottom
- Bottom edge of the view frustum
- top
- Top edge of the view frustum
- near
- Distance to the near clip plane
- far
- Distance to the far clip plane
Returns: A projection matrix that transforms camera space to raster space
public override int GetHashCode()
result = matrix4X4.GetHashCode()
Returns the hashcode for this instance.
Returns: A System.Int32 containing the unique hashcode for this instance.
public static Matrix4X4 Invert(Matrix4X4 mat)
result = Matrix4X4.Invert(mat)
Calculate the inverse of the given matrix
- mat
- The matrix to invert
Returns: The inverse of the given matrix if it has one, or the input if it is singular
public static Matrix4X4 LookAt(double eyeX, double eyeY, double eyeZ, double targetX, double targetY, double targetZ, double upX, double upY, double upZ)
result = Matrix4X4.LookAt(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ)
Build a world space to camera space matrix
- eyeX
- Eye (camera) position in world space
- eyeY
- Eye (camera) position in world space
- eyeZ
- Eye (camera) position in world space
- targetX
- Target position in world space
- targetY
- Target position in world space
- targetZ
- Target position in world space
- upX
- Up vector in world space (should not be parallel to the camera direction, that is target - eye)
- upY
- Up vector in world space (should not be parallel to the camera direction, that is target - eye)
- upZ
- Up vector in world space (should not be parallel to the camera direction, that is target - eye)
Returns: A Matrix4 that transforms world space to camera space
public static Matrix4X4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
result = Matrix4X4.LookAt(eye, target, up)
Build a world space to camera space matrix
- eye
- Eye (camera) position in world space
- target
- Target position in world space
- up
- Up vector in world space (should not be parallel to the camera direction, that is target - eye)
Returns: A Matrix that transforms world space to camera space
public static Matrix4X4 Mult(Matrix4X4 left, Matrix4X4 right)
result = Matrix4X4.Mult(left, right)
Multiplies two instances.
- left
- The left operand of the multiplication.
- right
- The right operand of the multiplication.
Returns: A new instance that is the result of the multiplication
public static void Mult(Matrix4X4 left, Matrix4X4 right, Matrix4X4 result)
Matrix4X4.Mult(left, right, result)
Multiplies two instances.
- left
- The left operand of the multiplication.
- right
- The right operand of the multiplication.
- result
- A new instance that is the result of the multiplication
public static bool op_Equality(Matrix4X4 left, Matrix4X4 right)
result = Matrix4X4.op_Equality(left, right)
Compares two instances for equality.
- left
- The first instance.
- right
- The second instance.
Returns: True, if left equals right; false otherwise.
public static bool op_Inequality(Matrix4X4 left, Matrix4X4 right)
result = Matrix4X4.op_Inequality(left, right)
Compares two instances for inequality.
- left
- The first instance.
- right
- The second instance.
Returns: True, if left does not equal right; false otherwise.
public static Matrix4X4 op_Multiply(Matrix4X4 left, Matrix4X4 right)
result = Matrix4X4.op_Multiply(left, right)
Matrix multiplication
- left
- left-hand operand
- right
- right-hand operand
Returns: A new Matrix44 which holds the result of the multiplication
public static Matrix4X4 Perspective(double fovy, double aspect, double near, double far)
result = Matrix4X4.Perspective(fovy, aspect, near, far)
Build a projection matrix
- fovy
- Angle of the field of view in the y direction (in radians)
- aspect
- Aspect ratio of the view (width / height)
- near
- Distance to the near clip plane
- far
- Distance to the far clip plane
Returns: A projection matrix that transforms camera space to raster space
public override string ToString()
result = matrix4X4.ToString()
Returns a System.String that represents the current Matrix44.
public static Matrix4X4 Transpose(Matrix4X4 mat)
result = Matrix4X4.Transpose(mat)
Calculate the transpose of the given matrix
- mat
- The matrix to transpose
Returns: The transpose of the given matrix
public static void Transpose(Matrix4X4 mat, Matrix4X4 result)
Matrix4X4.Transpose(mat, result)
Calculate the transpose of the given matrix
- mat
- The matrix to transpose
- result
- The result of the calculation