|
transfrm.h00001 /* 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 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 00070 inline const csVector3& GetO2TTranslation () const { return v_o2t; } 00071 00076 inline const csVector3& GetOrigin () const { return v_o2t; } 00077 00082 virtual void SetO2T (const csMatrix3& m) { m_o2t = m; } 00083 00089 virtual void SetO2TTranslation (const csVector3& v) { v_o2t = v; } 00090 00095 inline void SetOrigin (const csVector3& v) { SetO2TTranslation (v); } 00096 00102 inline void Translate (const csVector3& v) { SetO2TTranslation (v_o2t + v); } 00103 00109 inline csVector3 Other2This (const csVector3& v) const 00110 { 00111 return m_o2t * (v - v_o2t); 00112 } 00113 00119 csVector3 Other2ThisRelative (const csVector3& v) const 00120 { return m_o2t * v; } 00121 00127 csPlane3 Other2This (const csPlane3& p) const; 00128 00135 csPlane3 Other2ThisRelative (const csPlane3& p) const; 00136 00144 void Other2This (const csPlane3& p, const csVector3& point, 00145 csPlane3& result) const; 00146 00150 csSphere Other2This (const csSphere& s) const; 00151 00156 friend csVector3 operator* (const csVector3& v, const csTransform& t); 00157 00162 friend csVector3 operator* (const csTransform& t, const csVector3& v); 00163 00168 friend csVector3& operator*= (csVector3& v, const csTransform& t); 00169 00174 friend csPlane3 operator* (const csPlane3& p, const csTransform& t); 00175 00180 friend csPlane3 operator* (const csTransform& t, const csPlane3& p); 00181 00186 friend csPlane3& operator*= (csPlane3& p, const csTransform& t); 00187 00192 friend csSphere operator* (const csSphere& p, const csTransform& t); 00193 00198 friend csSphere operator* (const csTransform& t, const csSphere& p); 00199 00204 friend csSphere& operator*= (csSphere& p, const csTransform& t); 00205 00210 friend csMatrix3 operator* (const csMatrix3& m, const csTransform& t); 00211 00216 friend csMatrix3 operator* (const csTransform& t, const csMatrix3& m); 00217 00222 friend csMatrix3& operator*= (csMatrix3& m, const csTransform& t); 00223 00235 friend csTransform operator* (const csTransform& t1, 00236 const csReversibleTransform& t2); 00237 00243 static csTransform GetReflect (const csPlane3& pl); 00244 }; 00245 00253 class csReversibleTransform : public csTransform 00254 { 00255 protected: 00257 csMatrix3 m_t2o; 00258 00262 csReversibleTransform (const csMatrix3& o2t, const csMatrix3& t2o, 00263 const csVector3& pos) : csTransform (o2t,pos), m_t2o (t2o) {} 00264 00265 public: 00269 csReversibleTransform () : csTransform (), m_t2o () {} 00270 00278 csReversibleTransform (const csMatrix3& o2t, const csVector3& pos) : 00279 csTransform (o2t,pos) { m_t2o = m_o2t.GetInverse (); } 00280 00284 csReversibleTransform (const csTransform& t) : 00285 csTransform (t) { m_t2o = m_o2t.GetInverse (); } 00286 00290 csReversibleTransform (const csReversibleTransform& t) : 00291 csTransform (t) { m_t2o = t.m_t2o; } 00292 00297 inline const csMatrix3& GetT2O () const { return m_t2o; } 00298 00303 inline csVector3 GetT2OTranslation () const { return -m_o2t*v_o2t; } 00304 00308 csReversibleTransform GetInverse () const 00309 { return csReversibleTransform (m_t2o, m_o2t, -m_o2t*v_o2t); } 00310 00315 virtual void SetO2T (const csMatrix3& m) 00316 { m_o2t = m; m_t2o = m_o2t.GetInverse (); } 00317 00323 virtual void SetT2O (const csMatrix3& m) 00324 { m_t2o = m; m_o2t = m_t2o.GetInverse (); } 00325 00331 csVector3 This2Other (const csVector3& v) const 00332 { return v_o2t + m_t2o * v; } 00333 00339 inline csVector3 This2OtherRelative (const csVector3& v) const 00340 { return m_t2o * v; } 00341 00348 csPlane3 This2Other (const csPlane3& p) const; 00349 00356 csPlane3 This2OtherRelative (const csPlane3& p) const; 00357 00366 void This2Other (const csPlane3& p, const csVector3& point, 00367 csPlane3& result) const; 00368 00372 csSphere This2Other (const csSphere& s) const; 00373 00379 void RotateOther (const csVector3& v, float angle); 00380 00386 void RotateThis (const csVector3& v, float angle); 00387 00395 void RotateOther (const csMatrix3& m) { SetT2O (m * m_t2o); } 00396 00404 void RotateThis (const csMatrix3& m) { SetT2O (m_t2o * m); } 00405 00414 void LookAt (const csVector3& v, const csVector3& up); 00415 00420 friend csVector3 operator/ (const csVector3& v, 00421 const csReversibleTransform& t); 00422 00427 friend csVector3& operator/= (csVector3& v, const csReversibleTransform& t); 00428 00433 friend csPlane3 operator/ (const csPlane3& p, const csReversibleTransform& t); 00434 00439 friend csPlane3& operator/= (csPlane3& p, const csReversibleTransform& t); 00440 00445 friend csSphere operator/ (const csSphere& p, const csReversibleTransform& t); 00446 00459 friend csReversibleTransform& operator*= (csReversibleTransform& t1, 00460 const csReversibleTransform& t2) 00461 { 00462 t1.v_o2t = t2.m_t2o*t1.v_o2t; 00463 t1.v_o2t += t2.v_o2t; 00464 t1.m_o2t *= t2.m_o2t; 00465 t1.m_t2o *= t1.m_t2o; 00466 return t1; 00467 } 00468 00481 friend csReversibleTransform operator* (const csReversibleTransform& t1, 00482 const csReversibleTransform& t2) 00483 { 00484 return csReversibleTransform (t1.m_o2t*t2.m_o2t, t2.m_t2o*t1.m_t2o, 00485 t2.v_o2t + t2.m_t2o*t1.v_o2t); 00486 } 00487 00500 friend csTransform operator* (const csTransform& t1, 00501 const csReversibleTransform& t2); 00502 00515 friend csReversibleTransform& operator/= (csReversibleTransform& t1, 00516 const csReversibleTransform& t2); 00517 00530 friend csReversibleTransform operator/ (const csReversibleTransform& t1, 00531 const csReversibleTransform& t2); 00532 }; 00533 00540 class csOrthoTransform : public csReversibleTransform 00541 { 00542 public: 00546 csOrthoTransform () : csReversibleTransform () {} 00547 00551 csOrthoTransform (const csMatrix3& o2t, const csVector3& pos) : 00552 csReversibleTransform (o2t, o2t.GetTranspose (), pos) { } 00553 00557 csOrthoTransform (const csTransform& t) : 00558 csReversibleTransform (t.GetO2T (), t.GetO2T ().GetTranspose (), 00559 t.GetO2TTranslation ()) 00560 { } 00561 00566 virtual void SetO2T (const csMatrix3& m) 00567 { m_o2t = m; m_t2o = m_o2t.GetTranspose (); } 00568 00574 virtual void SetT2O (const csMatrix3& m) 00575 { m_t2o = m; m_o2t = m_t2o.GetTranspose (); } 00576 }; 00577 00578 #endif // __CS_TRANSFORM_H__ 00579 Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |