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

Generated on 5 Jan 2007 with doxygen version 1.5.1. Valid HTML 4.0! Valid CSS!