home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / matrixmath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-18  |  2.2 KB  |  59 lines

  1. #ifndef __matrixmath_h__
  2. #define __matrixmath_h__
  3.  
  4. /*!
  5. \file matrixmath.h
  6. \author Karsten Schwenk
  7.  
  8. \brief This file contains some simple but often used matrix and matrix-vector routines.
  9.  
  10. Matrices are stored in OpenGL-style, i.e. <b>column by column</b>. So 
  11.  
  12. (a b)
  13.  
  14. (c d) is stored in an one-dimensional array as (acbd).
  15.  
  16. Only quadtric matrices are supported!
  17.  
  18. All functions begin with \c matrix... and take their arguments (i.e. matrices or vectors) as pointers to \c float. One \c int argument is used to specify the dimension of the matrix and vector arguments.
  19.  
  20. */
  21.  
  22. typedef float matbase_t;        //!< our base type for matrices (float but could be changed to double)
  23. typedef matbase_t mat2x2_t[4];    //!< a 2x2 matrix of \c floats
  24. typedef matbase_t mat3x3_t[9];    //!< a 3x3 matrix
  25. typedef matbase_t mat4x4_t[16];    //!< a 4x4 matrix
  26.  
  27. extern mat2x2_t id2x2;        //!< a 2x2 identity matrix
  28. extern mat3x3_t id3x3;        //!< a 3x3 identity matrix
  29. extern mat4x4_t id4x4;        //!< a 4x4 identity matrix
  30.  
  31. //! Prints out an matrix (useful for debugging but not much more...).
  32. void matrixPrint(matbase_t* a, int n);
  33.  
  34. //! Multiplies vector b by matrix a and stores the result in r.
  35. void matrixMultVector(matbase_t* a, matbase_t* b, int n, matbase_t* r);
  36.  
  37. //! Multiplies matrix a by matrix b and stores the result in r.
  38. void matrixMultMatrix(matbase_t* a, matbase_t* b, int n, matbase_t* r);
  39.  
  40. //! Copies matrix a into matrix b.
  41. void matrixCopy(matbase_t* a, matbase_t* b, int n);
  42.  
  43. //! Calculates the transpose of matrix a and stores it in t.
  44. void matrixTranspose(matbase_t* a, int n, matbase_t* t);
  45.  
  46. //! Calculates the inverse of matrix a and stores it in u.
  47. void matrixInvert(matbase_t* a, int n, matbase_t* u);
  48.  
  49. //! Calculates the LR-decomposition of (first step for solving a linear system of equations).
  50. void matrixLU(matbase_t* a, int n);    // FIXME: include row-permutations!!!
  51. void matrixSolveForward(matbase_t* a, matbase_t* b, int n, matbase_t* c);
  52. void matrixSolveBackward(matbase_t* a, matbase_t* c, int n, matbase_t* x);
  53.  
  54. //! Solves the linear system of equations Ax=b and stores the solution in x.
  55. void matrixSolve(matbase_t* a, matbase_t* b, int n, matbase_t* x);
  56.  
  57.  
  58. #endif        /* __matrixmath_h__  */
  59.