CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csgeom/transfrm.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 1998-2001 by Jorrit Tyberghein
00003     Largely rewritten by Ivan Avramovic <ivan@avramovic.com>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_TRANSFORM_H__
00021 #define __CS_TRANSFORM_H__
00022 
00029 #include "csextern.h"
00030 
00031 #include "csgeom/matrix3.h"
00032 #include "csgeom/plane3.h"
00033 #include "csgeom/sphere.h"
00034 
00035 class csReversibleTransform;
00036 
00043 class CS_CSGEOM_EXPORT csTransform
00044 {
00045 protected:
00047   csMatrix3 m_o2t;
00049   csVector3 v_o2t;
00050 
00051 public:
00055   csTransform () : m_o2t (), v_o2t (0, 0, 0) {}
00056 
00064   csTransform (const csMatrix3& other2this, const csVector3& origin_pos) :
00065         m_o2t (other2this), v_o2t (origin_pos) {}
00066 
00070   void Identity ()
00071   {
00072     SetO2TTranslation (csVector3 (0));
00073     SetO2T (csMatrix3 ());
00074   }
00075 
00080   bool IsIdentity () const
00081   {
00082     if (ABS (v_o2t.x) >= SMALL_EPSILON) return false;
00083     if (ABS (v_o2t.y) >= SMALL_EPSILON) return false;
00084     if (ABS (v_o2t.z) >= SMALL_EPSILON) return false;
00085     if (ABS (m_o2t.m11-1) >= SMALL_EPSILON) return false;
00086     if (ABS (m_o2t.m12) >= SMALL_EPSILON) return false;
00087     if (ABS (m_o2t.m13) >= SMALL_EPSILON) return false;
00088     if (ABS (m_o2t.m21) >= SMALL_EPSILON) return false;
00089     if (ABS (m_o2t.m22-1) >= SMALL_EPSILON) return false;
00090     if (ABS (m_o2t.m23) >= SMALL_EPSILON) return false;
00091     if (ABS (m_o2t.m31) >= SMALL_EPSILON) return false;
00092     if (ABS (m_o2t.m32) >= SMALL_EPSILON) return false;
00093     if (ABS (m_o2t.m33-1) >= SMALL_EPSILON) return false;
00094     return true;
00095   }
00096 
00101   inline const csMatrix3& GetO2T () const { return m_o2t; }
00102 
00108   inline const csVector3& GetO2TTranslation () const { return v_o2t; }
00109 
00114   inline const csVector3& GetOrigin () const { return v_o2t; }
00115 
00120   virtual void SetO2T (const csMatrix3& m) { m_o2t = m; }
00121 
00127   virtual void SetO2TTranslation (const csVector3& v) { v_o2t = v; }
00128 
00133   inline void SetOrigin (const csVector3& v) { SetO2TTranslation (v); }
00134 
00140   inline void Translate (const csVector3& v) { SetO2TTranslation (v_o2t + v); }
00141 
00147   inline csVector3 Other2This (const csVector3& v) const
00148   {
00149     return m_o2t * (v - v_o2t);
00150   }
00151 
00157   csVector3 Other2ThisRelative (const csVector3& v) const
00158   { return m_o2t * v; }
00159 
00165   csPlane3 Other2This (const csPlane3& p) const;
00166 
00173   csPlane3 Other2ThisRelative (const csPlane3& p) const;
00174 
00182   void Other2This (const csPlane3& p, const csVector3& point,
00183         csPlane3& result) const;
00184 
00188   csSphere Other2This (const csSphere& s) const;
00189 
00194   friend CS_CSGEOM_EXPORT csVector3 operator* (const csVector3& v, 
00195     const csTransform& t);
00196 
00201   friend CS_CSGEOM_EXPORT csVector3 operator* (const csTransform& t, 
00202     const csVector3& v);
00203 
00208   friend CS_CSGEOM_EXPORT csVector3& operator*= (csVector3& v, 
00209     const csTransform& t);
00210 
00215   friend CS_CSGEOM_EXPORT csPlane3 operator* (const csPlane3& p, 
00216     const csTransform& t);
00217 
00222   friend CS_CSGEOM_EXPORT csPlane3 operator* (const csTransform& t, 
00223     const csPlane3& p);
00224 
00229   friend CS_CSGEOM_EXPORT csPlane3& operator*= (csPlane3& p, 
00230     const csTransform& t);
00231 
00236   friend CS_CSGEOM_EXPORT csSphere operator* (const csSphere& p, 
00237     const csTransform& t);
00238 
00243   friend CS_CSGEOM_EXPORT csSphere operator* (const csTransform& t, 
00244     const csSphere& p);
00245 
00250   friend CS_CSGEOM_EXPORT csSphere& operator*= (csSphere& p, 
00251     const csTransform& t);
00252 
00257   friend CS_CSGEOM_EXPORT csMatrix3 operator* (const csMatrix3& m, 
00258     const csTransform& t);
00259 
00264   friend CS_CSGEOM_EXPORT csMatrix3 operator* (const csTransform& t, 
00265     const csMatrix3& m);
00266 
00271   friend CS_CSGEOM_EXPORT csMatrix3& operator*= (csMatrix3& m, 
00272     const csTransform& t);
00273 
00285   friend CS_CSGEOM_EXPORT csTransform operator* (const csTransform& t1,
00286                               const csReversibleTransform& t2);
00287 
00293   static csTransform GetReflect (const csPlane3& pl);
00294 };
00295 
00303 class CS_CSGEOM_EXPORT csReversibleTransform : public csTransform
00304 {
00305 protected:
00307   csMatrix3 m_t2o;
00308 
00312   csReversibleTransform (const csMatrix3& o2t, const csMatrix3& t2o,
00313     const csVector3& pos) : csTransform (o2t,pos), m_t2o (t2o) {}
00314 
00315 public:
00319   csReversibleTransform () : csTransform (), m_t2o () {}
00320 
00328   csReversibleTransform (const csMatrix3& o2t, const csVector3& pos) :
00329     csTransform (o2t,pos) { m_t2o = m_o2t.GetInverse (); }
00330 
00334   csReversibleTransform (const csTransform& t) :
00335     csTransform (t) { m_t2o = m_o2t.GetInverse (); }
00336 
00340   csReversibleTransform (const csReversibleTransform& t) :
00341     csTransform (t) { m_t2o = t.m_t2o; }
00342 
00347   inline const csMatrix3& GetT2O () const { return m_t2o; }
00348 
00353   inline csVector3 GetT2OTranslation () const { return -m_o2t*v_o2t; }
00354 
00358   csReversibleTransform GetInverse () const
00359   { return csReversibleTransform (m_t2o, m_o2t, -m_o2t*v_o2t); }
00360 
00365   virtual void SetO2T (const csMatrix3& m)
00366   { m_o2t = m;  m_t2o = m_o2t.GetInverse (); }
00367 
00373   virtual void SetT2O (const csMatrix3& m)
00374   { m_t2o = m;  m_o2t = m_t2o.GetInverse (); }
00375 
00381   csVector3 This2Other (const csVector3& v) const
00382   { return v_o2t + m_t2o * v; }
00383 
00389   inline csVector3 This2OtherRelative (const csVector3& v) const
00390   { return m_t2o * v; }
00391 
00398   csPlane3 This2Other (const csPlane3& p) const;
00399 
00406   csPlane3 This2OtherRelative (const csPlane3& p) const;
00407 
00416   void This2Other (const csPlane3& p, const csVector3& point,
00417         csPlane3& result) const;
00418 
00422   csSphere This2Other (const csSphere& s) const;
00423 
00429   void RotateOther (const csVector3& v, float angle);
00430 
00436   void RotateThis (const csVector3& v, float angle);
00437 
00445   void RotateOther (const csMatrix3& m) { SetT2O (m * m_t2o); }
00446 
00454   void RotateThis (const csMatrix3& m) { SetT2O (m_t2o * m); }
00455 
00464   void LookAt (const csVector3& v, const csVector3& up);
00465 
00470   friend CS_CSGEOM_EXPORT csVector3 operator/ (const csVector3& v,
00471         const csReversibleTransform& t);
00472 
00477   friend CS_CSGEOM_EXPORT csVector3& operator/= (csVector3& v, 
00478     const csReversibleTransform& t);
00479 
00484   friend CS_CSGEOM_EXPORT csPlane3 operator/ (const csPlane3& p, 
00485     const csReversibleTransform& t);
00486 
00491   friend CS_CSGEOM_EXPORT csPlane3& operator/= (csPlane3& p, 
00492     const csReversibleTransform& t);
00493 
00498   friend CS_CSGEOM_EXPORT csSphere operator/ (const csSphere& p, 
00499     const csReversibleTransform& t);
00500 
00513   friend csReversibleTransform& operator*= (csReversibleTransform& t1,
00514                                           const csReversibleTransform& t2)
00515   {
00516     t1.v_o2t = t2.m_t2o*t1.v_o2t;
00517     t1.v_o2t += t2.v_o2t;
00518     t1.m_o2t *= t2.m_o2t;
00519     t1.m_t2o *= t1.m_t2o;
00520     return t1;
00521   }
00522 
00535   friend csReversibleTransform operator* (const csReversibleTransform& t1,
00536                                         const csReversibleTransform& t2)
00537   {
00538     return csReversibleTransform (t1.m_o2t*t2.m_o2t, t2.m_t2o*t1.m_t2o,
00539                              t2.v_o2t + t2.m_t2o*t1.v_o2t);
00540   }
00541 
00554   friend CS_CSGEOM_EXPORT csTransform operator* (const csTransform& t1,
00555                               const csReversibleTransform& t2);
00556 
00569   friend CS_CSGEOM_EXPORT csReversibleTransform& operator/= (
00570     csReversibleTransform& t1, const csReversibleTransform& t2);
00571 
00584   friend CS_CSGEOM_EXPORT csReversibleTransform operator/ (
00585     const csReversibleTransform& t1, const csReversibleTransform& t2);
00586 };
00587 
00594 class csOrthoTransform : public csReversibleTransform
00595 {
00596 public:
00600   csOrthoTransform () : csReversibleTransform () {}
00601 
00605   csOrthoTransform (const csMatrix3& o2t, const csVector3& pos) :
00606     csReversibleTransform (o2t, o2t.GetTranspose (), pos) { }
00607 
00611   csOrthoTransform (const csTransform& t) :
00612     csReversibleTransform (t.GetO2T (), t.GetO2T ().GetTranspose (),
00613         t.GetO2TTranslation ())
00614   { }
00615 
00620   virtual void SetO2T (const csMatrix3& m)
00621   { m_o2t = m;  m_t2o = m_o2t.GetTranspose (); }
00622 
00628   virtual void SetT2O (const csMatrix3& m)
00629   { m_t2o = m;  m_o2t = m_t2o.GetTranspose (); }
00630 };
00631 
00634 #endif // __CS_TRANSFORM_H__
00635 

Generated for Crystal Space by doxygen 1.2.18