XdkWrl: transformator.h Source File

Home | Hierarchy | Members | Alphabetical | Related Pages

# transformator.h

Go to the documentation of this file.

    00001 #ifndef XDKWRL_TRANSFORMATOR_H
    00002 #define XDKWRL_TRANSFORMATOR_H
    00003
    00004 #include <iostream>
    00005 #include <deque>
    00006
    00007 namespace wrl
    00008 {
    00009   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    00010   // Interface of Transformator
    00011   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    00012   class Transformator
    00013   {
    00014   public:
    00015     Transformator();
    00016
    00017     void loadIdentity();
    00018     void translate(float x,float y,float z);
    00019     void rotate(float rad,float x,float y,float z);
    00020     void scale(float x,float y,float z);
    00021     void scale(float s);
    00022     void postMultMatrix(const float *m);
    00023     void preMultMatrix(const float *m);
    00024     void loadMatrix(const float* m);
    00025
    00026     inline operator const float*() const;
    00027     void getMatrix(float* m) const;
    00028     void transform(const float* src,float* dst) const;
    00029     Transformator inverseTranspose() const;
    00030
    00031     friend std::ostream& operator<<(std::ostream& s,
    00032                                     const wrl::Transformator& t);
    00033     inline float& element(unsigned short i,
    00034                           unsigned short j);
    00035     inline float element(unsigned short i,
    00036                          unsigned short j) const;
    00037
    00038     static inline Transformator translation(float x,float y,float z);
    00039     static inline Transformator rotation(float rad,float x,float y,float z);
    00040     static inline Transformator scaling(float x,float y,float z);
    00041     static inline Transformator scaling(float s);
    00042
    00043     friend bool operator==(const Transformator& t0,const Transformator& t1);
    00044     friend bool operator!=(const Transformator& t0,const Transformator& t1);
    00045     friend bool operator<(const Transformator& t0,const Transformator& t1);
    00046   private:
    00047     float m_[16];
    00048   };
    00049   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    00050   // Interface of TransformatorHierarchy
    00051   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    00052   class TransformatorHierarchy
    00053   {
    00054   public:
    00055     TransformatorHierarchy();
    00056     inline void push(const Transformator& t);
    00057     void pop();
    00058
    00059     inline void transform(const float* src,float* dst) const;
    00060     inline void transformByInverseTranspose(const float* src,
    00061                                             float* dst) const;
    00062
    00063     friend bool operator==(const TransformatorHierarchy& th0,
    00064                            const TransformatorHierarchy& th1);
    00065     friend bool operator!=(const TransformatorHierarchy& th0,
    00066                            const TransformatorHierarchy& th1);
    00067     friend bool operator<(const TransformatorHierarchy& th0,
    00068                           const TransformatorHierarchy& th1);
    00069     friend std::ostream& operator<<(std::ostream& s,
    00070                                     const wrl::TransformatorHierarchy& t);
    00071   private:
    00072     std::deque<Transformator> t_;
    00073     Transformator             result_;
    00074     Transformator             invTransResult_;
    00075   };
    00076 }
    00077 //***************************************************************
    00078 // Implementation of Transformator
    00079 //***************************************************************
    00080 /*!
    00081  * Returns the internal matrix. Convenient alternative to getMAtrix(),
    00082  * especially to work with postMultMatrix and preMultMatrix~:
    00083  \code
    00084  Transformator t;
    00085  // ....
    00086  Transformator t2;
    00087  // ...
    00088  t2.postMultMatrix(t1);  // valid code
    00089  \endcode
    00090 */
    00091 inline
    00092 wrl::Transformator::operator const float*() const
    00093 {
    00094   return m_;
    00095 }
    00096 /*!
    00097  * Return element on line \p i and colum \p j
    00098  * (numbered from 0 to 3).
    00099  */
    00100 inline float&
    00101 wrl::Transformator::element(unsigned short i,
    00102                             unsigned short j)
    00103 {
    00104   return m_[i*4+j];
    00105 }
    00106 /*!
    00107  * Return element on line \p i and colum \p j
    00108  * (numbered from 0 to 3).
    00109  */
    00110 inline float
    00111 wrl::Transformator::element(unsigned short i,
    00112                             unsigned short j) const
    00113 {
    00114   return m_[i*4+j];
    00115 }
    00116 /*!
    00117  * Returns a transformation object for translation.
    00118  */
    00119 inline wrl::Transformator
    00120 wrl::Transformator::translation(float x,float y,float z)
    00121 {
    00122   Transformator t;
    00123   t.translate(x,y,z);
    00124   return t;
    00125 }
    00126 /*!
    00127  * Returns a transformation object for rotation.
    00128  * Provided for convenience.
    00129  */
    00130 inline wrl::Transformator
    00131 wrl::Transformator::rotation(float rad,float x,float y,float z)
    00132 {
    00133   Transformator t;
    00134   t.rotate(rad,x,y,z);
    00135   return t;
    00136 }
    00137 /*!
    00138  * Returns a transformation object for scaling.
    00139  * Provided for convenience.
    00140  */
    00141 inline wrl::Transformator
    00142 wrl::Transformator::scaling(float x,float y,float z)
    00143 {
    00144   Transformator t;
    00145   t.scale(x,y,z);
    00146   return t;
    00147 }
    00148 /*!
    00149  * Returns a transformation object for scaling.
    00150  * \overload
    00151  */
    00152 inline wrl::Transformator
    00153 wrl::Transformator::scaling(float s)
    00154 {
    00155   Transformator t;
    00156   t.scale(s);
    00157   return t;
    00158 }
    00159 //************************************************************
    00160 // Implementation of TransformatorHierarchy
    00161 //************************************************************
    00162 inline void
    00163 wrl::TransformatorHierarchy::push(const wrl::Transformator& t)
    00164 {
    00165   t_.push_back(t);
    00166   result_.postMultMatrix(t);
    00167   invTransResult_ = result_.inverseTranspose();
    00168 }
    00169 /*!
    00170  * Apply the sequence of Transformator pushed in the hierarchy by applying
    00171  * it in reverse order, that is last pushed first. The src and dst vectors
    00172  * can be the same (temporary values are used).
    00173  */
    00174 inline void
    00175 wrl::TransformatorHierarchy::transform(const float* src,float* dst) const
    00176 {
    00177   result_.transform(src,dst);
    00178 }
    00179 /*!
    00180  * Apply the sequence of Transformator pushed in the hierarchy by applying
    00181  * it in reverse order, that is last pushed first. Inverse transpose are
    00182  * used. This function should be used
    00183  * when transforming normals.
    00184  */
    00185 inline void
    00186 wrl::TransformatorHierarchy::transformByInverseTranspose(const float* src,
    00187                                                          float* dst) const
    00188 {
    00189   invTransResult_.transform(src,dst);
    00190 }
    00191 #endif //XDKWRL_TRANSFORMATOR_H
    00192
    00193 // Local variables section.
    00194 // This is only used by emacs!
    00195 // Local Variables:
    00196 // ff-search-directories: ("." "../../../src/xdkwrl/tools/")
    00197 // End:

Generated on 28 Jun 2006 with version 1.4.4. |