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

Additional info


Latest Forum posts

 Easter Day Deals
  Posted by: Applefly
  When: 19/04/2014 at 22:18:14

 40% OFF Pavtube DVD Ripper for Mac
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:54

 DVD Ripper with 40% off
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:22

 Get DVD Ripper Wind/Mac + $14 Coupon
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:03

 Backup DVD Escape Plan
  Posted by: Applefly
  When: 17/04/2014 at 06:00:12

 Disney DVDs to MP4
  Posted by: Applefly
  When: 17/04/2014 at 05:56:07

 DVD movies through media streamer
  Posted by: VIKIVannessa
  When: 16/04/2014 at 02:25:09

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 16/04/2014 at 02:20:51

 Blu-ray to Apple ProRes
  Posted by: Applefly
  When: 12/04/2014 at 00:47:46

 HD H.264 MP4 format
  Posted by: Applefly
  When: 12/04/2014 at 00:43:23


Ads

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.

Transformations
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...





    Google
     
    Webwww.riemers.net


    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

    Contents

    News
    Home
    Forum
    XNA 2.0 Recipes Book (8)
    XNA 3.0 Recipes Book (8)
    Downloads
    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!