XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
My XNA Book
       Go to section on this site

Additional info

Latest Forum posts

 Account settings
  Posted by: Anonymous
  When: 07/05/2014 at 09:48:39

 forced subtitle
  Posted by: Applefly
  When: 07/05/2014 at 06:00:48

 convert DVD into PMS
  Posted by: Applefly
  When: 07/05/2014 at 05:55:25

 DVD to Digital Copy easily
  Posted by: VIKIVannessa
  When: 05/05/2014 at 06:52:29

 DVD on Xbox 360/Xbox One Console
  Posted by: VIKIVannessa
  When: 05/05/2014 at 06:51:47

 Extract .Srt Subtitles
  Posted by: Applefly
  When: 04/05/2014 at 03:54:38

 Encode Movie collection
  Posted by: Applefly
  When: 04/05/2014 at 03:52:41

 Convert DVD to WMV
  Posted by: Applefly
  When: 29/04/2014 at 05:53:50

 rip DVDs into digital files
  Posted by: Applefly
  When: 29/04/2014 at 05:51:20

 iTunes movies/music to Kindle Fire
  Posted by: ciciyu80
  When: 29/04/2014 at 05:10:20


Matrices and DirectX

What exactly are those matrices we keep using in our DirectX programs? Maybe you already have an idea about the concept behind them, but want full control. Maybe you don’t care about the maths, but want the geometric meaning behind them. In both cases, these 3 pages are for you.

The first page we’ll talk about the geometric reasoning behind matrices, which can be summarized in 3 easy-to-understand properties. The second page we’ll cover the basic maths behind them and we’ll finish with homogeneous matrices, which are the matrices actually used by DirectX.

You all know transformations, these transform the coordinates of any 3D point into the coordinates of another 3D point. Below you see an example of the 3 basic transformations:

The first transformation will simply move all points in 3D space down and to the left. Such a ‘movement’ transformation is called a translation. The second transformation you see is the rotation, where all points in 3D space are rotated around a specified axis, in this case around the Z-axis. The last basic transformation is the scaling, where the coordinates of all points are multiplied by a certain number.

I call these the ‘basic’ transformations, because any transformation you can think of can be described as a combination of these 3 basic transformations. Below you can see the result of a translation, followed by a rotation:

This actually is the transformation we use in Series1, where we first translate the middle of our terrain to our origin, and then rotate it when the user presses a key.

The 3 properties
Property 1:
A matrix can be thought of as a special (but not complicated) element, that can describe any of above transformations. So imagine you have 3 matrices; Mtrans, Mrot and Mscal; that each correspond to one of the transformations above.

Property 2:
If you multiply such a matrix with the coordinates of any 3D point, you get the coordinates of the transformed point. As an illustration:

This means for any point, you can find its projection by simply multiplying its coordinates with a matrix! This of course also holds for the rotation and scaling transformations.

Property 3:
If you multiply 2 matrices M1 and M2, you get a new matrix M3. The transformation that corresponds to this new matrix M3, is the combination of the transformations corresponding to the first 2 matrices M1 and M2.
This third property is also EXTREMELY useful. Imagine the example above where we have a translation followed by a rotation. One way to calculate the positions of the projected points, would be to first calculate the points, transformed by the translation matrix M1, and then to calculate the rotated projections of these points by multiplying them with M2. This implies you would have to calculate a projection for each point TWICE. This is illustrated by the following equations:

Using the third property, you simply first multiply M1 and M2 to get M3. Now you only need to multiply your points with this matrix M3 to get the rotated and translated coordinates of your points! Multiplication of 2 matrices happens very fast (64 multiplications and 48 sums) while transforming all the points in your scene takes MUCH longer (16 multiplications and 12 sums for each point)

These 3 properties conclude this first page on the geometric meaning behind matrices. Next page we’re going to see what matrices exactly look like.

Click here to go to the forum on this chapter!

Or click on one of the topics on this chapter to go there:
  • Multiplication of matrices
          Hello First of all, thanks for your great tutor...
  • the scaling diagram
          hello reimer, I thought that scaling of the wor...


    If you appreciate the amount of time I spend creating and updating
    these pages, feel free to donate -- any amount is welcome !

    - Website design & XNA + DirectX code : Riemer Grootjans -
    ©2003 - 2011 Riemer Grootjans
  • Translations

    This site in English
    This site in Korean
    This site in Czech

    Microsoft MVP Award

    2007 - 2011 MVP Award
    DirectX - XNA


    XNA 2.0 Recipes Book (8)
    XNA 3.0 Recipes Book (8)
    Extra Reading (3)
    Matrices: geometrical
    Matrix Mathematics
    Homogenous matrices
    Community Projects (1)
    Tutorials (160)
    -- Expand all --

    Thank you!

    Support this site --
    any amount is welcome !

    Stay up-to-date

    I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!