00001 #ifndef XDKWRL_TRANSFORMATOR_H
00002 #define XDKWRL_TRANSFORMATOR_H
00003
00004 #include <iostream>
00005 #include <deque>
00006
00007 namespace wrl
00008 {
00009
00010
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(const unsigned short i,
00034 const unsigned short j);
00035 inline float element(const unsigned short i,
00036 const 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
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
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 inline
00092 wrl::Transformator::operator const float*() const
00093 {
00094 return m_;
00095 }
00096
00097
00098
00099
00100 inline float&
00101 wrl::Transformator::element(const unsigned short i,
00102 const unsigned short j)
00103 {
00104 return m_[i*4+j];
00105 }
00106
00107
00108
00109
00110 inline float
00111 wrl::Transformator::element(const unsigned short i,
00112 const unsigned short j) const
00113 {
00114 return m_[i*4+j];
00115 }
00116
00117
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
00128
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
00139
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
00150
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
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
00171
00172
00173
00174 inline void
00175 wrl::TransformatorHierarchy::transform(const float* src,float* dst) const
00176 {
00177 result_.transform(src,dst);
00178 }
00179
00180
00181
00182
00183
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
00194
00195
00196
00197