Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
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 00032 #include "csgeom/matrix3.h" 00033 #include "csgeom/vector3.h" 00034 00035 class csPlane3; 00036 class csSphere; 00037 00038 class csReversibleTransform; 00039 00046 class CS_CRYSTALSPACE_EXPORT csTransform 00047 { 00048 protected: 00050 csMatrix3 m_o2t; 00052 csVector3 v_o2t; 00053 00054 public: 00055 // Needed for GCC4. Otherwise emits a flood of "virtual functions but 00056 // non-virtual destructor" warnings. 00057 virtual ~csTransform() {} 00061 csTransform () : m_o2t (), v_o2t (0, 0, 0) {} 00062 00070 csTransform (const csMatrix3& other2this, const csVector3& origin_pos) : 00071 m_o2t (other2this), v_o2t (origin_pos) {} 00072 00076 inline void Identity () 00077 { 00078 SetO2TTranslation (csVector3 (0)); 00079 SetO2T (csMatrix3 ()); 00080 } 00081 00086 inline bool IsIdentity () const 00087 { 00088 if (ABS (v_o2t.x) >= SMALL_EPSILON) return false; 00089 if (ABS (v_o2t.y) >= SMALL_EPSILON) return false; 00090 if (ABS (v_o2t.z) >= SMALL_EPSILON) return false; 00091 if (ABS (m_o2t.m11-1) >= SMALL_EPSILON) return false; 00092 if (ABS (m_o2t.m12) >= SMALL_EPSILON) return false; 00093 if (ABS (m_o2t.m13) >= SMALL_EPSILON) return false; 00094 if (ABS (m_o2t.m21) >= SMALL_EPSILON) return false; 00095 if (ABS (m_o2t.m22-1) >= SMALL_EPSILON) return false; 00096 if (ABS (m_o2t.m23) >= SMALL_EPSILON) return false; 00097 if (ABS (m_o2t.m31) >= SMALL_EPSILON) return false; 00098 if (ABS (m_o2t.m32) >= SMALL_EPSILON) return false; 00099 if (ABS (m_o2t.m33-1) >= SMALL_EPSILON) return false; 00100 return true; 00101 } 00102 00107 inline const csMatrix3& GetO2T () const { return m_o2t; } 00108 00114 inline const csVector3& GetO2TTranslation () const { return v_o2t; } 00115 00121 inline const csVector3& GetOrigin () const { return v_o2t; } 00122 00127 virtual void SetO2T (const csMatrix3& m) { m_o2t = m; } 00128 00134 virtual void SetO2TTranslation (const csVector3& v) { v_o2t = v; } 00135 00140 inline void SetOrigin (const csVector3& v) { SetO2TTranslation (v); } 00141 00147 inline void Translate (const csVector3& v) { SetO2TTranslation (v_o2t + v); } 00148 00154 inline csVector3 Other2This (const csVector3& v) const 00155 { 00156 return m_o2t * (v - v_o2t); 00157 } 00158 00164 inline csVector3 Other2ThisRelative (const csVector3& v) const 00165 { return m_o2t * v; } 00166 00172 csPlane3 Other2This (const csPlane3& p) const; 00173 00180 csPlane3 Other2ThisRelative (const csPlane3& p) const; 00181 00189 void Other2This (const csPlane3& p, const csVector3& point, 00190 csPlane3& result) const; 00191 00195 csSphere Other2This (const csSphere& s) const; 00196 00201 friend CS_CRYSTALSPACE_EXPORT csVector3 operator* (const csVector3& v, 00202 const csTransform& t); 00203 00208 friend CS_CRYSTALSPACE_EXPORT csVector3 operator* (const csTransform& t, 00209 const csVector3& v); 00210 00215 friend CS_CRYSTALSPACE_EXPORT csVector3& operator*= (csVector3& v, 00216 const csTransform& t); 00217 00222 friend CS_CRYSTALSPACE_EXPORT csPlane3 operator* (const csPlane3& p, 00223 const csTransform& t); 00224 00229 friend CS_CRYSTALSPACE_EXPORT csPlane3 operator* (const csTransform& t, 00230 const csPlane3& p); 00231 00236 friend CS_CRYSTALSPACE_EXPORT csPlane3& operator*= (csPlane3& p, 00237 const csTransform& t); 00238 00243 friend CS_CRYSTALSPACE_EXPORT csSphere operator* (const csSphere& p, 00244 const csTransform& t); 00245 00250 friend CS_CRYSTALSPACE_EXPORT csSphere operator* (const csTransform& t, 00251 const csSphere& p); 00252 00257 friend CS_CRYSTALSPACE_EXPORT csSphere& operator*= (csSphere& p, 00258 const csTransform& t); 00259 00264 friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator* (const csMatrix3& m, 00265 const csTransform& t); 00266 00271 friend CS_CRYSTALSPACE_EXPORT csMatrix3 operator* (const csTransform& t, 00272 const csMatrix3& m); 00273 00278 friend CS_CRYSTALSPACE_EXPORT csMatrix3& operator*= (csMatrix3& m, 00279 const csTransform& t); 00280 00292 friend CS_CRYSTALSPACE_EXPORT csTransform operator* (const csTransform& t1, 00293 const csReversibleTransform& t2); 00294 00300 static csTransform GetReflect (const csPlane3& pl); 00301 }; 00302 00314 class CS_CRYSTALSPACE_EXPORT csReversibleTransform : public csTransform 00315 { 00316 protected: 00318 csMatrix3 m_t2o; 00319 00323 csReversibleTransform (const csMatrix3& o2t, const csMatrix3& t2o, 00324 const csVector3& pos) : csTransform (o2t,pos), m_t2o (t2o) {} 00325 00326 public: 00330 csReversibleTransform () : csTransform (), m_t2o () {} 00331 00339 csReversibleTransform (const csMatrix3& o2t, const csVector3& pos) : 00340 csTransform (o2t,pos) { m_t2o = m_o2t.GetInverse (); } 00341 00345 csReversibleTransform (const csTransform& t) : 00346 csTransform (t) { m_t2o = m_o2t.GetInverse (); } 00347 00351 csReversibleTransform (const csReversibleTransform& t) : 00352 csTransform (t) { m_t2o = t.m_t2o; } 00353 00358 inline const csMatrix3& GetT2O () const { return m_t2o; } 00359 00364 inline csVector3 GetT2OTranslation () const { return -m_o2t*v_o2t; } 00365 00369 csReversibleTransform GetInverse () const 00370 { return csReversibleTransform (m_t2o, m_o2t, -m_o2t*v_o2t); } 00371 00376 virtual void SetO2T (const csMatrix3& m) 00377 { m_o2t = m; m_t2o = m_o2t.GetInverse (); } 00378 00384 virtual void SetT2O (const csMatrix3& m) 00385 { m_t2o = m; m_o2t = m_t2o.GetInverse (); } 00386 00392 inline csVector3 This2Other (const csVector3& v) const 00393 { return v_o2t + m_t2o * v; } 00394 00400 inline csVector3 This2OtherRelative (const csVector3& v) const 00401 { return m_t2o * v; } 00402 00409 csPlane3 This2Other (const csPlane3& p) const; 00410 00417 csPlane3 This2OtherRelative (const csPlane3& p) const; 00418 00427 void This2Other (const csPlane3& p, const csVector3& point, 00428 csPlane3& result) const; 00429 00433 csSphere This2Other (const csSphere& s) const; 00434 00440 void RotateOther (const csVector3& v, float angle); 00441 00447 void RotateThis (const csVector3& v, float angle); 00448 00456 void RotateOther (const csMatrix3& m) { SetT2O (m * m_t2o); } 00457 00465 void RotateThis (const csMatrix3& m) { SetT2O (m_t2o * m); } 00466 00475 void LookAt (const csVector3& v, const csVector3& up); 00476 00481 friend CS_CRYSTALSPACE_EXPORT csVector3 operator/ (const csVector3& v, 00482 const csReversibleTransform& t); 00483 00488 friend CS_CRYSTALSPACE_EXPORT csVector3& operator/= (csVector3& v, 00489 const csReversibleTransform& t); 00490 00495 friend CS_CRYSTALSPACE_EXPORT csPlane3 operator/ (const csPlane3& p, 00496 const csReversibleTransform& t); 00497 00502 friend CS_CRYSTALSPACE_EXPORT csPlane3& operator/= (csPlane3& p, 00503 const csReversibleTransform& t); 00504 00509 friend CS_CRYSTALSPACE_EXPORT csSphere operator/ (const csSphere& p, 00510 const csReversibleTransform& t); 00511 00524 friend csReversibleTransform& operator*= (csReversibleTransform& t1, 00525 const csReversibleTransform& t2) 00526 { 00527 t1.v_o2t = t2.m_t2o*t1.v_o2t; 00528 t1.v_o2t += t2.v_o2t; 00529 t1.m_o2t *= t2.m_o2t; 00530 t1.m_t2o *= t1.m_t2o; 00531 return t1; 00532 } 00533 00546 friend csReversibleTransform operator* (const csReversibleTransform& t1, 00547 const csReversibleTransform& t2) 00548 { 00549 return csReversibleTransform (t1.m_o2t*t2.m_o2t, t2.m_t2o*t1.m_t2o, 00550 t2.v_o2t + t2.m_t2o*t1.v_o2t); 00551 } 00552 00553 #if !defined(SWIG) /* Otherwise Swig 1.3.22 thinks this is multiply declared */ 00554 00566 friend CS_CRYSTALSPACE_EXPORT csTransform operator* (const csTransform& t1, 00567 const csReversibleTransform& t2); 00568 #endif 00569 00582 friend CS_CRYSTALSPACE_EXPORT csReversibleTransform& operator/= ( 00583 csReversibleTransform& t1, const csReversibleTransform& t2); 00584 00597 friend CS_CRYSTALSPACE_EXPORT csReversibleTransform operator/ ( 00598 const csReversibleTransform& t1, const csReversibleTransform& t2); 00599 }; 00600 00607 class csOrthoTransform : public csReversibleTransform 00608 { 00609 public: 00613 csOrthoTransform () : csReversibleTransform () {} 00614 00618 csOrthoTransform (const csMatrix3& o2t, const csVector3& pos) : 00619 csReversibleTransform (o2t, o2t.GetTranspose (), pos) { } 00620 00624 csOrthoTransform (const csTransform& t) : 00625 csReversibleTransform (t.GetO2T (), t.GetO2T ().GetTranspose (), 00626 t.GetO2TTranslation ()) 00627 { } 00628 00633 virtual void SetO2T (const csMatrix3& m) 00634 { m_o2t = m; m_t2o = m_o2t.GetTranspose (); } 00635 00641 virtual void SetT2O (const csMatrix3& m) 00642 { m_t2o = m; m_o2t = m_t2o.GetTranspose (); } 00643 }; 00644 00647 #endif // __CS_TRANSFORM_H__ 00648
Generated for Crystal Space by doxygen 1.4.4