A 3D Dynamic Geometry Software

Calques 3D C++



tmatrix Class Reference

Collaboration diagram for tmatrix:

Collaboration graph

List of all members.


Detailed Description

A transformation matrix class.

The matrix class groups sixteen real values an treats them as a 4x4 matrix. Standard C++ matrices (2 dimensional vectors) are stored by row, since for graphical applications a column major order is preferable the access indices are internally swapped.

The most common operators between matrices (and some which involves scalars and vectors too) are defined.


Public Types

enum  ordermode { COLUMN, ROW }
 Espresses how to store a tmatrix in a single 16 elements vector, by column or by row. More...

Public Member Functions

 tmatrix ()
 default constructor
 tmatrix (const real &val)
 constructs a tmatrix and fills it with a value
 tmatrix (const real vector[16], ordermode ord=COLUMN)
 constructs a tmatrix from a vector which contains a 4x4 matrix in row major or column major order
 tmatrix (const tmatrix &other)
 the copy constructor
 ~tmatrix ()
 the distructor
tmatrixoperator- ()
 negation
tmatrixoperator= (const tmatrix &other)
 assignment
tmatrixoperator+= (const tmatrix &other)
 sum & assign
tmatrixoperator-= (const tmatrix &other)
 subtract & assign
tmatrixoperator *= (const tmatrix &other)
 multiply by a tmatrix & assign
tmatrixoperator *= (const real &fact)
 multiply by a scalar factor & assign
tmatrixoperator/= (const real &fact)
 divide by a scalar factor & assign
realoperator() (const int &row, const int &col)
 an "access like a C++ tmatrix"
 operator double * ()
 conversion to a 16 doubles C++ vector (column major order)
void loadIdentity ()
 fills the matrix with the identity matrix

Static Public Member Functions

static int howMany ()
 returns how many tmatrix objects exists

Private Attributes

real mat [4][4]
 the matrix data

Static Private Attributes

static int counter = 0
 counts how many matrices objects are present

Friends

int operator== (const tmatrix &t1, const tmatrix &t2)
 the equality operator
int operator!= (const tmatrix &t1, const tmatrix &t2)
 the inequality operator
tmatrix operator+ (const tmatrix &t1, const tmatrix &t2)
 the sum
tmatrix operator- (const tmatrix &t1, const tmatrix &t2)
 the difference
tmatrix operator * (const tmatrix &t1, const tmatrix &t2)
 tmatrix product
tmatrix operator * (const tmatrix &tmat, const real &fact)
 multiply a tmatrix by a scalar factor
tmatrix operator * (const real &fact, const tmatrix &tmat)
 multiply a scalar factor by a tmatrix
tmatrix operator/ (const tmatrix &tmat, const real &fact)
 divide a tmatrix by a scalar factor
ostream & operator<< (ostream &os, const tmatrix &m)
 print tmatrix to C++ stream

Member Enumeration Documentation

enum ordermode

Espresses how to store a tmatrix in a single 16 elements vector, by column or by row.

Enumerator:
COLUMN  column major order
ROW  row major order


Constructor & Destructor Documentation

tmatrix (  ) 

default constructor

Parameters:
bInit if set to true initializes the matrix to the identity matrix

tmatrix ( const real val  ) 

constructs a tmatrix and fills it with a value

tmatrix ( const real  vector[16],
ordermode  ord = COLUMN 
)

constructs a tmatrix from a vector which contains a 4x4 matrix in row major or column major order

tmatrix ( const tmatrix other  )  [inline]

the copy constructor

~tmatrix (  )  [inline]

the distructor


Member Function Documentation

tmatrix & operator- (  ) 

negation

tmatrix & operator= ( const tmatrix other  ) 

assignment

tmatrix & operator+= ( const tmatrix other  ) 

sum & assign

tmatrix & operator-= ( const tmatrix other  ) 

subtract & assign

tmatrix & operator *= ( const tmatrix other  ) 

multiply by a tmatrix & assign

tmatrix & operator *= ( const real fact  ) 

multiply by a scalar factor & assign

tmatrix & operator/= ( const real fact  ) 

divide by a scalar factor & assign

real & operator() ( const int &  row,
const int &  col 
) [inline]

an "access like a C++ tmatrix"

This operator redirects the access to the internal matrix. It does make a range check on the index in debug builds trough the ANSI assert function. It can be used on both sides of an assignment.

Returns:
a reference to the requested element
Parameters:
row the row index which should be one of 0,1,2,3
col the column index which should be one of 0,1,2,3
Date:
18/06/99

operator double * (  )  [inline]

conversion to a 16 doubles C++ vector (column major order)

this conversion operator allows to use a tmatrix in places where a column major order vector of 16 double elements is requested (e.g. the OpenGL functions for retrieving/setting the modelview or projection matrix).

void loadIdentity (  ) 

fills the matrix with the identity matrix

int howMany (  )  [inline, static]

returns how many tmatrix objects exists

The counting of the tmatrix objects is realized trough a static counter variable.

Returns:
the number of tmatrix objects in memory


Friends And Related Function Documentation

int operator== ( const tmatrix t1,
const tmatrix t2 
) [friend]

the equality operator

int operator!= ( const tmatrix t1,
const tmatrix t2 
) [friend]

the inequality operator

tmatrix operator+ ( const tmatrix t1,
const tmatrix t2 
) [friend]

the sum

tmatrix operator- ( const tmatrix t1,
const tmatrix t2 
) [friend]

the difference

tmatrix operator * ( const tmatrix t1,
const tmatrix t2 
) [friend]

tmatrix product

tmatrix operator * ( const tmatrix tmat,
const real fact 
) [friend]

multiply a tmatrix by a scalar factor

tmatrix operator * ( const real fact,
const tmatrix tmat 
) [friend]

multiply a scalar factor by a tmatrix

tmatrix operator/ ( const tmatrix tmat,
const real fact 
) [friend]

divide a tmatrix by a scalar factor

ostream& operator<< ( ostream &  os,
const tmatrix m 
) [friend]

print tmatrix to C++ stream


Member Data Documentation

int counter = 0 [static, private]

counts how many matrices objects are present

real mat[4][4] [private]

the matrix data