Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Gamasutra: The Art & Business of Making Gamesspacer
Complex Matrix Transformations
View All     RSS
February 18, 2020
arrowPress Releases
February 18, 2020
Games Press
View All     RSS







If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Complex Matrix Transformations


May 17, 2002 Article Start Page 1 of 4 Next
 

Matrix transforms are a ubiquitous aspect of 3D game programming. Yet it is surprising that game programmers do not often use a rigorous method for creating them or a common way of discussing them. Practitioners in the field of Robotics have mastered them long ago but these methods haven't made their way into daily practice among game programmers. Some of the many symptoms include models that import the wrong way and characters that rotate left when they are told to rotate right. So after a review of matrix conventions and notation, we'll introduce a useful naming scheme, a shorthand notation for transforms and tips for debugging them that will allow you to create concatenated matrix transforms correctly in much shorter time.

Matrix Representation of Transforms

Matrices represent transforms by storing the vectors that represent one reference frame in another reference frame. Figure 1 shows two 2D reference frames offset by a vector T and rotated relative to each. To represent frame one in the space of frame zero , we need the translation vector T, and the unit axis vectors X1 and Y1 expressed in the zero frame.





Figure 1: 2D Reference Frames offset and rotated from each other


We know that we need to store vectors in a matrix but now we have to decide how. We can either store them in a square matrix as rows or as columns. Each convention is shown below with the vectors expanded into their x and y components.


Figure 2: 2D Transform Stored as Columns

 

Figure 3: 2D Transform Stored as Rows

Each stores the same information so the question of which one is better will not be discussed. The difference only matters when you use them in a multiplication. Matrix multiplication is a set of dot products between the rows of the left matrix and columns of the right matrix. Figure 4 below shows the multiplication of two 3x3 matrices, A and B.


Figure 4: The First Dot Product in a Matrix Multiply

The first element in the product A times B is the row (a00, a01, a02) dotted with the column (b00, b10, b20). The dot product is valid because the row and the column each have three components. This dictates how a row vector and a column vector are each multiplied by a matrix.

A column vector must go on the right of the matrix.

 

A row vector must go on the left of the matrix.

 

In each convention, the vectors are represented consistently as rows or columns as one might expect but it is important to realize that the order changes. Again, we must switch the order because the rows on the left must be the same size as the columns on the right in order for the matrix multiplication to be defined.

You can convert between row and column matrices by taking the matrix transpose of either matrix. Here we show that the transpose of a column matrix is a row matrix.


Article Start Page 1 of 4 Next

Related Jobs

Insomniac Games
Insomniac Games — Burbank CA or Durham NC, California, United States
[02.18.20]

Mid to Senior Engine Programmer (Tools)
AfterThought
AfterThought — Henderson, Nevada, United States
[02.18.20]

Unreal Engine 4 Programmer
Square Enix Co., Ltd.
Square Enix Co., Ltd. — Tokyo, Japan
[02.18.20]

Experienced Game Developer
Yacht Club Games
Yacht Club Games — Los Angeles, California, United States
[02.17.20]

Senior Tools & Engine Programmer





Loading Comments

loader image