Back to index

extremetuxracer  0.5beta
Public Member Functions | Static Public Member Functions | Public Attributes
pp::Matrix Class Reference

#include <matrix.h>

List of all members.

Public Member Functions

 Matrix (void)
 Matrix (const Quat quat)
Matrix operator* (const Matrix matrix) const
void makeIdentity (void)
void makeRotation (const double angle, const char axis)
void makeTranslation (const double x, const double y, const double z)
void makeScaling (const double x, const double y, const double z)
void makeRotationAboutVector (const Vec3d u, const double angle)
void transpose (const Matrix &mat)
Vec3d transformVector (const Vec3d v) const
Vec3d transformPoint (const Vec3d p) const

Static Public Member Functions

static void makeChangeOfBasisMatrix (Matrix &mat, Matrix &invMat, const Vec3d w1, const Vec3d w2, const Vec3d w3)

Public Attributes

double data [4][4]

Detailed Description

Definition at line 32 of file matrix.h.


Constructor & Destructor Documentation

pp::Matrix::Matrix ( void  ) [inline]

Definition at line 36 of file matrix.h.

{};
pp::Matrix::Matrix ( const Quat  quat)

Definition at line 27 of file matrix.cpp.

{
    data[0][0] = 1.0 - 2.0 * ( quat.y * quat.y + quat.z * quat.z );
    data[1][0] =       2.0 * ( quat.x * quat.y - quat.w * quat.z );
    data[2][0] =       2.0 * ( quat.x * quat.z + quat.w * quat.y );

    data[0][1] =       2.0 * ( quat.x * quat.y + quat.w * quat.z );
    data[1][1] = 1.0 - 2.0 * ( quat.x * quat.x + quat.z * quat.z );
    data[2][1] =       2.0 * ( quat.y * quat.z - quat.w * quat.x );

       data[0][2] =       2.0 * ( quat.x * quat.z - quat.w * quat.y );
    data[1][2] =       2.0 * ( quat.y * quat.z + quat.w * quat.x );
    data[2][2] = 1.0 - 2.0 * ( quat.x * quat.x + quat.y * quat.y );

    data[3][0] = data[3][1] = data[3][2] = 0.0;
    data[0][3] = data[1][3] = data[2][3] = 0.0;
    data[3][3] = 1.0;
}

Member Function Documentation

void pp::Matrix::makeChangeOfBasisMatrix ( Matrix mat,
Matrix invMat,
const Vec3d  w1,
const Vec3d  w2,
const Vec3d  w3 
) [static]

Definition at line 211 of file matrix.cpp.

{
       mat.makeIdentity();
    mat.data[0][0] = w1.x;
    mat.data[0][1] = w1.y;
    mat.data[0][2] = w1.z;
    mat.data[1][0] = w2.x;
    mat.data[1][1] = w2.y;
    mat.data[1][2] = w2.z;
    mat.data[2][0] = w3.x;
    mat.data[2][1] = w3.y;
    mat.data[2][2] = w3.z;

    invMat.makeIdentity();
    invMat.data[0][0] = w1.x;
    invMat.data[1][0] = w1.y;
    invMat.data[2][0] = w1.z;
    invMat.data[0][1] = w2.x;
    invMat.data[1][1] = w2.y;
    invMat.data[2][1] = w2.z;
    invMat.data[0][2] = w3.x;
    invMat.data[1][2] = w3.y;
    invMat.data[2][2] = w3.z;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Matrix::makeIdentity ( void  )

Definition at line 47 of file matrix.cpp.

{
       for(int i=0; i<4; i++){
              for(int j=0; j<4; j++){
                     data[i][j]=(i==j);   
              }
       }
}      

Here is the caller graph for this function:

void pp::Matrix::makeRotation ( const double  angle,
const char  axis 
)

Definition at line 57 of file matrix.cpp.

{
       double sinv = sin( ANGLES_TO_RADIANS( angle ) );
    double cosv = cos( ANGLES_TO_RADIANS( angle ) );

    makeIdentity();

    switch( axis ) {
    case 'x':
        data[1][1] = cosv;
        data[2][1] = -sinv;
        data[1][2] = sinv;
        data[2][2] = cosv;
        break;

    case 'y':
        data[0][0] = cosv;
        data[2][0] = sinv;
        data[0][2] = -sinv;
        data[2][2] = cosv;
        break;

    case 'z': 
        data[0][0] = cosv;
        data[1][0] = -sinv;
        data[0][1] = sinv;
        data[1][1] = cosv;
        break;

    default:
              {
        //code_not_reached();  /* shouldn't get here */
              }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Matrix::makeRotationAboutVector ( const Vec3d  u,
const double  angle 
)

Definition at line 112 of file matrix.cpp.

{
       Matrix rx,irx, ry, iry;
       
    double a = u.x;
    double b = u.y;
    double c = u.z;
       double d = sqrt( b*b + c*c );

    if ( d < EPS ) {
        if ( a < 0 ) 
            makeRotation( -angle, 'x' );
        else
            makeRotation( angle, 'x' );
        return;
    } 

    rx.makeIdentity();
    irx.makeIdentity();
    ry.makeIdentity();
    iry.makeIdentity();

    rx.data[1][1] = c/d;
    rx.data[2][1] = -b/d;
    rx.data[1][2] = b/d;
    rx.data[2][2] = c/d;

    irx.data[1][1] = c/d;
    irx.data[2][1] = b/d;
    irx.data[1][2] = -b/d;
    irx.data[2][2] = c/d;

    ry.data[0][0] = d;
    ry.data[2][0] = -a;
    ry.data[0][2] = a;
    ry.data[2][2] = d;

    iry.data[0][0] = d;
    iry.data[2][0] = a;
    iry.data[0][2] = -a;
    iry.data[2][2] = d;

    makeRotation( angle, 'z' );

    *this=(*this)*ry;
    *this=(*this)*rx;
    *this=iry*(*this);
    *this=irx*(*this);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Matrix::makeScaling ( const double  x,
const double  y,
const double  z 
)

Definition at line 103 of file matrix.cpp.

{
       makeIdentity();
    data[0][0] = x;
    data[1][1] = y;
    data[2][2] = z;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Matrix::makeTranslation ( const double  x,
const double  y,
const double  z 
)

Definition at line 94 of file matrix.cpp.

{
       makeIdentity();
    data[3][0] = x;
    data[3][1] = y;
    data[3][2] = z;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Matrix pp::Matrix::operator* ( const Matrix  matrix) const

Definition at line 174 of file matrix.cpp.

{
       Matrix ret;
 
    for( int i= 0 ; i< 4 ; i++ )
       for( int j= 0 ; j< 4 ; j++ )
           ret.data[j][i]=
              data[0][i] * matrix.data[j][0] +
              data[1][i] * matrix.data[j][1] +
              data[2][i] * matrix.data[j][2] +
              data[3][i] * matrix.data[j][3];

       return ret;
}

Definition at line 201 of file matrix.cpp.

{
       return Vec3d(
       p.x * data[0][0] + p.y * data[1][0] + p.z * data[2][0] + data[3][0],
       p.x * data[0][1] + p.y * data[1][1] + p.z * data[2][1] + data[3][1],
       p.x * data[0][2] + p.y * data[1][2] + p.z * data[2][2] + data[3][2]
    );
}

Here is the caller graph for this function:

Definition at line 190 of file matrix.cpp.

{   
       return Vec3d(
              v.x * data[0][0] + v.y * data[1][0] + v.z * data[2][0],
       v.x * data[0][1] + v.y * data[1][1] + v.z * data[2][1],
       v.x * data[0][2] + v.y * data[1][2] + v.z * data[2][2]
       );
}

Here is the caller graph for this function:

void pp::Matrix::transpose ( const Matrix mat)

Definition at line 164 of file matrix.cpp.

{
       for( int i= 0 ; i< 4 ; i++ ){
              for( int j= 0 ; j< 4 ; j++ ){
              data[j][i] = matrix.data[i][j];
              }
       }
}

Here is the caller graph for this function:


Member Data Documentation

double pp::Matrix::data[4][4]

Definition at line 35 of file matrix.h.


The documentation for this class was generated from the following files: