TAPs 0.7.7.3
TAPsModelDefBasedOnFEM_CD.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsModelDefBasedOnFEM_CD.hpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (04/15/2010)
00009 UPDATE          (12/05/2010)
00010 ******************************************************************************/
00011 #ifndef TAPs_MODEL_DEF_BASED_ON_FEM_CD_HPP
00012 #define TAPs_MODEL_DEF_BASED_ON_FEM_CD_HPP
00013 
00014 #include "../../Physics/TAPsForces.hpp"
00015 
00016 BEGIN_NAMESPACE_TAPs__FEM
00017 //=============================================================================
00018 template <typename T>
00019 class ModelDefBasedOnFEM_CD {
00020 //=============================================================================
00021 public:
00022     // Member Functions -------------------------------------------------------
00024     friend std::ostream & operator<< ( std::ostream &output, ModelDefBasedOnFEM_CD<T> const &obj )
00025     {
00026         output << obj.StrInfo();
00027         return output;
00028     }
00029     //-------------------------------------------------------------------------
00031     ModelDefBasedOnFEM_CD ();
00033     //ModelDefBasedOnFEM_CD ( ModelDefBasedOnFEM_CD<T,DATA> const &orig );
00035     virtual ~ModelDefBasedOnFEM_CD ();
00036     //-------------------------------------------------------------------------
00038     virtual std::string StrInfo () const;
00039     //-------------------------------------------------------------------------
00041     //inline ModelDefBasedOnFEM_CD<T,DATA> & operator= ( ModelDefBasedOnFEM_CD<T,DATA> const &orig );
00042     //-------------------------------------------------------------------------
00043 
00045     void Reset ();
00046 
00048     bool GetCollisionStatus () const    { return m_bCollisionStatus; }
00050     void SetCollisionStatus ( bool b )  { m_bCollisionStatus = b; }
00051 
00053     inline T    GetCDForceScale () const    { return m_tCDForceScale; }
00055     inline void SetCDForceScale ( T s ) { m_tCDForceScale = s; }
00056 
00061     inline T    GetGrabbedForceScale () const   { return m_tGrabbedForceScale; }
00066     inline void SetGrabbedForceScale ( T s )    { m_tGrabbedForceScale = s; }
00067 
00069     virtual bool Init ( 
00070         OpenGL::OpenGLHalfEdgeTrigonalModel<T> * pHEModel   
00071     );
00072 
00076     inline virtual void ClearCollidedParts () = 0;
00077 
00079     inline virtual bool CDRwith (
00080         MultiBoundingVolume<T> * const pMBVObj      
00081     ) = 0;
00082 
00084     inline virtual bool CDRwith (
00085         MultiBoundingVolume<T> * const pMBVObj,     
00086         TransformationSupport<T> * const pTransform 
00087     ) = 0;
00088 
00089     // Data Members -----------------------------------------------------------
00090 //=============================================================================
00091 protected:
00092 
00093     template <typename T>
00094     class CDObj {
00095     public:
00096         // Member functions -----------------------------------------
00098         CDObj ( HEVertex<T> * _pHEVertex, Vector3<T> const & _PosAdj )
00099             : pHEVertex( _pHEVertex ), PosAdj( _PosAdj ), PtForce()
00100         {}
00101 
00102         CDObj ( CDObj const & O )
00103             : pHEVertex( O.pHEVertex ), PosAdj( O.PosAdj ), PtForce( O.PtForce )
00104         {}
00105 
00106         CDObj & operator= ( CDObj const & O )
00107         {
00108             pHEVertex = O.pHEVertex;
00109             PosAdj = O.PosAdj;
00110             PtForce = O.PtForce;
00111             return *this;
00112         }
00113         
00114         // Data members ---------------------------------------------
00115         HEVertex<T> *   pHEVertex;  
00116         Vector3<T>      PosAdj;     
00117         PointForce<T>   PtForce;    
00118     };
00119 
00120     // Member Functions -------------------------------------------------------
00121 
00122 public:
00123     // HAVE TO BE HERE, SINCE CDObj IS DECLARED HERE (ABOVE).
00125     std::vector< CDObj<T> > const & RefToCollidedMeshParts () const { return m_ListOfCDObjs; }
00127     std::vector< CDObj<T> > &       RefToCollidedMeshParts ()       { return m_ListOfCDObjs; }
00128 
00129 
00130     //=========================================================================
00131     // Grabbing
00132     //-------------------------------------------------------------------------
00133 
00142     inline int GrabbedBy (
00143         Vector3<T> *    pSpherePos,     
00144         T               sphereRadius    
00145     );
00146 
00155     //inline int GrabbedBy (
00156     //  MultiBoundingVolume<T> * const pMBVObj      //!< a multi bounding volume object
00157     //);
00158 
00167     //inline int GrabbedBy (
00168     //  MultiBoundingVolume<T> * const pMBVObj,     //!< a multi bounding volume object
00169     //  TransformationSupport<T> * const pTransform //!< an extra transformation for the MBV object
00170     //);
00171 
00176     inline void ReleaseGrabbedPart ( int grabbedPartID );
00177 
00182     inline virtual void MoveGrabbedPart ( int grabbedPartID ) = 0;
00183 
00185     inline virtual void MoveAllGrabbedParts () = 0;
00186 
00188     int GetNumOfGrabbedParts () const   { return static_cast<int>( m_ListOfGrabbedParts.size() ); }
00189 
00191     int GetMaxNumOfGrabbedPartsAllowed () const { return MAX_NUMBER_OF_GRABBED_PARTS; }
00192 
00193 protected:
00194     static const int    MAX_NUMBER_OF_GRABBED_PARTS = 32;           
00195     bool    m_ListOfGrabbedParts_IsGrabbedStatus[MAX_NUMBER_OF_GRABBED_PARTS];  
00196     class GrabbedPartData {
00197     public:
00198         GrabbedPartData () : ID(-1), pGrabbingPosition( NULL ) {}
00199 
00200         GrabbedPartData & operator= ( GrabbedPartData const & orig )
00201         {
00202             GrabbedVertices = orig.GrabbedVertices;
00203             ID = orig.ID;
00204             pGrabbingPosition = orig.pGrabbingPosition;
00205             return *this;
00206         }
00207 
00208         void Clear ()
00209         {
00210             GrabbedVertices.clear();
00211             ID = -1;
00212         }
00213 
00214         std::vector< CDObj<T> > GrabbedVertices;    
00215         int                     ID;                 
00216         Vector3<T> *            pGrabbingPosition;  
00217     };
00218     std::vector< GrabbedPartData >  m_ListOfGrabbedParts;   
00219 
00221     inline virtual bool GrabbedBy (
00222         MultiBoundingVolume<T> * const pMBVObj,     
00223         std::vector< CDObj<T> > *   pListOfCDObj    
00224     );
00225 
00226     //-------------------------------------------------------------------------
00227     // Grabbing
00228     //=========================================================================
00229 
00230 
00231 
00232 protected:
00233 
00237     inline virtual bool CORE_CDwith (
00238         MultiBoundingVolume<T> * const pMBVObj,     
00239         std::vector< CDObj<T> > *   pListOfCDObj    
00240     );
00241 
00242     // Data Members -----------------------------------------------------------
00243     OpenGL::OpenGLHalfEdgeTrigonalModel<T> *    m_pHEModel; 
00244     bool    m_bCollisionStatus;     
00245     std::vector< CDObj<T> > m_ListOfCDObjs; 
00246 
00247     T   m_tCDForceScale;        
00248     T   m_tGrabbedForceScale;   
00249 
00250 
00251 
00252 
00253     // DEBUG
00254     void PrintListOfCDObjs ()
00255     {
00256         for ( unsigned int i = 0; i < m_ListOfCDObjs.size(); ++i ) {
00257             std::cout << i << "\tHEVertex *: " << m_ListOfCDObjs[i].pHEVertex
00258                 << "\t" << *(m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr())
00259                 //<< "\t" << m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr()->GetElementID()
00260                 //<< "\t" << m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr()->RetVertexPtr()
00261                 //<< "\t" << *(m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr()->RetVertexPtr())
00262                 //<< "\t" << &(m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr()->RetGenBaryCoords())
00263                 //<< "\t" << m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr()->RetGenBaryCoords()
00264                 << "\tID: " << m_ListOfCDObjs[i].pHEVertex->GetID() 
00265                 << "\t" << m_ListOfCDObjs[i].PosAdj 
00266                 << "\t" << m_ListOfCDObjs[i].PtForce 
00267                 << "\n";
00268 
00269             //TetBarycentricCoordsForVertexRef<T> * ptr = dynamic_cast< TetBarycentricCoordsForVertexRef<T> * >( m_ListOfCDObjs[i].pHEVertex->GetBarycentricPtr() );
00270             //if ( ptr ) {
00271             //  std::cout << "YES\n";
00272             //}
00273         }
00274     }
00275 
00276 //=============================================================================
00277 private:
00278     // Member Functions -------------------------------------------------------
00279     // Data Members -----------------------------------------------------------
00280 //=============================================================================
00281 
00282 #if defined(__gl_h_) || defined(__GL_H__)
00283 public:
00284 #endif
00285 
00286 //=============================================================================
00287 }; // END CLASS ModelDefBasedOnFEM_CD
00288 //=============================================================================
00289 END_NAMESPACE_TAPs__FEM
00290 //-----------------------------------------------------------------------------
00292 #include "TAPsModelDefBasedOnFEM_CD.cpp"
00293 
00295 // Include definition if TAPs_USE_EXPORT is not defined
00296 //#if !defined( TAPs_USE_EXPORT )
00297 //  #include "TAPsModelDefBasedOnFEM_CD.cpp"
00298 //#endif
00299 //-----------------------------------------------------------------------------
00300 #endif
00301 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00302 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines