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

Matrix4x4 Class Reference

#include <matrix.h>

List of all members.

Public Methods

 Matrix4x4 ()
 Matrix4x4 (float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
 Matrix4x4 (Matrix4x4 *matrix)
const VECTOR operator * (const VECTOR &vec) const
void identity ()
void transpose ()
void rotation (VECTOR from, VECTOR to)
void rotateX (float alpha)
void rotateY (float alpha)
void rotateZ (float alpha)
Matrix4x4 mul (Matrix4x4 m)
void translate (VECTOR a)

Private Attributes

float mat [4][4]


Constructor & Destructor Documentation

Matrix4x4::Matrix4x4  
 

Definition at line 16 of file matrix.cpp.

References mat.

Referenced by mul().

00016                      {
00017         
00018         for(int i = 0; i < 4; i++) {
00019                 for(int j=0;j < 4; j++) {
00020                         mat[i][j] = 0.0;
00021                 }
00022         }
00023 }

Matrix4x4::Matrix4x4 float    m11,
float    m12,
float    m13,
float    m14,
float    m21,
float    m22,
float    m23,
float    m24,
float    m31,
float    m32,
float    m33,
float    m34,
float    m41,
float    m42,
float    m43,
float    m44
 

Definition at line 31 of file matrix.cpp.

References mat.

00034                                                                                      {
00035         
00036         mat[0][0] = m11;
00037         mat[0][1] = m21;
00038         mat[0][2] = m31;
00039         mat[0][3] = m41;
00040         mat[1][0] = m12;
00041         mat[1][1] = m22;
00042         mat[1][2] = m32;
00043         mat[1][3] = m42;
00044         mat[2][0] = m13;
00045         mat[2][1] = m23;
00046         mat[2][2] = m33;
00047         mat[2][3] = m43;
00048         mat[3][0] = m14;
00049         mat[3][1] = m24;
00050         mat[3][2] = m34;
00051         mat[3][3] = m44;
00052 
00053 }

Matrix4x4::Matrix4x4 Matrix4x4 *    matrix
 

Definition at line 25 of file matrix.cpp.

References mat.

00025                                       {
00026         for(int i =0;i <4;i++)
00027                 for(int j=0;j <4; j++)
00028                         mat[i][j] = matrix->mat[i][j];
00029 }


Member Function Documentation

void Matrix4x4::identity  
 

Definition at line 56 of file matrix.cpp.

References mat.

Referenced by Raycaster::SetViewingMatrix().

00056                     {
00057         for(int i =0; i < 4; i++)
00058                 for(int j= 0;j < 4; j++)
00059                         mat[i][j] = 0.0;
00060         mat[0][0] = 1.0;
00061         mat[1][1] = 1.0;
00062         mat[2][2] = 1.0;
00063         mat[3][3] = 1.0;
00064 }

Matrix4x4 Matrix4x4::mul Matrix4x4    m
 

Definition at line 88 of file matrix.cpp.

References mat, and Matrix4x4().

Referenced by Raycaster::RotateX(), Raycaster::RotateY(), and Raycaster::RotateZ().

00088                          {
00089         Matrix4x4 *ret = new Matrix4x4();
00090         for(int i = 0;i < 4; i++) {
00091                 for(int j = 0;j < 4;j++) {
00092                         for(int k = 0; k< 4; k++) {
00093                                 ret->mat[i][j] = ret->mat[i][j]+mat[k][j]*m.mat[i][k];
00094                         }
00095                 }
00096         }
00097         return *ret;
00098 }

const VECTOR Matrix4x4::operator * const VECTOR   vec const
 

Definition at line 67 of file matrix.cpp.

References mat, VECTOR::x, VECTOR::y, and VECTOR::z.

00067                                               {
00068         VECTOR result;
00069         result.x = mat[0][0]*vec.x + mat[1][0]*vec.y + mat[2][0] * vec.z + mat[3][0];
00070         result.y = mat[0][1]*vec.x + mat[1][1]*vec.y + mat[2][1] * vec.z + mat[3][1];
00071         result.z = mat[0][2]*vec.x + mat[1][2]*vec.y + mat[2][2] * vec.z + mat[3][2];
00072         return result;
00073 }

void Matrix4x4::rotateX float    alpha
 

Definition at line 204 of file matrix.cpp.

References mat, and PI.

Referenced by Raycaster::RotateX().

00204                               {
00205         double rad = alpha / 180 * PI;
00206         float cosa = cos(rad);
00207         float sina;// = sin(PI);
00208 
00209         sina = sqrt((1 - cosa * cosa));
00210 
00211         mat[0][0] = 1.0f;
00212         mat[0][1] = 0.0f;
00213         mat[0][2] = 0.0f;
00214         mat[0][3] = 0.0f;
00215 
00216         mat[1][0] = 0.0f;
00217         mat[1][1] = cosa;
00218         mat[1][2] = sina;
00219         mat[1][3] = 0.0f;
00220 
00221         mat[2][0] = 1.0f;
00222         mat[2][1] = -sina;
00223         mat[2][2] = cosa;
00224         mat[2][3] = 0.0f;
00225 
00226         mat[3][0] = 0.0f;
00227         mat[3][1] = 0.0f;
00228         mat[3][2] = 0.0f;
00229         mat[3][3] = 1.0f;
00230 }

void Matrix4x4::rotateY float    alpha
 

Definition at line 233 of file matrix.cpp.

References mat, and PI.

Referenced by Raycaster::RotateY().

00233                               {
00234         double rad = alpha / 180 * PI;
00235         float cosa = cos(rad);
00236         float sina;// = sin(PI);
00237 
00238         sina = sqrt((1 - cosa * cosa));
00239 
00240         mat[0][0] = cosa;
00241         mat[0][1] = 0.0f;
00242         mat[0][2] = -sina;
00243         mat[0][3] = 0.0f;
00244 
00245         mat[1][0] = 0.0f;
00246         mat[1][1] = 1.0f;
00247         mat[1][2] = 0.0f;
00248         mat[1][3] = 0.0f;
00249 
00250         mat[2][0] = sina;
00251         mat[2][1] = 0.0f;
00252         mat[2][2] = cosa;
00253         mat[2][3] = 0.0f;
00254 
00255         mat[3][0] = 0.0f;
00256         mat[3][1] = 0.0f;
00257         mat[3][2] = 0.0f;
00258         mat[3][3] = 1.0f;
00259 }

void Matrix4x4::rotateZ float    alpha
 

Definition at line 262 of file matrix.cpp.

References mat, and PI.

Referenced by Raycaster::RotateZ().

00262                               {
00263         double rad = alpha / 180 * PI;
00264         float cosa = cos(rad);
00265         float sina;// = sin(PI);
00266 
00267         sina = sqrt((1 - cosa * cosa));
00268 
00269         mat[0][0] = cosa;
00270         mat[0][1] = sina;
00271         mat[0][2] = 0.0f;
00272         mat[0][3] = 0.0f;
00273 
00274         mat[1][0] = -sina;
00275         mat[1][1] = cosa;
00276         mat[1][2] = 0.0f;
00277         mat[1][3] = 0.0f;
00278 
00279         mat[2][0] = 0.0f;
00280         mat[2][1] = 0.0f;
00281         mat[2][2] = 1.0f;
00282         mat[2][3] = 0.0f;
00283 
00284         mat[3][0] = 0.0f;
00285         mat[3][1] = 0.0f;
00286         mat[3][2] = 0.0f;
00287         mat[3][3] = 1.0f;
00288 }

void Matrix4x4::rotation VECTOR    from,
VECTOR    to
 

Definition at line 121 of file matrix.cpp.

References VECTOR::cross(), VECTOR::dot(), EPSILON, mat, VECTOR::x, VECTOR::y, and VECTOR::z.

00121                                           {
00122         VECTOR v;
00123         float e, h, f;
00124         
00125         v = from.cross(to);
00126         e = from.dot(to);
00127         f = (e < 0)? -e:e;
00128         if (f > 1.0 - EPSILON) {
00129                 VECTOR x;
00130 
00131                 x.x = (from.x > 0.0) ? from.x : -from.x;
00132                 x.y = (from.y > 0.0) ? from.y : -from.y;
00133                 x.z = (from.z > 0.0) ? from.z : -from.z;
00134 
00135                 if(x.x < x.y) {
00136                         if(x.x < x.z) {
00137                                 x.x = 1.0;
00138                                 x.y = x.z = 0.0;
00139                         } else {
00140                                 x.z = 1.0; x.x = x.y = 0.0;
00141                         }
00142                 }
00143                 else {
00144                         if(x.y < x.z) {
00145                                 x.y = 1.0; x.x = x.z = 0.0;
00146                         } else {
00147                                 x.z = 1.0; x.x = x.y = 0.0;
00148                         }
00149                 }
00150 
00151                 VECTOR u = x - from;
00152                 VECTOR w = x - to;
00153 
00154                 float c1 = 2.0 / u.dot(u);
00155                 float c2 = 2.0 / w.dot(w);
00156                 float c3 = c1 * c2 * u.dot(w);
00157 
00158                 float u_h[3];
00159                 float w_h[3];
00160 
00161                 u_h[0] = u.x;
00162                 u_h[1] = u.y;
00163                 u_h[2] = u.z;
00164 
00165                 w_h[0] = w.x;
00166                 w_h[1] = w.y;
00167                 w_h[2] = w.z;
00168 
00169 
00170                 for(int i = 0; i < 3; i++) {
00171                         for(int j = 0; j < 3; j++) {
00172                                 mat[i][j] = -c1 * u_h[i] * u_h[j] - c2 * w_h[i]*w_h[j] + c3 * w_h[i] * u_h[j];
00173                         }
00174                         mat[i][i] += 1.0;
00175                 }
00176         }
00177         else
00178         {
00179                 h = (1.0 - e)/(v.dot(v));
00180     
00181                 mat[0][0] = e + h*v.x * v.x; 
00182                 mat[0][1] = h*v.x*v.y - v.z;     
00183                 mat[0][2] = h*v.x*v.z + v.y;
00184                 mat[0][3] = 0.0f;
00185 
00186                 mat[1][0] = h*v.x*v.y + v.z;  
00187                 mat[1][1] = e + h * v.y * v.y; 
00188                 mat[1][2] = h*v.y*v.z - v.x;
00189                 mat[1][3] = 0.0f;
00190 
00191                 mat[2][0] = h*v.x*v.z - v.y;  
00192                 mat[2][1] = h*v.y*v.z + v.x;     
00193                 mat[2][2] = e + h*v.z * v.z;
00194                 mat[2][3] = 0.0f;
00195 
00196                 mat[3][0] = 0.0f;
00197                 mat[3][1] = 0.0f;
00198                 mat[3][2] = 0.0f;
00199                 mat[3][3] = 1.0f;
00200         }
00201 }

void Matrix4x4::translate VECTOR    a
 

Definition at line 101 of file matrix.cpp.

References mat, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by Raycaster::Raycast().

00101                              {
00102         for(int i = 0;i < 4;i++) {
00103                 for(int j = 0; j <4;j++) {
00104                         mat[i][j] = 0.0;
00105                 }
00106         }
00107         for(int j = 0;j <4; j++) {
00108                 mat[j][j] = 1.0;
00109         }
00110         mat[3][0] = a.x;
00111         mat[3][1] = a.y;
00112         mat[3][2] = a.z;
00113 }

void Matrix4x4::transpose  
 

Definition at line 76 of file matrix.cpp.

References mat.

00076                      {
00077         float tmp;
00078         for(int i = 0; i < 4; i++) {
00079                 for(int j = 0; j < 4; j++) {
00080                         tmp = mat[i][j];
00081                         mat[i][j] = mat[j][i];
00082                         mat[j][i] = tmp;
00083                 }
00084         }
00085 }


Member Data Documentation

float Matrix4x4::mat[4][4] [private]
 

Definition at line 9 of file matrix.h.

Referenced by identity(), Matrix4x4(), mul(), operator *(), rotateX(), rotateY(), rotateZ(), rotation(), translate(), and transpose().


The documentation for this class was generated from the following files:
Generated on Thu Jan 30 21:35:44 2003 for 3DVis by doxygen1.3-rc2