renderstack::matrix Class Reference

4 x 4 float matrix, column major

#include <matrix.hpp>

Public Member Functions

 matrix ()
 matrix (matrix const &other)
 matrix (quaternion const &q)
matrixoperator= (matrix const &other)
 matrix (float m00, float m10, float m20, float m30, float m01, float m11, float m21, float m31, float m02, float m12, float m22, float m32, float m03, float m13, float m23, float m33)
 matrix (vec4 const &row0, vec4 const &row1, vec4 const &row2, vec4 const &row3)
vec3 transform_vector (vec3 const &v) const
vec4 transform_vector (vec4 const &v) const
vec3 uniform_transform_direction (vec3 const &v) const
matrix operator* (matrix const &other) const
matrixoperator*= (matrix const &other)
vec3 column3 (int column) const
vec4 column (int column) const
vec4 row (int row) const
void set_row (int row, vec4 const &v)
void set_column (int col, vec4 const &v)

Static Public Member Functions

static matrix identity ()

Data Fields

float m [4][4]

Detailed Description

Definition at line 44 of file matrix.hpp.


Constructor & Destructor Documentation

renderstack::matrix::matrix (  )  [inline]

Definition at line 47 of file matrix.hpp.

00047 {}

renderstack::matrix::matrix ( matrix const &  other  )  [inline]

Definition at line 48 of file matrix.hpp.

00049     {
00050         m[0][0] = other.m[0][0]; m[1][0] = other.m[1][0]; m[2][0] = other.m[2][0]; m[3][0] = other.m[3][0];
00051         m[0][1] = other.m[0][1]; m[1][1] = other.m[1][1]; m[2][1] = other.m[2][1]; m[3][1] = other.m[3][1];
00052         m[0][2] = other.m[0][2]; m[1][2] = other.m[1][2]; m[2][2] = other.m[2][2]; m[3][2] = other.m[3][2];
00053         m[0][3] = other.m[0][3]; m[1][3] = other.m[1][3]; m[2][3] = other.m[2][3]; m[3][3] = other.m[3][3];
00054     }

renderstack::matrix::matrix ( quaternion const &  q  )  [explicit]

Definition at line 109 of file matrix.cpp.

00110 {
00111     float x2 = 2.0f * q.x;
00112     float y2 = 2.0f * q.y;
00113     float z2 = 2.0f * q.z;
00114     float xx = q.x * x2;
00115     float xy = q.x * y2;
00116     float xz = q.x * z2;
00117     float yy = q.y * y2;
00118     float yz = q.y * z2;
00119     float zz = q.z * z2;
00120     float wx = q.w * x2;
00121     float wy = q.w * y2;
00122     float wz = q.w * z2;
00123 
00124     m[0][0] = 1.0f - yy - zz;   m[1][0] = xy - wz;          m[2][0] = xz + wy;          m[3][0] = 0.0f; 
00125     m[0][1] = xy + wz;          m[1][1] = 1.0f - xx - zz;   m[2][1] = yz - wx;          m[3][1] = 0.0f; 
00126     m[0][2] = xz - wy;          m[1][2] = yz + wx;          m[2][2] = 1.0f - xx - yy;   m[3][2] = 0.0f;
00127     m[0][3] = 0.0f;             m[1][3] = 0.0f;             m[2][3] = 0.0f;             m[3][3] = 1.0f;
00128 
00129 }

renderstack::matrix::matrix ( float  m00,
float  m10,
float  m20,
float  m30,
float  m01,
float  m11,
float  m21,
float  m31,
float  m02,
float  m12,
float  m22,
float  m32,
float  m03,
float  m13,
float  m23,
float  m33 
) [inline]

Definition at line 67 of file matrix.hpp.

00073     {
00074         m[0][0] = m00; m[1][0] = m10; m[2][0] = m20; m[3][0] = m30;
00075         m[0][1] = m01; m[1][1] = m11; m[2][1] = m21; m[3][1] = m31;
00076         m[0][2] = m02; m[1][2] = m12; m[2][2] = m22; m[3][2] = m32;
00077         m[0][3] = m03; m[1][3] = m13; m[2][3] = m23; m[3][3] = m33;
00078     }

renderstack::matrix::matrix ( vec4 const &  row0,
vec4 const &  row1,
vec4 const &  row2,
vec4 const &  row3 
) [inline]

Definition at line 79 of file matrix.hpp.

00085     {
00086         m[0][0] = row0.x; m[1][0] = row0.y; m[2][0] = row0.z; m[3][0] = row0.w;
00087         m[0][1] = row1.x; m[1][1] = row1.y; m[2][1] = row1.z; m[3][1] = row1.w;
00088         m[0][2] = row2.x; m[1][2] = row2.y; m[2][2] = row2.z; m[3][2] = row2.w;
00089         m[0][3] = row3.x; m[1][3] = row3.y; m[2][3] = row3.z; m[3][3] = row3.w;
00090     }


Member Function Documentation

matrix& renderstack::matrix::operator= ( matrix const &  other  )  [inline]

Definition at line 57 of file matrix.hpp.

00058     {
00059         m[0][0] = other.m[0][0]; m[1][0] = other.m[1][0]; m[2][0] = other.m[2][0]; m[3][0] = other.m[3][0];
00060         m[0][1] = other.m[0][1]; m[1][1] = other.m[1][1]; m[2][1] = other.m[2][1]; m[3][1] = other.m[3][1];
00061         m[0][2] = other.m[0][2]; m[1][2] = other.m[1][2]; m[2][2] = other.m[2][2]; m[3][2] = other.m[3][2];
00062         m[0][3] = other.m[0][3]; m[1][3] = other.m[1][3]; m[2][3] = other.m[2][3]; m[3][3] = other.m[3][3];
00063 
00064         return *this;
00065     }

vec3 renderstack::matrix::transform_vector ( vec3 const &  v  )  const

Definition at line 80 of file matrix.cpp.

00081 {
00082     return vec3(
00083         m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0],
00084         m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1],
00085         m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2]
00086     );
00087 }

vec4 renderstack::matrix::transform_vector ( vec4 const &  v  )  const

Definition at line 89 of file matrix.cpp.

00090 {
00091     return vec4(
00092         m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z + m[3][0] * v.w,
00093         m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z + m[3][1] * v.w,
00094         m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z + m[3][2] * v.w,
00095         m[0][3] * v.x + m[1][3] * v.y + m[2][3] * v.z + m[3][3] * v.w
00096     );
00097 }

vec3 renderstack::matrix::uniform_transform_direction ( vec3 const &  v  )  const

Definition at line 99 of file matrix.cpp.

00100 {
00101     return vec3(
00102         m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z,
00103         m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z,
00104         m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z
00105     );
00106 }

matrix renderstack::matrix::operator* ( matrix const &  other  )  const

Definition at line 131 of file matrix.cpp.

00132 {
00133     return matrix(
00134         m[0][0] * other.m[0][0] + m[1][0] * other.m[0][1] + m[2][0] * other.m[0][2] + m[3][0] * other.m[0][3],
00135         m[0][0] * other.m[1][0] + m[1][0] * other.m[1][1] + m[2][0] * other.m[1][2] + m[3][0] * other.m[1][3],
00136         m[0][0] * other.m[2][0] + m[1][0] * other.m[2][1] + m[2][0] * other.m[2][2] + m[3][0] * other.m[2][3],
00137         m[0][0] * other.m[3][0] + m[1][0] * other.m[3][1] + m[2][0] * other.m[3][2] + m[3][0] * other.m[3][3],
00138 
00139         m[0][1] * other.m[0][0] + m[1][1] * other.m[0][1] + m[2][1] * other.m[0][2] + m[3][1] * other.m[0][3],
00140         m[0][1] * other.m[1][0] + m[1][1] * other.m[1][1] + m[2][1] * other.m[1][2] + m[3][1] * other.m[1][3],
00141         m[0][1] * other.m[2][0] + m[1][1] * other.m[2][1] + m[2][1] * other.m[2][2] + m[3][1] * other.m[2][3],
00142         m[0][1] * other.m[3][0] + m[1][1] * other.m[3][1] + m[2][1] * other.m[3][2] + m[3][1] * other.m[3][3],
00143 
00144         m[0][2] * other.m[0][0] + m[1][2] * other.m[0][1] + m[2][2] * other.m[0][2] + m[3][2] * other.m[0][3],
00145         m[0][2] * other.m[1][0] + m[1][2] * other.m[1][1] + m[2][2] * other.m[1][2] + m[3][2] * other.m[1][3],
00146         m[0][2] * other.m[2][0] + m[1][2] * other.m[2][1] + m[2][2] * other.m[2][2] + m[3][2] * other.m[2][3],
00147         m[0][2] * other.m[3][0] + m[1][2] * other.m[3][1] + m[2][2] * other.m[3][2] + m[3][2] * other.m[3][3],
00148 
00149         m[0][3] * other.m[0][0] + m[1][3] * other.m[0][1] + m[2][3] * other.m[0][2] + m[3][3] * other.m[0][3],
00150         m[0][3] * other.m[1][0] + m[1][3] * other.m[1][1] + m[2][3] * other.m[1][2] + m[3][3] * other.m[1][3],
00151         m[0][3] * other.m[2][0] + m[1][3] * other.m[2][1] + m[2][3] * other.m[2][2] + m[3][3] * other.m[2][3],
00152         m[0][3] * other.m[3][0] + m[1][3] * other.m[3][1] + m[2][3] * other.m[3][2] + m[3][3] * other.m[3][3]
00153     );
00154 }

matrix& renderstack::matrix::operator*= ( matrix const &  other  )  [inline]

Definition at line 97 of file matrix.hpp.

00097 { return *this = *this * other; }

vec3 renderstack::matrix::column3 ( int  column  )  const

Definition at line 53 of file matrix.cpp.

00054 {
00055     return vec3(
00056         m[col][0],
00057         m[col][1],
00058         m[col][2]
00059     );
00060 }

vec4 renderstack::matrix::column ( int  column  )  const

Definition at line 62 of file matrix.cpp.

00063 {
00064     return vec4(
00065         m[col][0],
00066         m[col][1],
00067         m[col][2],
00068         m[col][3]
00069     );
00070 }

vec4 renderstack::matrix::row ( int  row  )  const

Definition at line 43 of file matrix.cpp.

00044 {
00045     return vec4(
00046         m[0][row],
00047         m[1][row],
00048         m[2][row],
00049         m[3][row]
00050     );
00051 }

void renderstack::matrix::set_row ( int  row,
vec4 const &  v 
)

Definition at line 35 of file matrix.cpp.

00036 {
00037     m[0][row] = v.x;
00038     m[1][row] = v.y;
00039     m[2][row] = v.z;
00040     m[3][row] = v.w;
00041 }

void renderstack::matrix::set_column ( int  col,
vec4 const &  v 
)

Definition at line 72 of file matrix.cpp.

00073 {
00074     m[col][0] = v.x;
00075     m[col][1] = v.y;
00076     m[col][2] = v.z;
00077     m[col][3] = v.w;
00078 }

static matrix renderstack::matrix::identity (  )  [inline, static]

Definition at line 111 of file matrix.hpp.

00112     {
00113         return matrix(
00114             1.0f, 0.0f, 0.0f, 0.0f,
00115             0.0f, 1.0f, 0.0f, 0.0f,
00116             0.0f, 0.0f, 1.0f, 0.0f,
00117             0.0f, 0.0f, 0.0f, 1.0f
00118         );
00119     };


Field Documentation

Definition at line 108 of file matrix.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 12:23:11 2010 for RenderStack by  doxygen 1.6.3