MatrixTypes.h

Go to the documentation of this file.
00001 
00011 #pragma once
00012 
00013 #include <math.h> // sqrt
00014 
00015 #include "Matrix.h"
00016 
00017 #ifndef mfloat
00018 #define mfloat double
00019 #endif
00020 
00021 typedef SymmetricMatrix<4,mfloat> SymmetricMatrix4x4;
00022 typedef Matrix<4,4,mfloat>        Matrix4x4;
00023 typedef Matrix<3,3,mfloat>        Matrix3x3;
00024 
00025 typedef Matrix<4,4,double>        Matrix4x4d;
00026 typedef Matrix<3,3,double>        Matrix3x3d;
00027 
00028 typedef ColVector<2,mfloat>       ColVector2;
00029 typedef ColVector<3,mfloat>       ColVector3;
00030 typedef ColVector<4,mfloat>       ColVector4;
00031 
00032 typedef ColVector<2,double>       ColVector2d;
00033 typedef ColVector<3,double>       ColVector3d;
00034 typedef ColVector<4,double>       ColVector4d;
00035 
00036 // -------------------------------------------------------------------
00037 // RgbColor: embodies a color.
00038   
00039 template < typename T >
00040 class RgbColor : public ColVector<3, T>
00041 {
00042 
00043     public:
00044         typedef ColVector< 3, T > parentType;
00045 
00046         RgbColor(parentType &p) { parentType::operator=(p); }
00047         void operator=(const parentType &p) { parentType::operator=(p); }
00048 
00049         RgbColor() {}
00050         RgbColor (T r_in, T g_in, T b_in)
00051         {
00052             array[0] = r_in;
00053             array[1] = g_in;
00054             array[2] = b_in;
00055         }
00056         T & r() { return array[0]; }
00057         T & g() { return array[1]; }
00058         T & b() { return array[2]; }
00059 
00060         T r() const { return array[0]; }
00061         T g() const { return array[1]; }
00062         T b() const { return array[2]; }
00063 
00064 };
00065 
00066 typedef RgbColor< float > RgbFloat;
00067 typedef RgbColor< double > RgbDouble;
00068 typedef RgbColor< unsigned char > RgbByte;
00069 
00070 // -------------------------------------------------------------------
00071 // RgbaColor: embodies a color.
00072   
00073 template < typename T >
00074 class RgbaColor : public ColVector<4, T>
00075 {
00076 
00077     public:
00078         typedef ColVector< 4, T > parentType;
00079 
00080         RgbaColor(parentType &p) { parentType::operator=(p); }
00081         void operator=(const parentType &p) { parentType::operator=(p); }
00082 
00083         RgbaColor() {}
00084         RgbaColor (T r_in, T g_in, T b_in, T a_in)
00085         {
00086             array[0] = r_in;
00087             array[1] = g_in;
00088             array[2] = b_in;
00089             array[3] = a_in;
00090         }
00091         T & r() { return array[0]; }
00092         T & g() { return array[1]; }
00093         T & b() { return array[2]; }
00094         T & a() { return array[3]; }
00095 
00096         T r() const { return array[0]; }
00097         T g() const { return array[1]; }
00098         T b() const { return array[2]; }
00099         T a() const { return array[3]; }
00100 };
00101 
00102 typedef RgbaColor< float > RgbaFloat;
00103 typedef RgbaColor< double > RgbaDouble;
00104 typedef RgbaColor< unsigned char > RgbaByte;
00105 
00106 // -------------------------------------------------------------------
00107 // Vertex: Vertices have a position, but no length. Among other
00108 // things, this class helps with normal calculations.
00109 
00110 class Vertex : public Matrix<1,3,double> 
00111 {
00112     public:
00113         typedef Matrix<1,3,mfloat> parentType;
00114 
00115         // constructors
00116         Vertex() {}
00117         Vertex (mfloat x, mfloat y, mfloat z);
00118         Vertex(parentType &p) { parentType::operator=(p); }
00119 
00120         // accessors
00121         bool operator==(const Vertex & v) const;
00122         ColVector3 getNonUnitLengthNormalWith(const Vertex &v2, const Vertex &v3) const;
00123         ColVector3 getUnitLengthNormalWith   (const Vertex &v2, const Vertex &v3) const;
00124 
00125         // mutators
00126         void operator=(const parentType &p) { parentType::operator=(p); }
00127 };
00128 
00129 typedef Vertex Vertex3d;
00130 
00131 
00132 
00133 // -------------------------------------------------------------------
00134 //                      inlined methods (Vertex)
00135 // -------------------------------------------------------------------
00136 
00137 inline Vertex::Vertex (mfloat x, mfloat y, mfloat z) { array[0] = x; array[1] = y; array[2] = z; }
00138 
00139 inline ColVector3 Vertex::getNonUnitLengthNormalWith(const Vertex &v2, const Vertex &v3) const
00140 {
00141         ColVector3 v21 = v2 - *this;
00142         ColVector3 v31 = v3 - *this;
00143 
00144         return (v21.crossProduct(v31));
00145 }
00146 
00147 inline ColVector3 Vertex::getUnitLengthNormalWith (const Vertex &v2, const Vertex &v3) const
00148 {
00149     ColVector3 rtn = getNonUnitLengthNormalWith (v2,v3);
00150     mfloat length = rtn.getLength();
00151     if (length == 0)
00152         throw LogicError("Vertex::getUnitLengthNormalWidth(): unable to get a normal vector, since the vector length is zero!");
00153     return (rtn / rtn.getLength());
00154 }
00155 
00156 inline bool Vertex::operator==(const Vertex & v) const
00157 {
00158     return ((parentType)*this == (parentType)v);
00159 }
00160 
00161 
00162 

Generated on Tue May 21 03:34:51 2002 for Archimedes by doxygen1.2.15