00001 /********************************************************************** 00002 *< 00003 FILE: matrix2.h 00004 00005 DESCRIPTION: Class definitions for Matrix2 00006 00007 CREATED BY: Dan Silva 00008 00009 HISTORY: 00010 00011 *> Copyright (c) 1994, All Rights Reserved. 00012 **********************************************************************/ 00013 00014 #pragma once 00015 00016 #include "GeomExport.h" 00017 #include "maxheap.h" 00018 #include "ioapi.h" 00019 #include "point2.h" 00020 #include "point3.h" 00021 00022 #include <iosfwd> 00023 00032 class Matrix2: public MaxHeapOperators { 00033 Point2& operator[](int i) { return((Point2&)(*m[i])); } 00034 Point2& operator[](int i) const { return((Point2&)(*m[i])); } 00035 public: 00036 float m[3][2]; 00037 00038 // Constructors 00041 Matrix2(){} // NO INITIALIZATION done in this constructor!! (can use Zero or IdentityMatrix) 00042 Matrix2(BOOL init) { UNUSED_PARAM(init); IdentityMatrix(); } // An option to initialize 00043 00045 GEOMEXPORT Matrix2(float (*fp)[2]); 00046 00047 // Data member 00048 static const Matrix2 Identity; 00049 00050 // Assignment operators 00052 GEOMEXPORT Matrix2& operator-=( const Matrix2& M); 00054 GEOMEXPORT Matrix2& operator+=( const Matrix2& M); 00056 GEOMEXPORT Matrix2& operator*=( const Matrix2& M); // Matrix multiplication 00057 00058 // Conversion function 00060 operator float*() { return(&m[0][0]); } 00061 00062 // Initialize matrix 00064 GEOMEXPORT void IdentityMatrix(); // Set to the Identity Matrix 00066 GEOMEXPORT void Zero(); // Set all elements to 0 00067 00072 Point2 GetRow(int i) const { return (*this)[i]; } 00079 GEOMEXPORT void SetRow(int i, Point2 p) { (*this)[i] = p; } 00080 00085 GEOMEXPORT Point3 GetColumn(int i); 00092 GEOMEXPORT void SetColumn(int i, Point3 col); 00098 GEOMEXPORT Point2 GetColumn2(int i); 00099 00100 // Access the translation row 00106 void SetTrans(const Point2 p) { (*this)[2] = p; } 00114 void SetTrans(int i, float v) { (*this)[2][i] = v; } 00116 Point2 GetTrans() { return (*this)[2]; } 00117 00118 // Apply Incremental transformations to this matrix 00123 GEOMEXPORT void Translate(const Point2& p); 00129 GEOMEXPORT void Rotate(float angle); 00130 // if trans = FALSE the translation component is unaffected: 00150 GEOMEXPORT void Scale(const Point2& s, BOOL trans=FALSE); 00151 00152 // Apply Incremental transformations to this matrix 00153 // Equivalent to multiplying on the LEFT by transform 00154 GEOMEXPORT void PreTranslate(const Point2& p); 00155 GEOMEXPORT void PreRotate(float angle); 00156 GEOMEXPORT void PreScale(const Point2& s, BOOL trans = FALSE); 00157 00158 // Set matrix as described 00164 GEOMEXPORT void SetTranslate(const Point2& s); // makes translation matrix 00170 GEOMEXPORT void SetRotate(float angle); // makes rotation matrix 00172 GEOMEXPORT void Invert(); 00173 00174 // Binary operators 00176 GEOMEXPORT Matrix2 operator*(const Matrix2& B) const; 00178 GEOMEXPORT Matrix2 operator+(const Matrix2& B) const; 00181 GEOMEXPORT Matrix2 operator-(const Matrix2& B) const; 00182 00183 GEOMEXPORT IOResult Save(ISave* isave); 00184 GEOMEXPORT IOResult Load(ILoad* iload); 00185 00186 }; 00187 00188 // Build new matrices for transformations 00195 GEOMEXPORT Matrix2 RotateMatrix(float angle); 00202 GEOMEXPORT Matrix2 TransMatrix(const Point2& p); 00209 GEOMEXPORT Matrix2 ScaleMatrix(const Point2& s); 00210 00216 GEOMEXPORT Matrix2 Inverse(const Matrix2& M); 00217 00218 // Transform point with matrix: 00226 GEOMEXPORT Point2 operator*(const Matrix2& A, const Point2& V); 00234 GEOMEXPORT Point2 operator*( const Point2& V, const Matrix2& A); 00243 GEOMEXPORT Point2 VectorTransform(const Matrix2& M, const Point2& V); 00244 00245 // Printout 00246 GEOMEXPORT std::ostream &operator<<(std::ostream& s, const Matrix2& A); 00247