• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/util/header/m3x3.inl

Go to the documentation of this file.
00001 
00002 // ==================================================
00003 // METHODS
00004 // ==================================================
00005 
00006 template<typename Real>
00007 m3x3<Real>& m3x3<Real>::asRotationX(const Real angle)
00008 {
00009         const Real s = sin(angle);
00010         const Real c = cos(angle);
00011         m[0][0] = 1.0f; m[0][1] = 0.0f; m[0][2] = 0.0f;
00012         m[1][0] = 0.0f; m[1][1] =  c;   m[1][2] = -s;
00013         m[2][0] = 0.0f; m[2][1] =  s;   m[2][2] =  c;
00014         return *this;
00015 }
00016 
00017 template<typename Real>
00018 m3x3<Real>& m3x3<Real>::asRotationY(const Real angle)
00019 {
00020         const Real s = sin(angle);
00021         const Real c = cos(angle);
00022         m[0][0] =  c;   m[0][1] = 0.0f; m[0][2] =  s;
00023         m[1][0] = 0.0f; m[1][1] = 1.0f; m[1][2] = 0.0f;
00024         m[2][0] = -s;   m[2][1] = 0.0f; m[2][2] =  c;
00025         return *this;
00026 }
00027 
00028 template<typename Real>
00029 m3x3<Real>& m3x3<Real>::asRotationZ(const Real angle)
00030 {
00031         const Real s = sin(angle);
00032         const Real c = cos(angle);
00033         m[0][0] =  c;   m[0][1] = -s;   m[0][2] = 0.0f;
00034         m[1][0] =  s;   m[1][1] =  c;   m[1][2] = 0.0f;
00035         m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = 1.0f;
00036         return *this;
00037 }
00038 
00039 template<typename Real>
00040 m3x3<Real>& m3x3<Real>::asRotation(const Real x, const Real y, const Real z)
00041 {
00042         const Real sx = sin(x);
00043         const Real cx = cos(x);
00044         const Real sy = sin(y);
00045         const Real cy = cos(y);
00046         const Real sz = sin(z);
00047         const Real cz = cos(z);
00048         const Real sxsy = sx*sy;
00049         const Real cysz = cy*sz;
00050         const Real cycz = cy*cz;
00051 
00052         m[0][0] =  cycz-sxsy*sz; m[0][1] = -cx*sz; m[0][2] = sy*cz+cysz*sx;
00053         m[1][0] =  cysz+cz*sxsy; m[1][1] =  cx*cz; m[1][2] = sy*sz-cycz*sx;
00054         m[2][0] = -cx*sy;        m[2][1] =  sx;    m[2][2] = cx*cy;
00055 
00056         return *this;
00057 }
00058 
00059 template<typename Real>
00060 m3x3<Real>& m3x3<Real>::asScale(const Real x, const Real y, const Real z)
00061 {
00062         m[0][0] = x;    m[0][1] = 0.0f; m[0][2] = 0.0f;
00063         m[1][0] = 0.0f; m[1][1] = y;    m[1][2] = 0.0f;
00064         m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = z;
00065         return *this;
00066 }
00067 
00068 template<typename Real>
00069 m3x3<Real>& m3x3<Real>::scale(const Real x, const Real y, const Real z)
00070 {
00071         m[0][0] *= x;
00072         m[1][1] *= y;
00073         m[2][2] *= z;
00074         return *this;
00075 }
00076 
00077 template<typename Real>
00078 m3x3<Real>& m3x3<Real>::zero(void){
00079         for(char i=0; i<3; i++)
00080                 for(char j=0; j<3; j++)
00081                         m[i][j] = 0.f;
00082         return *this;
00083 }
00084 
00085 template<typename Real>
00086 m3x3<Real>& m3x3<Real>::identity(void){
00087         m[0][1] = m[0][2] =
00088         m[1][0] = m[1][2] =
00089         m[2][0] = m[2][1] = 0.0f; 
00090         m[0][0] = m[2][2] = m[1][1] = 1.0f;
00091         return *this;
00092 }
00093 
00094 template<typename Real>
00095 m3x3<Real>& m3x3<Real>::invert(void)
00096 {
00097         return *this = inverse(*this);
00098 }
00099 
00100 template<typename Real>
00101 m3x3<Real>& m3x3<Real>::transpose(void)
00102 {
00103         register Real temp;
00104         temp = m[0][1]; m[0][1] = m[1][0]; m[1][0] = temp;
00105         temp = m[0][2]; m[0][2] = m[2][0]; m[2][0] = temp;
00106         temp = m[1][2]; m[1][2] = m[2][1]; m[2][1] = temp;
00107         return *this;
00108 }
00109 
00110 template<typename Real>
00111 m3x3<Real>& m3x3<Real>::set(
00112         const Real a, const Real b, const Real c,
00113         const Real d, const Real e, const Real f,
00114         const Real g, const Real h, const Real i)
00115 {
00116         m[0][0]=a; m[0][1]=b; m[0][2]=c;
00117         m[1][0]=d; m[1][1]=e; m[1][2]=f;
00118         m[2][0]=g; m[2][1]=h; m[2][2]=i;
00119         return *this;
00120 }
00121 
00122 template<typename Real>
00123 m3x3<Real>& m3x3<Real>::get(
00124         Real& a, Real& b, Real& c,
00125         Real& d, Real& e, Real& f,
00126         Real& g, Real& h, Real& i)
00127 {
00128         a=m[0][0]; b=m[0][1]; c=m[0][2];
00129         d=m[1][0]; e=m[1][1]; f=m[1][2];
00130         g=m[2][0]; h=m[2][1]; i=m[2][2];
00131         return *this;
00132 }
00133 
00134 // ==================================================
00135 // CLASS OPERATORS
00136 // ==================================================
00137 
00138 template<typename Real>
00139 m3x3<Real>& m3x3<Real>::operator = (const m3x3<Real>& a){
00140         m[0][0]=a(0,0); m[0][1]=a(0,1); m[0][2]=a(0,2);
00141         m[1][0]=a(1,0); m[1][1]=a(1,1); m[1][2]=a(1,2);
00142         m[2][0]=a(2,0); m[2][1]=a(2,1); m[2][2]=a(2,2);
00143         return *this;
00144 }
00145 
00146 template<typename Real>
00147 m3x3<Real>& m3x3<Real>::operator += (const m3x3<Real>& a)
00148 {
00149         m[0][0]+=a(0,0); m[0][1]+=a(0,1); m[0][2]+=a(0,2);
00150         m[1][0]+=a(1,0); m[1][1]+=a(1,1); m[1][2]+=a(1,2);
00151         m[2][0]+=a(2,0); m[2][1]+=a(2,1); m[2][2]+=a(2,2);
00152         return *this;
00153 }
00154 
00155 template<typename Real>
00156 m3x3<Real>& m3x3<Real>::operator -= (const m3x3<Real>& a)
00157 {
00158         m[0][0]-=a(0,0); m[0][1]-=a(0,1); m[0][2]-=a(0,2);
00159         m[1][0]-=a(1,0); m[1][1]-=a(1,1); m[1][2]-=a(1,2);
00160         m[2][0]-=a(2,0); m[2][1]-=a(2,1); m[2][2]-=a(2,2);
00161         return *this;
00162 }
00163 
00164 template<typename Real>
00165 m3x3<Real>& m3x3<Real>::operator *= (const m3x3<Real>& a)
00166 {
00167         return *this = mul(*this, a);
00168 }
00169 
00170 template<typename Real>
00171 bool m3x3<Real>::operator == (const m3x3<Real>& a){
00172         for(char i=0; i<9; i++)
00173                 if(m9[i] != a(i))
00174                         return false;
00175         return true;
00176 }
00177 
00178 template<typename Real>
00179 bool m3x3<Real>::operator != (const m3x3<Real>& a){
00180         for(char i=0; i<9; i++)
00181                 if(m9[i] != a(i))
00182                         return true;
00183         return false;
00184 }
00185 
00186 template<typename Real>
00187 Real* m3x3<Real>::operator [] (const unsigned char i){
00188         assert(i<3);
00189         return m[i];
00190 }
00191 
00192 template<typename Real>
00193 const Real* m3x3<Real>::operator [] (const unsigned char i) const{
00194         assert(i<3);
00195         return m[i];
00196 }
00197 
00198 template<typename Real>
00199 Real& m3x3<Real>::operator () (const unsigned char i){
00200         assert(i<9);
00201         return m9[i];
00202 }
00203 
00204 template<typename Real>
00205 const Real m3x3<Real>::operator () (const unsigned char i) const{
00206         assert(i<9);
00207         return m9[i];
00208 }
00209 
00210 template<typename Real>
00211 Real& m3x3<Real>::operator () (const unsigned char i, const unsigned char j){
00212         assert(i<3);
00213         assert(j<3);
00214         return m[i][j];
00215 }
00216 
00217 template<typename Real>
00218 const Real m3x3<Real>::operator () (const unsigned char i, const unsigned char j) const{
00219         assert(i<3);
00220         assert(j<3);
00221         return m[i][j];
00222 }
00223 
00224 // ==================================================
00225 // FUNCTIONS
00226 // ==================================================
00227 
00228 template<typename Real>
00229 m3x3<Real> Identity3x3(){
00230         return m3x3<Real>(1.0f,0.0f,0.0f,
00231                                 0.0f,1.0f,0.0f,
00232                                 0.0f,0.0f,1.0f);
00233 }
00234 
00235 template<typename Real>
00236 m3x3<Real> Zero3x3(){
00237         return m3x3<Real>(
00238                 0.0f,0.0f,0.0f,
00239                 0.0f,0.0f,0.0f,
00240                 0.0f,0.0f,0.0f);
00241 }
00242 
00243 template<typename Real>
00244 m3x3<Real> transpose(const m3x3<Real> m){
00245         return m3x3<Real>(m(0,0),m(1,0),m(2,0),
00246                                 m(0,1),m(1,1),m(2,1),
00247                                 m(0,2),m(1,2),m(2,2));
00248 }
00249 
00250 template<typename Real>
00251 m3x3<Real> inverse(const m3x3<Real> m){
00252         const Real _00 = m(1,1)*m(2,2) - m(1,2)*m(2,1);
00253         const Real _10 = m(1,2)*m(2,0) - m(1,0)*m(2,2);
00254         const Real _20 = m(1,0)*m(2,1) - m(1,1)*m(2,0);
00255 
00256         const Real det = m(0,0)*_00 + m(0,1)*_10 + m(0,2)*_20;
00257         if(det < 0.001f && det > -0.001f)
00258                 return m3x3<Real>(1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f);
00259         const Real invDet = 1.0f/det;
00260 
00261         return m3x3<Real>(
00262                 _00*invDet,
00263                 (m(0,2)*m(2,1) - m(0,1)*m(2,2)) * invDet,
00264                 (m(0,1)*m(1,2) - m(0,2)*m(1,1)) * invDet,
00265                 _10*invDet,
00266                 (m(0,0)*m(2,2) - m(0,2)*m(2,0)) * invDet,
00267                 (m(0,2)*m(1,0) - m(0,0)*m(1,2)) * invDet,
00268                 _20*invDet,
00269                 (m(0,1)*m(2,0) - m(0,0)*m(2,1)) * invDet,
00270                 (m(0,0)*m(1,1) - m(0,1)*m(1,0)) * invDet);
00271 }
00272 
00273 template<typename Real>
00274 m3x3<Real> add(const m3x3<Real>& a, const m3x3<Real>& b){
00275         return m3x3<Real>(
00276                 a(0,0)+b(0,0), a(0,1)+b(0,1), a(0,2)+b(0,2),
00277                 a(1,0)+b(1,0), a(1,1)+b(1,1), a(1,2)+b(1,2),
00278                 a(2,0)+b(2,0), a(2,1)+b(2,1), a(2,2)+b(2,2));
00279 }
00280 
00281 template<typename Real>
00282 m3x3<Real> sub(const m3x3<Real>& a, const m3x3<Real>& b){
00283         return REAL::MATH::m3x3<Real>(
00284                 a(0,0)-b(0,0), a(0,1)-b(0,1), a(0,2)-b(0,2),
00285                 a(1,0)-b(1,0), a(1,1)-b(1,1), a(1,2)-b(1,2),
00286                 a(2,0)-b(2,0), a(2,1)-b(2,1), a(2,2)-b(2,2));
00287 }
00288 
00289 template<typename Real>
00290 m3x3<Real> mul(const m3x3<Real>& a, const m3x3<Real>& b){
00291         return m3x3<Real>(
00292                 a(0,0)*b(0,0) + a(0,1)*b(1,0) + a(0,2)*b(2,0),
00293                 a(0,0)*b(0,1) + a(0,1)*b(1,1) + a(0,2)*b(2,1),
00294                 a(0,0)*b(0,2) + a(0,1)*b(1,2) + a(0,2)*b(2,2),
00295                 a(1,0)*b(0,0) + a(1,1)*b(1,0) + a(1,2)*b(2,0),
00296                 a(1,0)*b(0,1) + a(1,1)*b(1,1) + a(1,2)*b(2,1),
00297                 a(1,0)*b(0,2) + a(1,1)*b(1,2) + a(1,2)*b(2,2),
00298                 a(2,0)*b(0,0) + a(2,1)*b(1,0) + a(2,2)*b(2,0),
00299                 a(2,0)*b(0,1) + a(2,1)*b(1,1) + a(2,2)*b(2,1),
00300                 a(2,0)*b(0,2) + a(2,1)*b(1,2) + a(2,2)*b(2,2));
00301 }
00302 
00303 template<typename Real>
00304 v3<Real> mul(const v3<Real>& v, const m3x3<Real>& m){
00305         return v3<Real>(
00306                 v.x*m(0,0) + v.y*m(1,0) + v.z*m(2,0),
00307                 v.x*m(0,1) + v.y*m(1,1) + v.z*m(2,1),
00308                 v.x*m(0,2) + v.y*m(1,2) + v.z*m(2,2));
00309 }
00310 
00311 template<typename Real>
00312 v3<Real> mul(const m3x3<Real>& m, const v3<Real>& v){
00313         return mul(v,m);
00314 }
00315 
00316 // ==================================================
00317 // OPERATORS
00318 // ==================================================
00319 
00320 template<typename Real>
00321 v3<Real> operator * (const v3<Real>& v, const m3x3<Real>& m){
00322         return mul(v,m);
00323 }
00324 
00325 template<typename Real>
00326 v3<Real> operator * (const m3x3<Real>& m, const v3<Real>& v){
00327         return mul(v,m);
00328 }
00329 
00330 template<typename Real>
00331 m3x3<Real> operator * (const m3x3<Real>& a, const m3x3<Real>& b){
00332         return mul(a,b);
00333 }
00334 
00335 template<typename Real>
00336 m3x3<Real> operator + (const m3x3<Real>& a, const m3x3<Real>& b){
00337         return add(a,b);
00338 }
00339 
00340 template<typename Real>
00341 m3x3<Real> operator - (const m3x3<Real>& a, const m3x3<Real>& b){
00342         return sub(a,b);
00343 }

Generated on Fri Jun 18 2010 17:48:40 for Cannonball by  doxygen 1.7.0