00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_TRANSFORM_H__
00021 #define __CS_TRANSFORM_H__
00022
00023 #include "csgeom/matrix3.h"
00024 #include "csgeom/plane3.h"
00025 #include "csgeom/sphere.h"
00026
00027 class csReversibleTransform;
00028
00035 class csTransform
00036 {
00037 protected:
00039 csMatrix3 m_o2t;
00041 csVector3 v_o2t;
00042
00043 public:
00047 csTransform () : m_o2t (), v_o2t (0, 0, 0) {}
00048
00056 csTransform (const csMatrix3& other2this, const csVector3& origin_pos) :
00057 m_o2t (other2this), v_o2t (origin_pos) {}
00058
00063 inline const csMatrix3& GetO2T () const { return m_o2t; }
00064
00069 inline const csVector3& GetO2TTranslation () const { return v_o2t; }
00070
00074 inline const csVector3& GetOrigin () const { return v_o2t; }
00075
00080 virtual void SetO2T (const csMatrix3& m) { m_o2t = m; }
00081
00086 virtual void SetO2TTranslation (const csVector3& v) { v_o2t = v; }
00087
00091 inline void SetOrigin (const csVector3& v) { SetO2TTranslation (v); }
00092
00096 inline void Translate (const csVector3& v) { SetO2TTranslation (v_o2t + v); }
00097
00102 inline csVector3 Other2This (const csVector3& v) const
00103 {
00104 return m_o2t * (v - v_o2t);
00105 }
00106
00111 csVector3 Other2ThisRelative (const csVector3& v) const
00112 { return m_o2t * v; }
00113
00117 csPlane3 Other2This (const csPlane3& p) const;
00118
00123 csPlane3 Other2ThisRelative (const csPlane3& p) const;
00124
00130 void Other2This (const csPlane3& p, const csVector3& point,
00131 csPlane3& result) const;
00132
00136 csSphere Other2This (const csSphere& s) const;
00137
00141 friend csVector3 operator* (const csVector3& v, const csTransform& t);
00142
00144 friend csVector3 operator* (const csTransform& t, const csVector3& v);
00146 friend csVector3& operator*= (csVector3& v, const csTransform& t);
00148 friend csPlane3 operator* (const csPlane3& p, const csTransform& t);
00150 friend csPlane3 operator* (const csTransform& t, const csPlane3& p);
00152 friend csPlane3& operator*= (csPlane3& p, const csTransform& t);
00154 friend csSphere operator* (const csSphere& p, const csTransform& t);
00156 friend csSphere operator* (const csTransform& t, const csSphere& p);
00158 friend csSphere& operator*= (csSphere& p, const csTransform& t);
00160 friend csMatrix3 operator* (const csMatrix3& m, const csTransform& t);
00162 friend csMatrix3 operator* (const csTransform& t, const csMatrix3& m);
00164 friend csMatrix3& operator*= (csMatrix3& m, const csTransform& t);
00166 friend csTransform operator* (const csTransform& t1,
00167 const csReversibleTransform& t2);
00168
00174 static csTransform GetReflect (const csPlane3& pl);
00175 };
00176
00184 class csReversibleTransform : public csTransform
00185 {
00186 protected:
00188 csMatrix3 m_t2o;
00189
00193 csReversibleTransform (const csMatrix3& o2t, const csMatrix3& t2o,
00194 const csVector3& pos) : csTransform (o2t,pos), m_t2o (t2o) {}
00195
00196 public:
00200 csReversibleTransform () : csTransform (), m_t2o () {}
00201
00209 csReversibleTransform (const csMatrix3& o2t, const csVector3& pos) :
00210 csTransform (o2t,pos) { m_t2o = m_o2t.GetInverse (); }
00211
00215 csReversibleTransform (const csTransform& t) :
00216 csTransform (t) { m_t2o = m_o2t.GetInverse (); }
00217
00218 csReversibleTransform (const csReversibleTransform& t) :
00219 csTransform (t) { m_t2o = t.m_t2o; }
00220
00224 inline const csMatrix3& GetT2O () const { return m_t2o; }
00225
00229 inline csVector3 GetT2OTranslation () const { return -m_o2t*v_o2t; }
00230
00234 csReversibleTransform GetInverse () const
00235 { return csReversibleTransform (m_t2o, m_o2t, -m_o2t*v_o2t); }
00236
00240 virtual void SetO2T (const csMatrix3& m)
00241 { m_o2t = m; m_t2o = m_o2t.GetInverse (); }
00242
00246 virtual void SetT2O (const csMatrix3& m)
00247 { m_t2o = m; m_o2t = m_t2o.GetInverse (); }
00248
00253 csVector3 This2Other (const csVector3& v) const
00254 { return v_o2t + m_t2o * v; }
00255
00260 inline csVector3 This2OtherRelative (const csVector3& v) const
00261 { return m_t2o * v; }
00262
00266 csPlane3 This2Other (const csPlane3& p) const;
00267
00272 csPlane3 This2OtherRelative (const csPlane3& p) const;
00273
00279 void This2Other (const csPlane3& p, const csVector3& point,
00280 csPlane3& result) const;
00281
00285 csSphere This2Other (const csSphere& s) const;
00286
00292 void RotateOther (const csVector3& v, float angle);
00293
00299 void RotateThis (const csVector3& v, float angle);
00300
00306 void RotateOther (const csMatrix3& m) { SetT2O (m * m_t2o); }
00307
00313 void RotateThis (const csMatrix3& m) { SetT2O (m_t2o * m); }
00314
00320 void LookAt (const csVector3& v, const csVector3& up);
00321
00323 friend csVector3 operator/ (const csVector3& v, const csReversibleTransform& t);
00325 friend csVector3& operator/= (csVector3& v, const csReversibleTransform& t);
00327 friend csPlane3 operator/ (const csPlane3& p, const csReversibleTransform& t);
00329 friend csPlane3& operator/= (csPlane3& p, const csReversibleTransform& t);
00331 friend csSphere operator/ (const csSphere& p, const csReversibleTransform& t);
00333 friend csReversibleTransform& operator*= (csReversibleTransform& t1,
00334 const csReversibleTransform& t2);
00336 friend csReversibleTransform operator* (const csReversibleTransform& t1,
00337 const csReversibleTransform& t2);
00339 friend csTransform operator* (const csTransform& t1,
00340 const csReversibleTransform& t2);
00342 friend csReversibleTransform& operator/= (csReversibleTransform& t1,
00343 const csReversibleTransform& t2);
00345 friend csReversibleTransform operator/ (const csReversibleTransform& t1,
00346 const csReversibleTransform& t2);
00347 };
00348
00355 class csOrthoTransform : public csReversibleTransform
00356 {
00357 public:
00361 csOrthoTransform () : csReversibleTransform () {}
00362
00366 csOrthoTransform (const csMatrix3& o2t, const csVector3& pos) :
00367 csReversibleTransform (o2t, o2t.GetTranspose (), pos) { }
00368
00372 csOrthoTransform (const csTransform& t) :
00373 csReversibleTransform (t.GetO2T (), t.GetO2T ().GetTranspose (), t.GetO2TTranslation ()) { }
00374
00378 virtual void SetO2T (const csMatrix3& m)
00379 { m_o2t = m; m_t2o = m_o2t.GetTranspose (); }
00380
00384 virtual void SetT2O (const csMatrix3& m)
00385 { m_t2o = m; m_o2t = m_t2o.GetTranspose (); }
00386 };
00387
00388 #endif // __CS_TRANSFORM_H__