- Game Physics Cookbook
- Gabor Szauer
- 418字
- 2021-04-02 20:27:30
Matrix majors
When we talk about a 4 X 4 matrix containing translation, rotation, and scale, it's important to realize that all of that information lives somewhere in the matrix. The following figure demonstrates how data is packed into the components of a 4 X 4 matrix:

The preceding figure demonstrates how data is packed into a Row Major matrix. This is called a Row Major Matrix because all three of the rotation basis vectors, as well as the translation vecto, are stored in the rows of the matrix. There is another notation to store the same data in a 4 X 4 matrix: Column Major notation. The following figure demonstrates how the same data is stored in a Column Major matrix:

It is important to note that the indexing of the matrix did not change between the row and column major notations. This is because the major of a matrix does not affect the definition of what a matrix is! The only thing the major of a matrix describes is in which elements the rotation, translation, and scaling data are stored. With a Row Major matrix the data is stored in rows; with a Column Major matrix the data is stored in columns.
We have to choose a major for our matrix class, it's important to define whether we are working with Row Major or Column Major matrices. For me, this choice comes down to memory layout. The rotation basis vectors: X-Rotation Axis, Y-Rotation Axis, and Z-Rotation Axis should be laid out linearly in memory. The easiest way to do this is to use a Row Major Matrix. This decision means our matrix will conceptually look like this:

The matrix will be laid out in a linear array of memory, like so:
float linear[] = { 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44 };
You may have noticed that converting between a row and column major matrix is a matter of transposing the matrix.
Note
Direct X and OpenGL have caused a lot of confusion when it comes to matrices in video games. Conceptually, Direct X is row major, while OpenGL is column major. However, physically in memory both API's are laid out the same way. This is because Direct-X stores matrices row by row in memory, while OpenGL stores matrices column by column in memory. As a result, our matrix library is compatible with both! The .asArray
accessor for the matrix class will work with both API's.
- 大學(xué)計(jì)算機(jī)基礎(chǔ)(第二版)
- Reporting with Visual Studio and Crystal Reports
- vSphere High Performance Cookbook
- Apache Spark 2 for Beginners
- iOS開發(fā)實(shí)戰(zhàn):從零基礎(chǔ)到App Store上架
- Mastering PHP Design Patterns
- Oracle Database 12c Security Cookbook
- Unity 5 for Android Essentials
- 執(zhí)劍而舞:用代碼創(chuàng)作藝術(shù)
- Java網(wǎng)絡(luò)編程核心技術(shù)詳解(視頻微課版)
- SpringBoot從零開始學(xué)(視頻教學(xué)版)
- 跟戴銘學(xué)iOS編程:理順核心知識點(diǎn)
- Data Manipulation with R(Second Edition)
- Python數(shù)據(jù)預(yù)處理技術(shù)與實(shí)踐
- Instant Pygame for Python Game Development How-to