Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

MMatrix Class Reference

The (Mathematical) Matrix Class. More...

#include <mmatrix.h>

List of all members.

Public Methods

 MMatrix (int m = 1, int n = 1)
 ~MMatrix ()
void set (int m, int n, GLfloat val)
GLfloat get (int m, int n)
MMatrix trans ()
MMatrix homogen ()
MMatrix reduce ()
MMatrix operator= (MMatrix m)
MMatrix operator= (Vector v)
MMatrix operator+ (MMatrix m)
MMatrix operator- (MMatrix m)
MMatrix operator * (MMatrix m)

Public Attributes

int getM
int getN

Private Attributes

int dimM
int dimN
GLfloat mat [MAX_MMATRIX_M][MAX_MMATRIX_N]


Detailed Description

The (Mathematical) Matrix Class.

Author(s):
StonedBones
Date:
310100

Definition at line 15 of file mmatrix.h.

00015 {
00016     public:
00017     MMatrix (int m = 1, int n = 1);     // create a mathematical mxn matrix (note: m = y, n = x !)
00018     ~MMatrix ();
00019 
00020     int getM;
00021     int getN;
00022 
00023     void    set (int m, int n, GLfloat val) ;
00024     GLfloat get (int m, int n);
00025 
00026     MMatrix trans ();       // I don't know the english translations of these operations
00027     MMatrix homogen ();     // in german: Transponierte der Matrix, Homogenisierte Matrix und wieder reduzierte Matrix
00028     MMatrix reduce ();
00029 
00030     MMatrix operator= (MMatrix m);
00031     MMatrix operator= (Vector v);
00032     MMatrix operator+ (MMatrix m);
00033     MMatrix operator- (MMatrix m);
00034     MMatrix operator* (MMatrix m);
00035 
00036     private:
00037     int dimM, dimN;
00038 
00039     GLfloat mat[MAX_MMATRIX_M][MAX_MMATRIX_N];
00040 }

Constructor & Destructor Documentation

MMatrix::MMatrix ( int m = 1,
int n = 1)

Definition at line 3 of file mmatrix.cpp.

00003 {
00004     if ((dimN > 4) || (dimM > 4)) {
00005     dimN = 0;
00006     dimM = 0;
00007     } else {
00008         dimN = n;
00009     dimM = m;
00010     };
00011     
00012     for (int x = 1; x <= MAX_MMATRIX_M; x++) {
00013     for (int y = 1; y <= MAX_MMATRIX_N; y++) {
00014         mat[x][y] = 0;
00015     };
00016     };
00017     
00018     return;
00019 }

MMatrix::~MMatrix ()

Definition at line 21 of file mmatrix.cpp.

00021 {
00022 }

Member Function Documentation

float MMatrix::get ( int m,
int n)

Definition at line 38 of file mmatrix.cpp.

00038 {
00039     if ((m < 1) || (m > MAX_MMATRIX_M) || (n < 1) || (y > MAX_MMATRIX_N)) return 0.0;
00040     
00041     return mat[m][n];
00042 }

MMatrix MMatrix::homogen ()

Definition at line 125 of file mmatrix.cpp.

00125 {
00126     if ((dimN < MAX_MMATRIX_N) && (dimM < MAX_MMATRIX_M)) {
00127     MMatrix tmp (dimM + 1, dimN + 1);
00128     
00129     for (int x = 1; x <= dimM; x++) {
00130         for (int y = 1; y <= dimN; y++) {
00131         tmp.set (x, y, mat[x][y]);
00132         };
00133     };
00134     
00135     tmp.set (dimM +1, dimN +1, 1);
00136     return tmp;
00137     } else {
00138     MMatrix tmp;
00139     return tmp;
00140     };
00141 }

MMatrix MMatrix::operator * ( MMatrix m)

Definition at line 84 of file mmatrix.cpp.

00084 {
00085     MMatrix tmp(m.getN (), dimM);
00086     float      f;
00087     
00088     if (dimN != m.getM ()) return tmp;
00089     
00090     for (int x = 1; x <= m.getM (); x ++) {
00091     for (int y = 1; y <= dimN; y++) {
00092         f = 0;
00093         for (int z = 1; z <= dimM; z++) {
00094         f += mat[z][y] * m.get (x, z);
00095         };
00096                 
00097         tmp.set (x, y, f);
00098     };
00099     };
00100     
00101     return tmp;
00102 }

MMatrix MMatrix::operator+ ( MMatrix m)

Definition at line 56 of file mmatrix.cpp.

00056 {
00057     MMatrix tmp(dimM, dimN);
00058     
00059     if ((m.getN () != dimN) || (m.getM () != dimM)) return tmp;
00060     
00061     for (int x = 1; x <= dimM; x ++) {
00062     for (int y = 1; y <= dimN; y++) {
00063         tmp.set (x, y, (mat[x][y] + m.get (x, y)));
00064     };
00065     };
00066     
00067     return tmp;
00068 }

MMatrix MMatrix::operator- ( MMatrix m)

Definition at line 70 of file mmatrix.cpp.

00070 {
00071     MMatrix tmp(dimM, dimN);
00072     
00073     if ((m.getN () != dimN) || (m.getM () != dimM)) return tmp;
00074     
00075     for (int x = 1; x <= dimM; x ++) {
00076     for (int y = 1; y <= dimN; y++) {
00077         tmp.set (x, y, (mat[x][y] - m.get (x, y)));
00078     };
00079     };
00080     
00081     return tmp;
00082 }

void MMatrix::operator= ( Vector v)

Definition at line 116 of file mmatrix.cpp.

00116 {
00117     dimM = 1;
00118     dimN = 3;
00119 
00120     mat[1][1] = v.x;
00121     mat[2][1] = v.y;
00122     mat[3][1] = v.z;
00123 }

MMatrix MMatrix::operator= ( MMatrix m)

MMatrix MMatrix::reduce ()

Definition at line 143 of file mmatrix.cpp.

00143 {
00144     if ((dimM > 1) && (dimN > 1)) {
00145     MMatrix tmp (dimM - 1, dimN - 1);
00146     
00147     for (int x = 1; x < dimM; x++) {
00148         for (int y = 1; y < dimN; y++) {
00149         tmp.set (x, y, mat[x][y]);
00150         };
00151     };
00152     
00153     return tmp;
00154     } else {
00155     MMatrix tmp;
00156     return tmp;
00157     };
00158 }

void MMatrix::set ( int m,
int n,
GLfloat val)

MMatrix MMatrix::trans ()

Definition at line 44 of file mmatrix.cpp.

00044 {
00045     MMatrix tmp(dimN, dimM);
00046     
00047     for (int x = 1; x <= dimN; x++) {
00048     for (int y = 1; y <= dimM; y++) {
00049         tmp.set (x, y, mat[y][x]);
00050     };
00051     };
00052     
00053     return tmp;
00054 }

Member Data Documentation

int MMatrix::dimM [private]

Definition at line 37 of file mmatrix.h.

int MMatrix::dimN [private]

Definition at line 37 of file mmatrix.h.

int MMatrix::getM

Definition at line 20 of file mmatrix.h.

int MMatrix::getN

Definition at line 21 of file mmatrix.h.

GLfloat MMatrix::mat[MAX_MMATRIX_M][MAX_MMATRIX_N] [private]

Definition at line 39 of file mmatrix.h.


The documentation for this class was generated from the following files:
Generated at Sat May 13 13:50:25 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000