00001 /************************************************************************ 00002 * CCD_Object.h 00003 ************************************************************************ 00004 * Author : Duksu Kim (bluekds@tclab.kaist.ac.kr) 00005 * Affiliation : SGLAB(http://sglab.kaist.ac.kr), Dept. of Computer Science(http://cs.kaist.ac.kr) , KAIST(http://www.kaist.ac.kr) 00006 * Version : 0.5 00007 * Create : 2009/02/18 00008 * Last update : 2009/03/10 00009 ************************************************************************/ 00010 00011 #pragma once 00012 00013 #include "Geometry/box.h" 00014 #include "typeDef.h" 00015 #include "BVH.h" 00016 00017 #define CCD_OBJECT_TYPE_MAX 2 00018 #define CCD_OBJECT_TYPE_STATIC 1 00019 #define CCD_OBJECT_TYPE_DEFORMABLE 2 00020 00021 #define CCD_OBJECT_STATE_INIT 0 00022 #define CCD_OBJECT_STATE_BEGIN 1 00023 #define CCD_OBJECT_STATE_END 2 00024 00025 #define CCD_OBJECT_PROPERTY_OBJECT_TYPE 0 00026 #define CCD_OBJECT_PROPERTY_NUM_FRAME 1 00027 #define CCD_OBJECT_PROPERTY_NUM_VERTEX 2 00028 #define CCD_OBJECT_PROPERTY_NUM_TRIANGLE 3 00029 #define CCD_OBJECT_PROPERTY_NUM_EDGE 4 00030 #define CCD_OBJECT_PROPERTY_STATE 5 00031 00033 00040 class CCD_Object { 00041 /************************************************************************/ 00042 /* friends */ 00043 /************************************************************************/ 00044 friend class CCD ; // Set CCD class as a friend 00045 friend class BVH_Node ; // Set BVH_Node class as a friend 00046 friend class BVH ; // Set BVH class as a friend 00047 00048 private: 00049 int _ID ; 00050 int _curFrame ; 00051 00052 // Properties 00053 UINT _objType ; // Object type ( CCD_OBJECT_TYPE_STATIC, CCD_OBJECT_TYPE_DEFORMABLE ) 00054 00055 UINT _numFrames ; // The number of key frames 00056 UINT _numVtxs ; // The number of vertices composing this object 00057 UINT _numTris ; // The number of triangles composing this object 00058 UINT _numEdge ; // The number of edges composing this object 00059 00060 // 00061 Vec3f* _vtxs ; // list of vertices of key frames 00062 tri3f* _tris ; // list of triangles 00063 00064 edge2v* _edges ; // list of edges 00065 tri3e* _tris_edge ; // list of triangles havind edge Info. 00066 00067 Vec3f* _cur_vtxs ; // Vertex list of current frame 00068 Vec3f* _prev_vtxs ; // Vertex list of previous frame 00069 00070 BOX* _tris_box ; // BVs of triangles 00071 00072 mat4f _transMat ; // Matrix(4x4) that represent transformation 00073 00074 int _state ; // 0 : before begin, 1: begin, 2: end' 00075 00076 BVH* _bvh ; // BVH of the object 00077 00078 #ifdef SHOW_COLLIDE_TRIANGLES 00079 bool* _flags ; 00080 #endif 00081 00082 // results 00083 CCD_Output* _output ; 00084 00088 void generateEdges(void) ; 00089 00093 void refitTriBox( void ) ; 00094 00099 void initEdges( UINT numEdges) ; 00100 00107 void setEdge( UINT index, UINT a, UINT b ) ; 00108 00116 void setTrisEdge ( UINT index, UINT a, UINT b, UINT c ) ; 00117 00123 void setBox ( UINT index, BOX box ) ; 00124 00130 BOX getTriBox ( UINT index ) ; 00131 00132 public: 00133 00134 CCD_Object(void) ; 00135 ~CCD_Object(void) ; 00136 00141 int getID() const { return _ID; } 00142 00147 void setID(int val) { _ID = val; } 00148 00156 void beginObject( UINT numFrame, UINT numVtx, UINT numTri, UINT objType ) ; 00157 00162 void endObject ( void ) ; 00163 00170 void setVtx( UINT frame, UINT index, Vec3f pos ) ; 00171 00177 void setCurVtx ( UINT index, Vec3f pos ) ; 00182 void setCurVtx ( Vec3f* vtxs ) ; 00183 00187 void swapVtxs_Cur_Prev ( void ) ; 00188 00194 void setPrevVtx ( UINT index, Vec3f pos ) ; 00199 void setPrevVtx ( Vec3f* vtxs ) ; 00200 00208 void setTri( UINT index, UINT a, UINT b, UINT c ) ; 00209 00214 void setTransformationMatrix( mat4f transMat ) ; 00215 00222 bool setProperty( UINT prop, UINT value ) ; 00223 00229 UINT getProperty( UINT prop ) ; 00230 00239 void printObjectInformation ( void ) ; 00240 00244 void nextFrame( void ) ; 00245 00250 inline void setOutput( CCD_Output* output ) { 00251 _output = output ; 00252 } 00253 00254 /************************************************************************/ 00255 /* Utilities */ 00256 /************************************************************************/ 00257 00262 void visualizeBVH( int level ) { 00263 _bvh->visualize( level ) ; 00264 } 00265 00269 void visualizeObject( void ) ; 00270 } ;