Skip to content
Chuck Walbourn edited this page Nov 3, 2015 · 18 revisions

A four by four row-major matrix modeled after the XNA Game Studio math library.

Header

#include <SimpleMath.h>

Initialization

using namespace DirectX::SimpleMath;

Matrix m;                  // Creates an identity matrix
Matrix m(1, 2, 3, 4,
         5, 6, 7, 8,
         9, 10, 11, 12,
         13, 14, 15, 16);  // Creates a matrix [1 2 3 4
                           //                   | 5 6 7 8
                           //                   | 9 10 11 12
                           //                   | 13 14 15 16 ]
Matrix m( Vector3(1,2,3),
          Vector3(4,5,6),
          Vector(7,8,9) ); // Creates a matrix [1 2 3 0
                           //                   | 4 5 6 0
                           //                   | 7 8 9 0
                           //                   | 0 0 0 1 ]
Matrix m( Vector4(1, 2, 3, 4),
          Vector4(5, 6, 7, 8),
          Vector4(9, 10, 11, 12),
          Vector4(13, 14, 15, 16) ); // Creates a matrix [1 2 3 4
                                     //                   | 5 6 7 8
                                     //                   | 9 10 11 12
                                     //                   | 13 14 15 16 ]
float arr[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
Matrix m( arr );           // Creates a matrix [1 2 3 0
                           //                   | 4 5 6 0
                           //                   | 7 8 9 0
                           //                   | 0 0 0 1 ]

Fields

  • _11, _12, _13, _14: First row of matrix
  • _21, _22, _23, _24: Second row of matrix
  • _31, _32, _33, _34: Third row of matrix
  • _41, _42, _43, _44: Fourth row of matrix

Properties

  • Up: The up direction vector from the matrix
  • Down: The down direction vector from the matrix
  • Right: The right direction vector from the matrix
  • Left: The left direction vector from the matrix
  • Forward: The forward direction vector in right-handed (RH) coordinates from the matrix
  • Backward: The backward direction vector in right-handed (RH) coordinates from the matrix
  • Translation: Returns the translation in the matrix

Methods

  • Comparison operators: == and !=
  • Assignment operators: =, +=, -=, *=, /=
  • Unary operators: +, -
  • Binary operators: +, -, *, /
  • Decompose
  • Transpose
  • Invert
  • Determinant

Statics

  • CreateBillboard
  • CreateConstrainedBillboard
  • CreateTranslation
  • CreateScale
  • CreateRotationX
  • CreateRotationY
  • CreateRotationZ
  • CreateFromAxisAngle
  • CreatePerspectiveFieldOfView
  • CreatePerspective
  • CreatePerspectiveOffCenter
  • CreateOrthographic
  • CreateOrthographicOffCenter
  • CreateLookAt
  • CreateWorld
  • CreateFromQuaternion
  • CreateFromYawPitchRoll
  • CreateShadow
  • CreateReflection
  • Lerp
  • Transform

Constants

  • Identity: An identity matrix

Remark

Matrix can freely convert to and from a XMFLOAT4X4 and XMMATRIX.

You can copy or assign a Matrix from a XMFLOAT3X3 or XMFLOAT4X3.

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXTex

DirectXMath

Win2D

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

Clone this wiki locally