Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why not 3x3 Matrix?

Discussion in 'General Graphics' started by ToshoDaimos, Sep 26, 2017.

  1. ToshoDaimos

    ToshoDaimos

    Joined:
    Jan 30, 2013
    Posts:
    679
    In 3D space only three coordinates are needed to define a point. However in 3D graphics everybody is using 4x4 matrices instead of 3x3. Can somebody explain the math behind this in simple terms?
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    You don't need to use matrices much in Unity because the game engine handles it all for you.

    A matrix defines Position, Scale, and Rotation. With the 3x3 matrix, the 3 rows represent the 3 axis's of the object's transform (forward, right, up). With these transform axis's the direction of each row gives us the rotation of the object, and the magnitude of each axis defines the scale of that axis. To define the position, we need a 4th row.

    In a 4x4 matrix, the last number in each row isn't used as often so I'm not sure how it's useful. When performing math with matrices, if the far bottom-right element is 0, the matrix is treated as a direction and it's position doesn't get applied. If that value is 1, the position does get applied.
     
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,858
  4. chantey

    chantey

    Joined:
    Mar 5, 2017
    Posts:
    49
    in my very early journey of discovery in the world of matrices im finding it useful to look at a 4x4 matrix like so:

    Code (CSharp):
    1. /*
    2.  
    3.  | right | up    | fwd   | pos   |
    4. x| 1     | 0     | 0     | 0     |
    5. y| 0     | 1     | 0     | 0     |
    6. z| 0     | 0     | 1     | 0     |
    7. w| 0     | 0     | 0     | 1     |
    8.  
    9. */
    where the first three columns describe rotation/scale, the last column describes position, and the 'w' row lies in the realm of dark sorcery.
     
  5. jitwtttl

    jitwtttl

    Joined:
    Aug 29, 2014
    Posts:
    8
    Projection matrix is used to transform object's data from Camera space to Clip space.
    In the process, w factor (bottom row of the 4*4 matrix) is needed for calculation of vertex position in the perspective camera view.

    As @aleksandrk says, with w, it become a homogeneous coordinates, not cartesian coordinates.