Mtx44, Mtx44Ptr

Syntax

#include <revolution/mtx/GeoTypes.h>

typedef f32 Mtx44[4][4];
typedef f32 (*Mtx44Ptr)[4];

#define MTX44_PTR_OFFSET   4

Arguments

None.

Return Values

None.

Description

Mtx44 is a four-row, four-column, two-dimensional array of 16 floating point values. Mtx44 exists to provide a true 4x4 matrix for the routines that generate projection matrices:  MTXFrustum, MTXPerspective, and MTXOrtho. Each of these requires a matrix with an explicit fourth row. Mtx44 is not used by any other MTX functions.

Mtx44 is stored and de-referenced C-style in row-major format. The table below summarizes the three ways of looking at a Mtx44: in memory, from a mathematical viewpoint, and as a C-style array.

Address Mathematical C arrays
0x80200080 m00 m[0][0]
0x80200084 m01 m[0][1]
0x80200088 m02 m[0][2]
0x8020008c m03 m[0][3]
0x80200090 m10 m[1][0]
0x80200094 m11 m[1][1]
0x80200098 m12 m[1][2]
0x8020009c m13 m[1][3]
0x802000a0 m20 m[2][0]
0x802000a4 m21 m[2][1]
0x802000a8 m22 m[2][2]
0x802000ac m23 m[2][3]
0x802000b0 m30 m[3][0]
0x802000b4 m31 m[3][1]
0x802000b8 m32 m[3][2]
0x802000bc m33 m[3][3]

Note: Storage format is transparent to the programmer if matrices are set and manipulated exclusively by MTX functions, but is relevant if matrix elements are set individually. To insulate code from future changes to the storage format, do not set matrix values by hand, and do not initialize matrices when they are first declared. Instead, use the MTXRowCol(m,row,col) macro defined in mtx.h.

Mtx44Ptr is a pointer to an array of 4 floats. Mtx44Ptr is also a pointer to Mtx44 and can replace Mtx44 as a function argument. It is even possible to use sub-scripts just as with Mtx44. However, it is really a pointer to an array of four floats. This has two implications. First, a Mtx44Ptr is assigned to a Mtx44 without the use of the & operator. For example:

Mtx44    mProj;
Mtx44Ptr m44Ptr;

m44Ptr = mProj;

MTXFrustum( mProj, 240, -240, -320, 320, 500, 2000 ); 

Second, you cannot just increment and decrement an Mtx44Ptr, because its size is 16, not 64. Therefore, we have defined a constant in mtx.h which provides the correct multiplier to offset a Mtx44Ptr by the size of one matrix:

#define MTX44_PTR_OFFSET   4

Use MTX44_PTR_OFFSET whenever you need to increment a Mtx44Ptr to the next matrix of an array. This will insulate your code from future changes to the Mtx44 storage format. For example:

Mtx44    m44Array[2];
Mtx44Ptr m44Ptr;

 m44Ptr = (Mtx44Ptr)m44Array;                 // mPtr points to m44Array[0]

 MTXFrustum( m44Ptr, 240, -240, -320, 320, 500, 2000 );      

 m44Ptr += MTX44_PTR_OFFSET ;                 // m44Ptr points to m44Array[1]

 MTXOrtho( m44Ptr, 240, -240, -320, 320, 500, 2000 );   

A function cannot return a pointer to a two-dimensional array, but it can return a Mtx44Ptr. This makes Mtx44Ptr especially useful for functions that need to return a matrix. While the MTX library does not currently contain any functions that return a Mtx44Ptr, this feature may be useful in your own code.

See Also

Mtx, MtxPtr, MTXFrustum, MTXOrtho, MTXPerspective, MTXRowCol

Revision History

2006/03/01 Initial version.


CONFIDENTIAL