gfx_math_matrix.hh File Reference

Matrix math. More...

Go to the source code of this file.

Namespaces

namespace  gfx

Classes

class  gfx::Matrix
 Matrix class. More...

Defines

#define GFX_MATH_MATRIX_HH   1
#define MATRIX_EXT   0
#define MATRIX_ELEMS   12
#define MATRIX_ROW_MAJOR   0
#define CODE_RESIZE_DEST_ARRAY(dest, src, vcnt)
#define CODE_ROTATE_TRANSLATE_ARRAY(dest, src, vcnt)
#define CODE_TRANSLATE_ROTATE_ARRAY(dest, src, vcnt)
#define MULTIPLY_MATRIX_ELEM3(i, a0, a1, b0, b1, c0, c1)
#define MULTIPLY_MATRIX_ELEM4(i, a0, a1, b0, b1, c0, c1, oi)

Enumerations

enum  {
  gfx::Xx, gfx::Yx, gfx::Zx, gfx::Xy,
  gfx::Yy, gfx::Zy, gfx::Xz, gfx::Yz,
  gfx::Zz, gfx::Ox, gfx::Oy, gfx::Oz
}

Functions

INLINE Matrix gfx::operator * (const Matrix &m, const Matrix &n)
INLINE void gfx::TransposeMatrix (Matrix &dest, const Matrix &src)


Detailed Description

Matrix math.

Id
LastChangedDate

Author:
Jim E. Brooks http://www.palomino3d.org
 *-------------------------------------------------------------------------------
 * A gfx matrix has 12 elements.
 * Xw,Yw,Zw,Ow were eliminated to minimize space (but can be conditionally-compiled
 * for other Matrix formats).
 *
 * The amount and the ordering of matrix elements are abstracted.
 * The idea is for matrix code to independent of the exact layout of a matrix
 * (in case, eg, a specific gfxsys requires a 16-element row-major matrix).
 * 
 * When computing the index of a matrix element using a row,col tuple,
 * don't hard-code the index computations as that would have implict dependencies
 * on a particular matrix layout.  Instead, use the MIX() macros.
 *     m[i*4+XX]     // wrong
 *     m[MIX(i,XX)]  // right (use macro that hides layout of matrix)
 * An example of a similar mistake is calling Distance( fpx[3], fpx[3]) as
 * Distance( pos, m[Ox] ) which wrongly assumes Ox,Oy,Oz are contiguous elements.
 *------------------------------------------------------------------------------
 * Local vs. fixed:
 * Transformation functions are named with either Local or Fixed.
 * Transformations in fixed space apply to Eye.
 * Transformations in local space are relative to a matrix.
 *------------------------------------------------------------------------------
 * 

Define Documentation

#define CODE_RESIZE_DEST_ARRAY ( dest,
src,
vcnt   ) 

Value:

/* Ensure dest array has enough room. */                        \
        const uint vcnt = src.size();                                   \
        ASSERT( vcnt > 0 );                                             \
        ASSERT( vcnt < MAX_VERTEXS );                                   \
        dest.resize( vcnt );
Macro to expand destination vertex array.

#define CODE_ROTATE_TRANSLATE_ARRAY ( dest,
src,
vcnt   ) 

Value:

{                                                                                   \
        for ( uint i = 0; i < vcnt; ++i )                                               \
        {                                                                               \
          /* catch memory corruption */ \
            dest[i].x = src[i].x * m[Xx] + src[i].y * m[Xy] + src[i].z * m[Xz] + m[Ox]; \
            dest[i].y = src[i].x * m[Yx] + src[i].y * m[Yy] + src[i].z * m[Yz] + m[Oy]; \
            dest[i].z = src[i].x * m[Zx] + src[i].y * m[Zy] + src[i].z * m[Zz] + m[Oz]; \
        }                                                                               \
    }

#define CODE_TRANSLATE_ROTATE_ARRAY ( dest,
src,
vcnt   ) 

Value:

{                                                                                   \
        for ( uint i = 0; i < vcnt; ++i )                                               \
        {                                                                               \
          /* catch memory corruption */ \
            fp x = src[i].x + m[Ox];                                                    \
            fp y = src[i].y + m[Oy];                                                    \
            fp z = src[i].z + m[Oz];                                                    \
            dest[i].x = x * m[Xx] + y * m[Xy] + z * m[Xz];                              \
            dest[i].y = x * m[Yx] + y * m[Yy] + z * m[Yz];                              \
            dest[i].z = x * m[Zx] + y * m[Zy] + z * m[Zz];                              \
        }                                                                               \
    }

#define GFX_MATH_MATRIX_HH   1

#define MATRIX_ELEMS   12

#define MATRIX_EXT   0

#define MATRIX_ROW_MAJOR   0

#define MULTIPLY_MATRIX_ELEM3 ( i,
a0,
a1,
b0,
b1,
c0,
c1   ) 

Value:

prod[i] =   m[a0] * n[a1]                                   \
              + m[b0] * n[b1]                                   \
              + m[c0] * n[c1];

#define MULTIPLY_MATRIX_ELEM4 ( i,
a0,
a1,
b0,
b1,
c0,
c1,
oi   ) 

Value:

prod[i] =   m[a0] * n[a1]                                   \
              + m[b0] * n[b1]                                   \
              + m[c0] * n[c1]                                   \
              +         n[oi];

Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:15 2007