![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsBoundingVolume.hpp 00003 ******************************************************************************/ 00009 /****************************************************************************** 00010 SUKITTI PUNAK (08/21/2006) 00011 UPDATE (09/07/2010) 00012 ******************************************************************************/ 00013 #ifndef TAPs_BOUNDING_VOLUME_HPP 00014 #define TAPs_BOUNDING_VOLUME_HPP 00015 00016 #include "../Core/TAPsLib.hpp" 00017 // Inheritance 00018 //#include "../Support/TAPsColDetSupport.hpp" // Is A 00019 #include "../Support/TAPsPhysicsSupport.hpp" // Is A 00020 // Association 00021 #include "../Support/TAPsTransformationSupport.hpp" // Has A 00022 00023 BEGIN_NAMESPACE_TAPs 00024 //============================================================================= 00025 template <typename T> 00026 class BoundingVolume { 00027 //============================================================================= 00028 // Member Functions 00029 public: 00030 //------------------------------------------------------------------------- 00031 // Output Operator << 00032 friend std::ostream & operator<< ( std::ostream &output, BoundingVolume<T> const &obj ) 00033 { 00034 output << obj.StrInfo(); 00035 return output; 00036 } 00037 //------------------------------------------------------------------------- 00039 BoundingVolume ( Enum::CD type ); 00041 BoundingVolume ( Enum::CD type, int id ); 00043 BoundingVolume ( const BoundingVolume<T> & orig ); 00045 virtual ~BoundingVolume (); 00046 //------------------------------------------------------------------------- 00048 virtual std::string StrInfo () const; 00049 //------------------------------------------------------------------------- 00051 inline BoundingVolume<T> & operator= ( BoundingVolume<T> const & orig ); 00052 //------------------------------------------------------------------------- 00053 // Get/Set Fn(s) 00054 inline int GetID () const; 00055 inline void SetID ( int id ); 00056 inline std::string const & GetName () const; 00057 inline void SetName ( std::string const & name ); 00058 inline Enum::CD GetType () const; 00059 00061 PhysicsSupport<T> const & GetPhysicsSupport () const { return *m_pPhysicsSupport; } 00063 void SetPhysicsSupport ( PhysicsSupport<T> * pPhysicsSupport ) { m_pPhysicsSupport = pPhysicsSupport; } 00064 00065 //------------------------------------------------------------------------- 00067 inline virtual Vector3<T> GetCenter () const { return m_vCenter; } 00068 inline virtual void GetCenter ( T &x, T &y, T &z ) const { x = m_vCenter[0]; y = m_vCenter[1]; z = m_vCenter[2]; } 00069 inline virtual void SetCenter ( Vector3<T> const & center ) { m_vCenter = center; } 00070 inline virtual void SetCenter ( T x, T y, T z ) { m_vCenter.SetXYZ( x, y, z ); } 00071 inline virtual T GetRadius () const {return 0; } 00072 inline virtual void SetRadius ( T radius ) {} 00073 inline virtual T GetWidth () const {return 0; } 00074 inline virtual void SetWidth ( T width ) {} 00075 inline virtual T GetHeight () const {return 0; } 00076 inline virtual void SetHeight ( T height ) {} 00077 inline virtual T GetDepth () const {return 0; } 00078 inline virtual void SetDepth ( T depth ) {} 00079 //------------------------------------------------------------------------- 00080 protected: 00081 // inline void SetType ( Enum::CD type ) { m_eType = type; } 00082 public: 00083 //------------------------------------------------------------------------- 00085 inline TransformationSupport<T> const & GetTransform () const { return m_Transform; } 00087 inline TransformationSupport<T> & GetTransform () { return m_Transform; } 00089 inline void SetTransform ( TransformationSupport<T> const & trx ) { m_Transform = trx; } 00090 //------------------------------------------- 00091 // Scale the bounding volume 00092 virtual void ScaledBy ( T val ) = 0; 00093 //------------------------------------------------------------------------- 00094 00107 virtual bool TestPointLocation ( 00108 Vector3<T> const & point, 00109 Vector3<T> * const pvDistance = NULL 00110 ) const = 0; 00111 00126 virtual bool TestPointLocation ( 00127 Vector3<T> const & point, 00128 TransformationSupport<T> const * const pTransform, 00129 Vector3<T> * const pvDistance = NULL 00130 ) const = 0; 00131 00132 //------------------------------------------------------------------------- 00133 00146 virtual bool TestSphereLocation ( 00147 Vector3<T> const & sphereCenter, 00148 T sphereRadius, 00149 Vector3<T> * const pvDistance = NULL 00150 ) const = 0; 00151 00166 virtual bool TestSphereLocation ( 00167 Vector3<T> const & sphereCenter, 00168 T sphereRadius, 00169 TransformationSupport<T> const * const pTransform, 00170 Vector3<T> * const pvDistance = NULL 00171 ) const = 0; 00172 00173 //------------------------------------------------------------------------- 00174 virtual T TestOverlapWith ( BoundingVolume<T> const * const that ) const = 0; 00175 //------------------------------------------------------------------------- 00176 // virtual T TestOverlapWith ( BVHNode<T> const * const that ) const; 00177 //------------------------------------------------------------------------- 00178 // virtual T TestOverlapWithTillLeafNodes ( BVHNode<T> const * const that ) const; 00179 //------------------------------------------------------------------------- 00180 /* 00181 protected: 00182 // returning minus means overlap 00183 // returning zero means contact 00184 // returning plus means separate 00185 //========================================================================= 00186 // Binary Spheres 00187 //------------------------------------------------------------------------- 00188 inline virtual T TestOverlapSphereWithSphere ( BVHNode<T> const * const that ) const; 00189 inline virtual T TestOverlapSphereWithSphere ( BVHNode<T> const * const that, 00190 Matrix4x4<T> const & thatTransform ) const; 00191 inline virtual T TestOverlapSphereWithSphere ( Matrix4x4<T> const & thisTransform, 00192 BVHNode<T> const * const that ) const; 00193 inline virtual T TestOverlapSphereWithSphere ( Matrix4x4<T> const & thisTransform, 00194 BVHNode<T> const * const that, 00195 Matrix4x4<T> const & thatTransform ) const; 00196 //------------------------------------------------------------------------- 00197 // No Primitive-Primitive Intersection Test 00198 // Stop at Leaf-Leaf-Node Intersection Test 00199 inline virtual T TestOverlapSphereWithSphereTillLeafNodes ( BVHNode<T> const * const that ) const; 00200 inline virtual T TestOverlapSphereWithSphereTillLeafNodes ( BVHNode<T> const * const that, 00201 Matrix4x4<T> const & thatTransform ) const; 00202 inline virtual T TestOverlapSphereWithSphereTillLeafNodes ( Matrix4x4<T> const & thisTransform, 00203 BVHNode<T> const * const that ) const; 00204 inline virtual T TestOverlapSphereWithSphereTillLeafNodes ( Matrix4x4<T> const & thisTransform, 00205 BVHNode<T> const * const that, 00206 Matrix4x4<T> const & thatTransform ) const; 00207 //*/ 00208 //========================================================================= 00209 //------------------------------------------------------------------------- 00210 // With OpenGL 00211 #if defined(__gl_h_) || defined(__GL_H__) 00212 public: 00214 virtual void DrawByOpenGL ( 00215 GLenum drawStyle = GLU_LINE, 00216 Vector4<T> color = Vector4<T>( 0.77, 0.85, 0.75, 0.75 ) 00217 ) = 0; 00218 00220 virtual void Draw ( 00221 GLenum drawStyle = GLU_LINE, 00222 Vector4<T> color = Vector4<T>( 0.77, 0.85, 0.75, 0.75 ) 00223 ) = 0; 00224 //------------------------------------------------------------------------- 00225 //========================================================================= 00226 //--------------------------------------------------------------- 00227 //static GLuint m_uiDisplayList; //!< for OpenGL drawing 00228 #endif 00229 //============================================================================= 00230 //----------------------------------------------------------------------------- 00231 // Data Members -------------------------------------------------------------- 00232 protected: 00233 //-------------------------------------------------------------------- 00234 // Data Members 00235 static int m_iTotal; 00236 Enum::CD m_eType; 00237 int m_iID; 00238 std::string m_strName; 00239 00240 Vector3<T> m_vCenter; 00241 //------------------------------------------------------------------------- 00242 TransformationSupport<T> m_Transform; 00243 PhysicsSupport<T> * m_pPhysicsSupport; 00244 //-------------------------------------------------------------------- 00257 //------------------------------------------------------------------------- 00258 }; // END CLASS BoundingVolume 00259 //============================================================================= 00260 END_NAMESPACE_TAPs 00261 //----------------------------------------------------------------------------- 00262 // Include definition if TAPs_USE_EXPORT is not defined 00263 //#if !defined( TAPs_USE_EXPORT ) 00264 #include "TAPsBoundingVolume.cpp" 00265 //#endif 00266 //----------------------------------------------------------------------------- 00267 #endif 00268 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00269 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----