# Matrix Structure (Microsoft.DirectX)

**How Do I...?**

- Set Up a Projection Matrix

Describes and manipulates a matrix.

**Definition**

Visual Basic Public Structure MatrixC# public struct MatrixC++ public value class MatrixsealedJScript In JScript, you can use structures, but you cannot define your own.

**Members Table**

The following table lists the members exposed by the object.

Fields

Field Description M11 Retrieves or sets the element in the first row and the first column of the matrix. M12 Retrieves or sets the element in the first row and the second column of the matrix. M13 Retrieves or sets the element in the first row and the third column of the matrix. M14 Retrieves or sets the element in the first row and the fourth column of the matrix. M21 Retrieves or sets the element in the second row and the first column of the matrix. M22 Retrieves or sets the element in the second row and the second column of the matrix. M23 Retrieves or sets the element in the second row and the third column of the matrix. M24 Retrieves or sets the element in the second row and the fourth column of the matrix. M31 Retrieves or sets the element in the third row and the first column of the matrix. M32 Retrieves or sets the element in the third row and the second column of the matrix. M33 Retrieves or sets the element in the third row and the third column of the matrix. M34 Retrieves or sets the element in the third row and the fourth column of the matrix. M41 Retrieves or sets the element in the fourth row and the first column of the matrix. M42 Retrieves or sets the element in the fourth row and the second column of the matrix. M43 Retrieves or sets the element in the fourth row and the third column of the matrix. M44 Retrieves or sets the element in the fourth row and the fourth column of the matrix.

Methods

Method Description Add Adds two matrices. AffineTransformation Builds a 3-D affine transformation matrix. AffineTransformation2D Builds a 2-D affine transformation matrix in the xyplane.Equals Returns a value that indicates whether the current instance is equal to a specified object. GetHashCode Returns the hash code for the current instance. Invert Calculates the inverse of a matrix. LookAtLH Builds a left-handed look-at matrix. LookAtRH Builds a right-handed look-at matrix. Matrix Initializes a new instance of the Matrixclass.Multiply Determines the product of two matrices. MultiplyTranspose Calculates the transposed product of two matrices. op_Addition Adds two instances of the Matrixstructure.op_Equality Compares the current instance of a class to another instance to determine whether they are the same. op_Inequality Compares the current instance of a class to another instance to determine whether they are different. op_Multiply Determines the product of two matrices. op_Subtraction Subtracts two instances of the Matrixstructure.OrthoLH Builds a left-handed orthogonal projection matrix. OrthoOffCenterLH Builds a customized, left-handed orthogonal projection matrix. OrthoOffCenterRH Builds a customized, right-handed orthogonal projection matrix. OrthoRH Builds a right-handed orthogonal projection matrix. PerspectiveFovLH Builds a left-handed perspective projection matrix based on a field of view. PerspectiveFovRH Builds a right-handed perspective projection matrix based on a field of view (FOV). PerspectiveLH Builds a left-handed perspective projection matrix. PerspectiveOffCenterLH Builds a customized, left-handed perspective projection matrix. PerspectiveOffCenterRH Builds a customized, right-handed perspective projection matrix. PerspectiveRH Builds a right-handed perspective projection matrix. Reflect Builds a matrix that reflects the coordinate system about a plane. RotateAxis Rotates the matrix around an arbitrary axis. RotateQuaternion Rotates a matrix from a quaternion. RotateX Rotates a matrix around the x-axis. RotateY Rotates a matrix around the y-axis. RotateYawPitchRoll Rotates a matrix with a specified yaw, pitch, and roll. RotateZ Rotates the matrix around the z-axis. RotationAxis Builds a matrix that rotates around an arbitrary axis. RotationQuaternion Builds a matrix from a quaternion. RotationX Builds a matrix that rotates around the x-axis. RotationY Builds a matrix that rotates around the y-axis. RotationYawPitchRoll Builds a matrix with a specified yaw, pitch, and roll. RotationZ Builds a matrix that rotates around the z-axis. Scale Scales the matrix along the x-axis, y-axis, and z-axis. Scaling Builds a matrix that scales along the x-axis, y-axis, and z-axis. Shadow Builds a matrix that flattens geometry into a plane. Subtract Subtracts one matrix from another. ToString Obtains a string representation of the current instance. Transform Transforms the matrix. Transformation Builds a transformation matrix. Transformation2D Builds a 2-D transformation matrix in the xyplane.Translate Translates the matrix using specified offsets. Translation Builds a matrix using specified offsets. Transpose Transposes the matrix using a source matrix. TransposeMatrix Returns the matrix transpose of a given matrix.

Properties

Property Description Determinant Retrieves the determinant of the matrix. Identity Retrieves the identity of the matrix. Zero Retrieves an empty matrix.

**Remarks**

This structure represents a 4x4 matrix of Single values. The fields of this structure are named with the row number first, then the column number.

In Microsoft Direct3D, the M34 element of a projection matrix cannot be a negative number. If an application needs to use a negative value in this location, it should scale the entire projection matrix by -1 instead.

**How Do I...?**

Set Up a Projection MatrixThis example demonstrates how to set up the projection transformation matrix, which transforms 3-D camera or view space coordinates into 2-D screen coordinates.

See the following C# code example, the Projection transformation matrix is set to be equal to the left-handed (LH) PerspectiveFovLH matrix. Input arguments to PerspectiveFovLH are as follows.

- Field of view in radians: pi/4.
- Aspect ratio, or view-space height divided by width: 1, for a square window.
- Near clipping plane distance: 1 unit.
- Far clipping plane distance: 100 units.
`[C#] using Microsoft.DirectX; Direct3D.Device device = null; // Create rendering device. // For the projection matrix, you set up a perspective transform (which // transforms geometry from 3-D view space to 2-D viewport space, with // a perspective divide making objects smaller in the distance). To build // a perspective transform, you need the field of view (1/4 pi is common), // the aspect ratio, and the near and far clipping planes (which define // the distances at which geometry should no longer be rendered). device.Transform.Projection = Matrix.PerspectiveFovLH( (float)Math.PI / 4, 1.0f, 1.0f, 100.0f );`

**Structure Information**

Namespace Microsoft.DirectX Assembly Microsoft.DirectX (microsoft.directx.dll) Strong Name Microsoft.DirectX, Version=1.0.900.0, Culture=neutral, PublicKeyToken=d3231b57b74a1492

**See Also**