00001 /************************************************************************/ 00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00003 /* 1993-2002, thereinafter the Software */ 00004 /* */ 00005 /* The Software has been developped within the Siames Project. */ 00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00007 /* property rights */ 00008 /* */ 00009 /* The Software has been registered with the Agence pour la Protection */ 00010 /* des Programmes (APP) under registration number */ 00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00012 /* */ 00013 /* This file may be distributed under the terms of the Q Public License */ 00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00015 /* the file LICENSE.QPL included in the packaging of this file. */ 00016 /* */ 00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00018 /* Universite Rennes 1 for the software may use this file in */ 00019 /* acordance with that specific license */ 00020 /************************************************************************/ 00021 #ifndef OMK_MATH_OMKTransform_H 00022 #define OMK_MATH_OMKTransform_H 00023 00024 #include "Wm4Matrix3.h" 00025 #include "Wm4Matrix4.h" 00026 #include "Wm4Plane3.h" 00027 #include "Wm4Quaternion.h" 00028 #include "OMKTracer.h" 00029 #include <iostream> 00030 00031 00032 00033 namespace OMK 00034 { 00035 class OutgoingSynchronisationMessage ; 00036 class IncomingSynchronisationMessage ; 00037 00038 namespace Type 00039 { 00040 class Transform ; 00041 } //namespace Type 00042 } //namespace OMK 00044 00045 00046 00047 OMK_API std::ostream& operator << ( std::ostream& out, const OMK::Type::Transform& q ); 00048 00051 OMK_API std::istream& operator >> ( std::istream& in, OMK::Type::Transform& q ) ; 00052 00055 OMK_API OMK::OutgoingSynchronisationMessage& operator << 00056 ( OMK::OutgoingSynchronisationMessage& out, const OMK::Type::Transform& q ) ; 00057 00060 OMK_API OMK::IncomingSynchronisationMessage& operator >> 00061 ( OMK::IncomingSynchronisationMessage& in, OMK::Type::Transform& q ) ; 00063 00064 namespace OMK 00065 { 00066 namespace Type 00067 { 00087 class OMK_API Transform 00088 { 00089 public: 00090 00092 00093 00094 00095 Transform() ; 00096 00098 Transform( const Wm4::Vector3f& translate, 00099 const Wm4::Matrix3f& rotate = Wm4::Matrix3f( 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f ), 00100 float scale = 1.0f ) ; 00101 00103 Transform( const Wm4::Vector3f& translate, 00104 const Wm4::Quaternionf& rotate, 00105 float scale = 1.0f ) ; 00106 00108 Transform( const Wm4::Vector3f& translate, 00109 const Wm4::Matrix3f& rotate, 00110 const Wm4::Vector3f& scale ) ; 00111 00113 Transform( const Wm4::Vector3f& translate, 00114 const Wm4::Quaternionf& rotate, 00115 const Wm4::Vector3f& scale ) ; 00116 00118 virtual ~Transform() ; 00120 00122 void resetToIdentity() { *this = sk_identity ; } 00123 00125 void resetUnitScale(); 00126 00132 00133 00134 00135 bool isIdentity() const ; 00136 00139 bool isUniformScale() const ; 00141 00143 00144 00145 00146 00147 void updateFlags() ; 00148 00155 void setTranslate( const Wm4::Vector3f& translate ); 00156 00164 void setRotate( const Wm4::Matrix3f& rotate ) ; 00165 00172 void setRotate( const Wm4::Quaternionf& rotate ) ; 00173 00182 void setScale( const Wm4::Vector3f& scale ) ; 00183 00192 void setUniformScale( float scale ) ; 00193 00199 const Wm4::Matrix3f& getRotate() const ; 00200 00206 Wm4::Quaternionf getQuaternionRotate() const ; 00207 00210 const Wm4::Vector3f& getTranslate() const ; 00211 00217 const Wm4::Vector3f& getScale() const ; 00218 00224 float getUniformScale() const ; 00225 00228 Wm4::Vector3f getRight() const ; 00229 00232 Wm4::Vector3f getUp() const ; 00233 00236 Wm4::Vector3f getDirection() const ; 00238 00243 bool getOrientation( float& head, float& pitch, float& roll ) const ; 00244 00249 void setOrientation( float head, float pitch, float roll ) ; 00250 00256 float getNorm() const; 00257 00261 Wm4::Vector3f applyForward( const Wm4::Vector3f& input ) const ; 00262 00266 std::vector< Wm4::Vector3f > applyForward( const std::vector< Wm4::Vector3f >& input ) const ; 00267 00271 Wm4::Vector3f applyInverse( const Wm4::Vector3f& input ) const ; 00272 00276 std::vector< Wm4::Vector3f > applyInverse( const std::vector< Wm4::Vector3f >& input ) const ; 00277 00281 Wm4::Vector3f invertVector( const Wm4::Vector3f& input ) const ; 00282 00286 Wm4::Plane3f applyForward( const Wm4::Plane3f& input ) const ; 00287 00292 friend Transform OMK_API product( const Transform& A, const Transform& B ) ; 00293 00301 Transform inverse() const ; 00302 00305 Wm4::Matrix4f getHomogeneous() const ; 00306 00308 static const Transform sk_identity ; 00309 00311 friend OMK_API bool operator == ( const Transform& t0, const Transform& t1 ) ; 00312 00314 friend OMK_API bool operator != ( const Transform& t0, const Transform& t1 ) ; 00315 00317 00318 00319 00320 friend std::ostream& ::operator << ( std::ostream& out, const Transform& q ); 00321 00324 friend std::istream& ::operator >> ( std::istream& in, Transform& q ) ; 00325 00328 friend OMK::OutgoingSynchronisationMessage& ::operator << 00329 ( OMK::OutgoingSynchronisationMessage& out, const Transform& q ) ; 00330 00333 friend OMK::IncomingSynchronisationMessage& ::operator >> 00334 ( OMK::IncomingSynchronisationMessage& in, Transform& q ) ; 00336 00337 private: 00338 00341 Wm4::Matrix3f _matrix ; 00342 00344 Wm4::Vector3f _translate ; 00345 00348 Wm4::Vector3f _scale ; 00349 00352 bool _identity ; 00353 00357 bool _uniformScale ; 00358 } ; 00359 00360 //------------------------------------------------------------------------- 00361 // isIdentity 00362 //------------------------------------------------------------------------- 00363 inline bool 00364 Transform::isIdentity() const 00365 { 00366 return _identity ; 00367 } 00368 00369 //------------------------------------------------------------------------- 00370 // isUniformScale 00371 //------------------------------------------------------------------------- 00372 inline bool 00373 Transform::isUniformScale() const 00374 { 00375 return _uniformScale ; 00376 } 00377 00378 //------------------------------------------------------------------------- 00379 // getRotate 00380 //------------------------------------------------------------------------- 00381 inline const Wm4::Matrix3f& 00382 Transform::getRotate() const 00383 { 00384 return _matrix ; 00385 } 00386 00387 //------------------------------------------------------------------------- 00388 // getQuaternionRotate 00389 //------------------------------------------------------------------------- 00390 inline Wm4::Quaternionf 00391 Transform::getQuaternionRotate() const 00392 { 00393 return Wm4::Quaternionf().FromRotationMatrix( _matrix ) ; 00394 } 00395 00396 //------------------------------------------------------------------------- 00397 // getTranslate 00398 //------------------------------------------------------------------------- 00399 inline const Wm4::Vector3f& 00400 Transform::getTranslate() const 00401 { 00402 return _translate; 00403 } 00404 00405 //------------------------------------------------------------------------- 00406 // getScale 00407 //------------------------------------------------------------------------- 00408 inline const Wm4::Vector3f& 00409 Transform::getScale() const 00410 { 00411 return _scale ; 00412 } 00413 00414 //------------------------------------------------------------------------- 00415 // getUniformScale 00416 //------------------------------------------------------------------------- 00417 inline float 00418 Transform::getUniformScale() const 00419 { 00420 OMASSERTM( isUniformScale(), "Must be a Rotate and Scale tranformation with uniform scale to return the scale value, you should use isUniformScale() before calling it" ) ; 00421 return _scale.X() ; // same as Y and Z 00422 } 00423 //------------------------------------------------------------------------- 00424 // GetRight 00425 //------------------------------------------------------------------------- 00426 inline Wm4::Vector3f 00427 Transform::getRight() const 00428 { 00429 return _matrix.GetColumn( 0 ) ; 00430 } 00431 00432 //------------------------------------------------------------------------- 00433 // GetUp 00434 //------------------------------------------------------------------------- 00435 inline Wm4::Vector3f 00436 Transform::getUp() const 00437 { 00438 return _matrix.GetColumn( 1 ) ; 00439 } 00440 00441 //------------------------------------------------------------------------- 00442 // GetDirection 00443 //------------------------------------------------------------------------- 00444 inline Wm4::Vector3f 00445 Transform::getDirection() const 00446 { 00447 return _matrix.GetColumn( 2 ) ; 00448 } 00449 00450 //------------------------------------------------------------------------- 00451 // GetOrientation 00452 //------------------------------------------------------------------------- 00453 inline bool 00454 Transform::getOrientation( float& head, float& pitch, float& roll ) const 00455 { 00456 return _matrix.ToEulerAnglesYXZ( head, pitch, roll ) ; 00457 } 00458 00459 //------------------------------------------------------------------------- 00460 // SetOrientation 00461 //------------------------------------------------------------------------- 00462 inline void 00463 Transform::setOrientation( float head, float pitch, float roll ) 00464 { 00465 // build the rotation matrix from the head, pitch and roll angles 00466 _matrix.FromEulerAnglesYXZ( head, pitch, roll ) ; 00467 _identity = false ; 00468 } 00469 00470 }// namespace Type 00471 }// namespace OMK 00472 00473 #endif // OMK_MATH_OMKTransform_H
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |