XMMATRIX structure

Describes a 4*4 matrix aligned on a 16-byte boundary that maps to four hardware vector registers.

DirectXMath uses row-major matrices, row vectors, and pre-multiplication. Handedness is determined by which function version is used (RH vs. LH).

For a list of additional functionality such as constructors and operators that are available using XMMATRIX when you are programming in C++, see XMMATRIX Extensions.

Note  See DirectXMath Library Type Equivalences for information about equivalent D3DDECLTYPE, D3DFORMAT, and DXGI_FORMAT objects.
 

Syntax

struct XMMATRIX {
  union {
    XMVECTOR r[4];
    struct {
      float _11;
      float _12;
      float _13;
      float _14;
      float _21;
      float _22;
      float _23;
      float _24;
      float _31;
      float _32;
      float _33;
      float _34;
      float _41;
      float _42;
      float _43;
      float _44;
    };
    float    m[4];
  };
  XMVECTOR              r[4];
  void                  XMMATRIX();
  void                  XMMATRIX( FXMVECTOR R0, FXMVECTOR R1, FXMVECTOR R2, CXMVECTOR R3);
  void                  XMMATRIX( const XMMATRIX & );
  void                  XMMATRIX( float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33);
  XMMATRIX &  noexcept  operator=( const XMMATRIX & M);
  void                  XMMATRIX( const float *pArray);
  XMMATRIX &            operator=( const XMMATRIX & );
  void                  XMMATRIX( XMMATRIX && );
  XMMATRIX &            operator=( XMMATRIX && );
  float                 operator()( size_t Row, size_t Column);
  float &               operator()( size_t Row, size_t Column);
  XMMATRIX              operator+();
  XMMATRIX              operator-();
  XMMATRIX &XM_CALLCONV operator+=( FXMMATRIX M);
  XMMATRIX &XM_CALLCONV operator-=( FXMMATRIX M);
  XMMATRIX &XM_CALLCONV operator*=( FXMMATRIX M);
  XMMATRIX &            operator*=( float S);
  XMMATRIX &            operator/=( float S);
  XMMATRIX XM_CALLCONV  operator+( FXMMATRIX M);
  XMMATRIX XM_CALLCONV  operator-( FXMMATRIX M);
  XMMATRIX XM_CALLCONV  operator*( FXMMATRIX M);
  XMMATRIX              operator*( float S);
  XMMATRIX              operator/( float S);
};

Members

r

Array of four vectors, representing the rows of the matrix.

_11

_12

_13

_14

_21

_22

_23

_24

_31

_32

_33

_34

_41

_42

_43

_44

m

r

Array of four vectors, representing the rows of the matrix.

````cpp void XMMATRIX()`

Default constructor for XMMATRIX.

Default constructor for XMMATRIX.

Note  This constructor is only available when developing with C++.
 

````cpp void XMMATRIX( FXMVECTOR R0, FXMVECTOR R1, FXMVECTOR R2, CXMVECTOR R3)`

Initializes a new instance of the XMMATRIX structure from four instances of XMVECTOR.

Initializes a new instance of the XMMATRIX structure from four instances of XMVECTOR Data Type.

Note  This constructor is only available when developing with C++.

````cpp void XMMATRIX( const XMMATRIX & )`

A constructor for XMMATRIX.

A constructor for XMMATRIX.

Note  This constructor is only available when developing with C++.

````cpp void XMMATRIX( float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)`

Initializes a new instance of the XMMATRIX structure from sixteen scalar float values.

Initializes a new instance of the XMMATRIX structure from sixteen scalar float values.

Note  This constructor is only available when developing with C++.
 

````cpp XMMATRIX & noexcept operator=( const XMMATRIX & M)`

Assigns the matrix data of one instance of XMMATRIX to the current instance of XMMATRIX and returns a reference to the current instance.

This operator assigns the matrix data of one instance of XMMATRIXto the current instance of XMMATRIX and returns a reference to the current instance.

Note  This operator is only available when developing with C++.
 

````cpp void XMMATRIX( const float *pArray)`

Initializes a new instance of the XMMATRIX structure from a sixteen element float array.

Initializes a new instance of the XMMATRIX structure from a sixteen element float array.

Note  This constructor is only available when developing with C++.
 
XMMATRIX & operator=(  const XMMATRIX & )`




````cpp
void XMMATRIX(  XMMATRIX && )`




````cpp
XMMATRIX & operator=(  XMMATRIX && )`




````cpp
float operator()(  size_t Row,  size_t Column)`





[````cpp
float & operator()(  size_t Row,  size_t Column)`](nf-directxmath-xmmatrix-operator-function-call(size_t_size_t).md)

Returns a <code>reference</code> to a matrix element of an instance <code>XMMATRIX</code> as specified by row and column
  arguments.

This operator returns a <code>reference</code> to a matrix element of an instance <a href="https://msdn.microsoft.com/64dd4128-103b-4d54-98f3-cc908170d81c">XMMATRIX</a> as
  specified by row and column arguments.
<div class="alert"><b>Note</b>  This operator is only available when developing with C++.</div><div> </div>



````cpp
XMMATRIX operator+()`




````cpp
XMMATRIX operator-()`




````cpp
XMMATRIX &XM_CALLCONV operator+=(  FXMMATRIX M)`




````cpp
XMMATRIX &XM_CALLCONV operator-=(  FXMMATRIX M)`





[````cpp
XMMATRIX &XM_CALLCONV operator*=(  FXMMATRIX M)`](nf-directxmath-xmmatrix-operator-mult-assign.md)

Performs a matrix multiplication of the current instance of <code>XMMATRIX</code> by another instance of <code>XMMATRIX</code> and returns a reference to the current instance, which has been updated. 

This operator performs a matrix multiplication of the current instance of <a href="https://msdn.microsoft.com/64dd4128-103b-4d54-98f3-cc908170d81c">XMMATRIX</a> by another instance of <code>XMMATRIX</code> and returns a reference to the current instance, which has been updated.
<div class="alert"><b>Note</b>  This operator is only available when developing with C++.</div><div> </div>



````cpp
XMMATRIX & operator*=(  float S)`




````cpp
XMMATRIX & operator/=(  float S)`




````cpp
XMMATRIX XM_CALLCONV operator+(  FXMMATRIX M)`




````cpp
XMMATRIX XM_CALLCONV operator-(  FXMMATRIX M)`





[````cpp
XMMATRIX XM_CALLCONV operator*(  FXMMATRIX M)`](nf-directxmath-xmmatrix-operator-mult.md)

Performs a matrix multiplication of the current instance of <code>XMMATRIX</code> by another instance of <code>XMMATRIX</code>.

This operator performs a matrix multiplication of the current instance of <a href="https://msdn.microsoft.com/64dd4128-103b-4d54-98f3-cc908170d81c">XMMATRIX</a> by another instance of <code>XMMATRIX</code>.
<div class="alert"><b>Note</b>  This operator is only available when developing with C++.</div><div> </div>



````cpp
XMMATRIX operator*(  float S)`




````cpp
XMMATRIX operator/(  float S)`




## Remarks
In the DirectXMath.h header file, the system uses an alias to the <code>XMMATRIX</code> object, specifically <b>CXMMATRIX</b>.
   The header uses the alias to comply with the optimal in-line calling conventions of different compilers. For most
   projects using DirectXMath it is sufficient to simply treat this as an exact alias to <code>XMMATRIX</code>.

Effectively:


```

typedef const XMMATRIX CXMMATRIX;

```


For projects that need detailed information about how different platform's calling conventions are handled, see
   <a href="https://docs.microsoft.com/windows/desktop/dxmath/pg-xnamath-internals">Library Internals</a>.

<code>XMMATRIX</code> is row-major and all DirectXMath functions that accept an <code>XMMATRIX</code> as a parameter expect data to be organized as row-major.

Data in an <code>XMMATRIX</code> has the following layout.


```

_11 _12 _13 _14
_21 _22 _23 _24
_31 _32 _33 _34
_41 _42 _43 _44

```


DirectXMath defines <b>XMMATRIX</b> as a fully opaque type. To access individual elements of <b>XMMATRIX</b>, use equivalent types such as <a href="https://docs.microsoft.com/windows/desktop/api/directxmath/ns-directxmath-xmfloat4">XMFLOAT4</a> for a given row or <a href="https://docs.microsoft.com/windows/desktop/api/directxmath/ns-directxmath-xmfloat4x4">XMFLOAT4X4</a> for the whole matrix.

<div class="alert"><b>Note</b>  XNAMath 2.x defines <code>XMMATRIX</code> as a union with <b>_11</b> to <b>_44</b> members and an <b>m</b> array member. When you use these members of the union, poor performance results. DirectXMath.h still defines these <code>XMMATRIX</code> union members for when you build an app with <a href="https://docs.microsoft.com/windows/desktop/dxmath/ovw-xnamath-reference-directives">_XM_NO_INTRINSICS_</a>. XNAMath version 2.05 provides an opt-in XM_STRICT_XMMATRIX to enforce the DirectXMath behavior.</div>
<div> </div>
<b>Namespace:</b> Use DirectX

<h3><a id="Platform_Requirements"></a><a id="platform_requirements"></a><a id="PLATFORM_REQUIREMENTS"></a>Platform Requirements</h3>
Microsoft Visual Studio 2010 or Microsoft Visual Studio 2012 with the Windows SDK for Windows 8. Supported for Win32 desktop apps, Windows Store apps, and Windows Phone 8 apps.


## Requirements
| &nbsp; | &nbsp; |
| ---- |:---- |
| **Header** | directxmath.h |

## See Also

<a href="https://docs.microsoft.com/windows/desktop/dxmath/ovw-xnamath-reference-structures">DirectXMath Library Structures</a>



<a href="https://docs.microsoft.com/windows/desktop/api/directxmath/ns-directxmath-xmfloat4x4">XMFLOAT4X4</a>



<a href="https://docs.microsoft.com/windows/desktop/dxmath/ovw-xmmatrix-extensions">XMMATRIX Extensions</a>