00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef FGMATRIX_H
00039 #define FGMATRIX_H
00040
00041 #ifdef FG_NAMESPACE
00042 namespace fgl {
00043 #endif
00044
00045
00046 #ifdef __BORLANDC__
00047 #pragma option push -b
00048 #pragma option push -a4
00049 #endif
00050
00051 class FGMatrix
00052 {
00053 public:
00054 FGMatrix();
00055 FGMatrix(const FGMatrix& old) { memcpy(this, &old, sizeof(*this)); }
00056 FGMatrix( double m11, double m12, double m21, double m22,
00057 double dx, double dy );
00058
00059 void setMatrix( double m11, double m12, double m21, double m22,
00060 double dx, double dy );
00061
00062 double m11() const { return _m11; }
00063 double m12() const { return _m12; }
00064 double m21() const { return _m21; }
00065 double m22() const { return _m22; }
00066 double dx() const { return _dx; }
00067 double dy() const { return _dy; }
00068
00069 void map( int x, int y, int *tx, int *ty ) const;
00070 void map( double x, double y, double *tx, double *ty ) const;
00071 FGRect mapRect( const FGRect & ) const;
00072
00073 FGPoint map( const FGPoint &p ) const { return operator *( p ); }
00074 FGCircle map( const FGCircle &c ) const { return operator *( c ); }
00075 FGSize map( const FGSize &sz ) const { return operator *( sz ); }
00076 FGRect map( const FGRect &r ) const { return mapRect ( r ); }
00077 FGPointArray map( const FGPointArray &a ) const { return operator * ( a ); }
00078 void map(FGPointArray& src, FGPointArray& dst);
00079 void reset();
00080 bool isIdentity() const;
00081
00082 FGMatrix &translate( double dx, double dy );
00083 FGMatrix &scale( double sx, double sy );
00084 FGMatrix &shear( double sh, double sv );
00085 FGMatrix &rotate( double a );
00086
00087 void shift_x(double x) { _dx += x; }
00088 void shift_y(double y) { _dy += y; }
00089 void SetDxDy(double dx, double dy) { _dx = dx; _dy = dy; }
00090 void zoom(double val) { _m11 *= val; _m22 *= val; }
00091
00092 FGMatrix &FGMatrix::scale_with_center( double sx, double sy, double center_x, double center_y)
00093 {
00094 scale(sx, sy);
00095 _dx = center_x + ((_dx - center_x) * sx);
00096 _dy = center_y + ((_dy - center_y) * sy);
00097
00098 return *this;
00099
00100 }
00101
00102 bool isInvertible() const { return (_m11*_m22 - _m12*_m21) != 0; }
00103 double det() const { return _m11*_m22 - _m12*_m21; }
00104
00105 FGMatrix invert( bool * = 0 ) const;
00106
00107 bool operator==( const FGMatrix & ) const;
00108 bool operator!=( const FGMatrix & ) const;
00109 FGMatrix &operator*=( const FGMatrix & );
00110
00111
00112 FGCircle operator * (const FGCircle & ) const;
00113 FGPoint operator * (const FGPoint & ) const;
00114 FGSize operator * (const FGSize & ) const;
00115 FGPointArray operator * ( const FGPointArray &a ) const;
00116
00117 enum TransformationMode { Points, Areas };
00118
00119 static void setTransformationMode( FGMatrix::TransformationMode m );
00120 static TransformationMode transformationMode();
00121
00122 private:
00123 double _m11, _m12;
00124 double _m21, _m22;
00125 double _dx, _dy;
00126
00127 struct FGDoublePoint
00128 {
00129 double x,y;
00130 };
00131 };
00132
00133 #ifdef __BORLANDC__
00134 #pragma option pop
00135 #pragma option pop
00136 #endif
00137
00138 #ifdef FG_NAMESPACE
00139 }
00140 #endif
00141
00142 #endif // FGMATRIX_H