00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef AMOD_MATH_LIB_INCTRANSF3D_H
00024 #define AMOD_MATH_LIB_INCTRANSF3D_H
00025 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00037 
00038 #include "point3d.H"
00039 #include "line3d.H"
00040 
00041 typedef Greal RAWmat[4][4];
00042 
00043 template <class T, class P, class V, class L, class Q>
00044 class _transf3d
00045 {
00046 protected:
00047     Greal _c[4][4];
00048     int    _perspective;
00049 
00050 public:
00051 
00052     
00053     
00054     inline _transf3d() {
00055        _c[0][1] = _c[0][2] = _c[0][3] = _c[1][0] = _c[1][2] = _c[1][3] = 
00056        _c[2][0] = _c[2][1] = _c[2][3] = _c[3][0] = _c[3][1] = _c[3][2] = 0.0;
00057        _c[0][0] = _c[1][1] = _c[2][2] = _c[3][3] = 1;
00058        
00059        _perspective = 0;
00060     }
00061 
00062     
00063     
00064     
00065     _transf3d(const P&  origin, 
00066               const V&    xDir, 
00067               const V&    yDir, 
00068               const V&    zDir);
00069 
00070     
00071     
00072     
00073     _transf3d(const V&    col0, 
00074               const V&    col1, 
00075               const V&    col2);
00076 
00077     
00078     
00079     
00080     
00081     _transf3d(const P&  origin, 
00082               const V&    xDir, 
00083               const V&    yDir);
00084 
00085     
00086     
00087     
00088     
00089     
00090     _transf3d(const L& axis);
00091 
00092     
00093     
00094     
00095     _transf3d(const P& origin);
00096 
00097     Greal& operator ()(int i1, int i2)       { return _c[i2][i1]; }
00098     Greal  operator ()(int i1, int i2) const { return _c[i2][i1]; }
00099 
00100     void    set_perspective(int p)  { _perspective = p;   }
00101     int     perspective()     const { return _perspective;}
00102 
00103     V        get_scale()const{return V(X().length(),Y().length(),Z().length());}
00104     void     getCoordSystem(P& o, V& x, V& y, V& z) const
00105                              { x = X(); y = Y(); z = Z(); o = origin(); }
00106 
00107     V        X()      const  { return V(_c[0][0],_c[0][1], _c[0][2]); }
00108     V        Y()      const  { return V(_c[1][0],_c[1][1], _c[1][2]); }
00109     V        Z()      const  { return V(_c[2][0],_c[2][1], _c[2][2]); }
00110     P        origin() const  { return P(_c[3][0],_c[3][1], _c[3][2]); }
00111     Greal  *matrix() const  { return (Greal *)_c; }
00112     void     vals(RAWmat &d, bool row=true) const 
00113                              { for (int i=0; i<4; i++)
00114                                   for (int j=0; j<4; j++)
00115                                      if (row)
00116                                           d[i][j] = _c[i][j];
00117                                      else d[j][i] = _c[i][j]; }
00118 
00119     
00120     T        rotation() const { return T(P(0,0,0), X(), Y(), Z()); }
00121     
00122     
00123     
00124     static T rotation   (const  Q& quat);
00125     static T rotation   (const  L& axis,    Greal   angle);
00126     static T rotation   (const  V& axis,    Greal   angle);
00127     static T shear      (const  V& normal,  const V& shearVec);
00128     static T scaling    (const  P& fixedPt, Greal   factor);
00129     static T scaling    (const  P& fixedPt, const V& xyzFactors);
00130     static T scaling    (const  V& xyzFactors);
00131     static T scaling    (Greal    factor);
00132     static T stretching (const  L& axis);
00133     static T translation(const  V&);
00134 
00135     
00136     
00137     
00138     
00139     
00140     
00141     static T align(const P& src1, const P& src2, const P& src3,
00142                    const P& dst1, const P& dst2, const P& dst3);
00143 
00144     
00145     
00146     
00147     
00148     
00149     
00150     static T align(const P&  src1, const V& src2, const V& src3,
00151                    const P&  dst1, const V& dst2, const V& dst3);
00152 
00153     static T align(const P&  src1, const V&    src2,
00154                    const P&  dst1, const V&    dst2);
00155 
00156     static T alignAndScale(const P& o, const V& x, const V& y, const V& z);
00157 
00158     T        transpose      ()          const;
00159     T        unscaled       ()          const;
00160     T        normalize_basis()          const;
00161     T        orthogonalize  ()          const;
00162     T        invert         ()          const;
00163     T        derivative(const P&)       const;
00164 
00165     bool     isValid                 () const;
00166     bool     isIdentity              () const;
00167     bool     isOrthogonal            () const;  
00168     bool     isEqualScalingOrthogonal() const;  
00169 
00170     int operator != (const T &m) const { return !(*this == m); }
00171     int operator == (const T &m) const {
00172        return origin() == m.origin() &&
00173               X()      == m.X() &&
00174               Y()      == m.Y() &&
00175               Z()      == m.Z();
00176     }
00177 
00178 }; 
00179 
00180 
00181 
00182 
00183 
00184 #define TPVLQ template <class T,class P,class V, class L, class Q>
00185 TPVLQ ostream &operator <<(ostream &os, const _transf3d<T,P,V,L,Q> &x); 
00186 TPVLQ istream &operator >>(istream &os,       _transf3d<T,P,V,L,Q> &x); 
00187 TPVLQ T operator *(const _transf3d<T,P,V,L,Q> &, const _transf3d<T,P,V,L,Q>&);
00188 TPVLQ P operator *(const _transf3d<T,P,V,L,Q> &, const _point3d<P,V> &);
00189 TPVLQ V operator *(const _transf3d<T,P,V,L,Q> &, const _vec3d<V> &);
00190 TPVLQ L operator *(const _transf3d<T,P,V,L,Q> &, const _line<L,P,V> &);
00191 #undef TPVLQ
00192 
00193 #ifdef GLUE_NEEDS_TEMPLATES_IN_H_FILE
00194 #include "transf3d.C"
00195 #endif
00196 
00197 #endif