{"id":41,"date":"2013-11-08T15:46:23","date_gmt":"2013-11-08T15:46:23","guid":{"rendered":"\/\/3dbym.ru\/2013\/11\/building-transformation-matrices\/"},"modified":"2013-11-08T15:46:23","modified_gmt":"2013-11-08T15:46:23","slug":"building-transformation-matrices","status":"publish","type":"post","link":"https:\/\/3dbym.ru\/2013\/11\/building-transformation-matrices\/","title":{"rendered":"Building Transformation Matrices"},"content":{"rendered":"

One of the most important uses for matrices in game programming is for transformations. Transformation matrices are used to position geometry and other objects onscreen. There are five main transformation matrices that you will use when working with 3D models. They are rotation around the X-axis, rotation around the Y-axis, rotation around the Z-axis, transla\u00adtion, and scaling. A rotation matrix, whether around the X, Y or Z axes, will rotate all of the affected geometry around that specific axis. A transla\u00adtion matrix is used to move geometry from one place to another, and a scale matrix is used to change the size of the geometry.<\/p>\n

The best thing about these matrices is the capability to multiply them together to perform several transformations with a single matrix. Keep in mind that the order of multiplication is important here; multiplying transformation matrices in one order will not necessarily give you the same result as multiplying the same matrices in a different order. Let\u2019s look at an example.<\/p>\n

Say you have three rotation matrices. The first is a rotation of 90 degrees around the X-axis, the second -90 degrees around the X-axis, and the third a rotation of 90 degrees around the Y-axis. If you multiply them in<\/p>\n

<\/p>\n

the order of the first times the second, times the third, you will end with a rotation of 90 degrees around the Y-axis because the first two will cancel each other out. However, if you multiply in the order of the first times the third, times the second, your end result will be a positive 90 degree rotation around the Z-axis. Quite a difference.<\/p>\n

So, how do you create these transformation matrices? Each rotation matrix will rotate a certain number of degrees around the X, Y, or Z axis. Figure 1.13 shows the X, Y, and Z rotation matrices.<\/p>\n\n\n\n\n\n\n\n
\n

1 0 0<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n<\/td>\n\n

cos(0)<\/p>\n<\/td>\n

\n

0 — sin(0)<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n<\/td>\n\n

cos(0)<\/p>\n<\/td>\n

\n

-sin(0)<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n<\/tr>\n

\n

0 cos(0) — sin(0)<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n<\/td>\n\n

0<\/p>\n<\/td>\n

\n

1 0<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n<\/td>\n\n

sin(0)<\/p>\n<\/td>\n

\n

\u041e<\/p>\n

\u043e<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n<\/tr>\n

\n

0 sin(0) cos(0)<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n<\/td>\n\n

sin(0)<\/p>\n<\/td>\n

\n

0 cos(0)<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n<\/td>\n\n

0<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n

1<\/p>\n<\/td>\n<\/tr>\n

\n

0 0 0<\/p>\n<\/td>\n

\n

1<\/p>\n<\/td>\n

\n<\/td>\n\n

0<\/p>\n<\/td>\n

\n

0 0<\/p>\n<\/td>\n

\n

1<\/p>\n<\/td>\n

\n<\/td>\n\n

0<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n

\n

0<\/p>\n<\/td>\n<\/tr>\n

\n

RotX<\/p>\n<\/td>\n

\n<\/td>\n\n<\/td>\n\n

RotY<\/p>\n<\/td>\n

\n<\/td>\n\n<\/td>\n\n

RotZ<\/p>\n<\/td>\n

\n<\/td>\n<\/tr>\n
\n

Figure 1.13 The three rotation matrices. The left matrix<\/p>\n<\/td>\n

\n

is<\/p>\n<\/td>\n

\n

for rotation around the X<\/p>\n<\/td>\n<\/tr>\n<\/table>\n\n\n
\n

axis, the center for rotation around the Y axis, the right for rotation around the Z axis. Each matrix will transform an object \u0432 degrees around its respective axis. Note that they are placed in 4×4 matrices so they can be multiplied with the other transformation matrices, but they could be stored in a 3×3 matrix as well.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n

<\/p>\n

The translation matrix will move an object a set number of units in each direction. The distances in each direction are given by three values stored in the bottom row of the matrix. The scaling matrix is also very simple. Like the translation matrix, there are also three values, one for each axis. Instead of being in the bottom row of the matrix, they are located along the diagonal. The scaling matrix looks a lot like the identity matrix, only with values other than one in the diagonal. Figure 1.14 shows both the translation and the scaling matrices.<\/p>\n","protected":false},"excerpt":{"rendered":"

One of the most important uses for matrices in game programming is for transformations. Transformation matrices are used to position geometry and other objects onscreen. There are five main transformation matrices that you will use when working with 3D models. They are rotation around the X-axis, rotation around the Y-axis, rotation around the Z-axis, transla\u00adtion, […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":0,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3dbym.ru\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}