ps2matrix4x4.h

00001 /*
00002 * "PS2" Application Framework
00003 *
00004 * University of Abertay Dundee
00005 * May be used for educational purposed only
00006 *
00007 * Author - Dr Henry S Fortuna
00008 *
00009 * $Revision: 1.2 $
00010 * $Date: 2007/08/19 12:45:11 $
00011 *
00012 */
00013 
00014 #ifndef __PS2MATRIX4x4_H__
00015 #define __PS2MATRIX4x4_H__
00016 
00017 #include <stdio.h>
00018 #include "ps2vector4.h"
00019 
00020 class Matrix4x4
00021 {
00022 public:
00023         Matrix4x4(void);
00024         Matrix4x4(const Matrix4x4 & rhs);
00025         Matrix4x4(float _elem[][4]);
00026         Matrix4x4(float _11, float _12, float _13, float _14,
00027                                 float _21, float _22, float _23, float _24,
00028                                 float _31, float _32, float _33, float _34,
00029                                 float _41, float _42, float _43, float _44);
00030 
00031         ~Matrix4x4(void);
00032 
00033         void Translation(float X, float Y, float Z);
00034         void Translate(float X, float Y, float Z);
00035         void Scaling(float S);
00036         void RotationX(float fAngle);
00037         void RotationY(float fAngle);
00038         void RotationZ(float fAngle);
00039         
00040         void DumpMatrix4x4(char * s = NULL);
00041 
00042         void LookAt(const Vector4 & vFrom,
00043                                 const Vector4 & vTo,
00044                                 const Vector4 & vUp);
00045 
00046         inline float &operator()( unsigned int Row, unsigned int Column )
00047         { return elem[Row][Column]; }
00048         inline float const &operator()( unsigned int Row, unsigned int Column ) const
00049         { return elem[Row][Column]; }
00050 
00051         float elem[4][4];
00052 
00053         static const Matrix4x4 IDENTITY;
00054         static const Matrix4x4 NULLMATRIX;
00055 };
00056 
00057 Matrix4x4 operator * ( const Matrix4x4 & M1,
00058                                            const Matrix4x4 & M2 );
00059 
00060 Vector4 operator * ( const Matrix4x4 & M,
00061                                          const Vector4 & V );
00062 
00063 inline Matrix4x4 operator - ( const Matrix4x4 & M )
00064 {
00065         return Matrix4x4(-M(0,0),-M(0,1),-M(0,2),-M(0,3),
00066                                          -M(1,0),-M(1,1),-M(1,2),-M(1,3),
00067                                          -M(2,0),-M(2,1),-M(2,2),-M(2,3),
00068                                          -M(3,0),-M(3,1),-M(3,2),-M(3,3));
00069 }
00070 
00071 inline Matrix4x4 operator - ( const Matrix4x4 & M1,
00072                                                           const Matrix4x4 & M2 )
00073 {
00074         return Matrix4x4(M1(0,0)-M2(0,0),M1(0,1)-M2(0,1),M1(0,2)-M2(0,2),M1(0,3)-M2(0,3),
00075                                          M1(1,0)-M2(1,0),M1(1,1)-M2(1,1),M1(1,2)-M2(1,2),M1(1,3)-M2(1,3),
00076                                          M1(2,0)-M2(2,0),M1(2,1)-M2(2,1),M1(2,2)-M2(2,2),M1(2,3)-M2(2,3),
00077                                          M1(3,0)-M2(3,0),M1(3,1)-M2(3,1),M1(3,2)-M2(3,2),M1(3,3)-M2(3,3));
00078 }
00079 
00080 inline Matrix4x4 operator + ( const Matrix4x4 & M1,
00081                                                           const Matrix4x4 & M2 )
00082 {
00083         return Matrix4x4(M1(0,0)+M2(0,0),M1(0,1)+M2(0,1),M1(0,2)+M2(0,2),M1(0,3)+M2(0,3),
00084                                          M1(1,0)+M2(1,0),M1(1,1)+M2(1,1),M1(1,2)+M2(1,2),M1(1,3)+M2(1,3),
00085                                          M1(2,0)+M2(2,0),M1(2,1)+M2(2,1),M1(2,2)+M2(2,2),M1(2,3)+M2(2,3),
00086                                          M1(3,0)+M2(3,0),M1(3,1)+M2(3,1),M1(3,2)+M2(3,2),M1(3,3)+M2(3,3));
00087 }
00088 
00089 inline Matrix4x4 operator * ( const Matrix4x4 & M,
00090                                                           const float & s )
00091 {
00092         return Matrix4x4(M(0,0) * s,M(0,1) * s,M(0,2) * s,M(0,3) * s,
00093                                          M(1,0) * s,M(1,1) * s,M(1,2) * s,M(1,3) * s,
00094                                          M(2,0) * s,M(2,1) * s,M(2,2) * s,M(2,3) * s,
00095                                          M(3,0) * s,M(3,1) * s,M(3,2) * s,M(3,3) * s);
00096 }
00097 
00098 inline Matrix4x4 operator * ( const float & s,
00099                                                           const Matrix4x4 & M )
00100 {
00101         return Matrix4x4(M(0,0) * s,M(0,1) * s,M(0,2) * s,M(0,3) * s,
00102                                          M(1,0) * s,M(1,1) * s,M(1,2) * s,M(1,3) * s,
00103                                          M(2,0) * s,M(2,1) * s,M(2,2) * s,M(2,3) * s,
00104                                          M(3,0) * s,M(3,1) * s,M(3,2) * s,M(3,3) * s);
00105 }
00106 
00107 inline Matrix4x4 Transpose( Matrix4x4 const & M )
00108 {
00109         Matrix4x4 ret;
00110 
00111         for(int j = 0; j < 4; j++)
00112         {
00113                 for(int i = 0; i < 4; i++)
00114                 {
00115                         ret(i,j) = M(j,i);
00116                 }
00117         }
00118 
00119         return ret;
00120 }
00121 
00122 #endif

Generated on Sun May 18 21:45:08 2008 for PS2X by  doxygen 1.5.4