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
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
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
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 inline
00093 wrl::Transformator::operator const float*() const
00094 {
00095 return m_;
00096 }
00097
00098
00099
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
00109
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
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
00129
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
00140
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
00151
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
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
00172
00173
00174
00175 inline void
00176 wrl::TransformatorHierarchy::transform(const float* src,float* dst) const
00177 {
00178 result_.transform(src,dst);
00179 }
00180
00181
00182
00183
00184
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
00195
00196
00197
00198