Game Engine Architecture

(Ben Green) #1

168 4. 3D Math for Games


abled (SIMD) microprocessor, as we’ll see later in this chapter. In most game
engines I’ve personally encountered, matrices are stored using approach (1),
with the vectors in the rows of the two-dimensional C/C++ array. This is shown
below:
float M[4][4];
M[0][0]=ix; M[0][1]=iy; M[0][2]=iz; M[0][3]=0.0f;
M[1][0]=jx; M[1][1]=jy; M[1][2]=jz; M[1][3]=0.0f;
M[2][0]=kx; M[2][1]=ky; M[2][2]=kz; M[2][3]=0.0f;
M[3][0]=tx; M[3][1]=ty; M[3][2]=tz; M[3][3]=1.0f;
The matrix M looks like this when viewed in a debugger:
M[][]
[0]
[0] ix
[1] iy
[2] iz
[3] 0.0000

[1]
[0] jx
[1] jy
[2] jz
[3] 0.0000

[2]
[0] kx
[1] ky
[2] kz
[3] 0.0000

[3]
[0] tx
[1] ty
[2] tz
[3] 1.0000
One easy way to determine which layout your engine uses is to fi nd a
function that builds a 4 × 4 translation matrix. (Every good 3D math library
provides such a function.) You can then inspect the source code to see where
the elements of the t vector are being stored. If you don’t have access to the
source code of your math library (which is prett y rare in the game industry),
you can always call the function with an easy-to-recognize translation like
(4, 3, 2), and then inspect the resulting matrix. If row 3 contains the values 4.0,
3.0, 2.0, 1.0, then the vectors are in the rows, otherwise the vectors are in
the columns.
Free download pdf