00001
00002
00003
00004
00005
00033
00034
00035
00036
00037 #ifndef Collision_H
00038 #define Collision_H
00039 #if defined(__sgi) || defined(_WIN32)
00040 #pragma once
00041 #endif
00042
00043
00044
00045
00046
00047
00048 #include <vector>
00049
00050 #include <OpenSG/OSGConfig.h>
00051 #include <OpenSG/OSGGeoProperty.h>
00052 #include <OpenSG/OSGGeometry.h>
00053
00054 #include <col_import_export.h>
00055
00057 namespace col {
00058
00059
00060
00061
00062
00063 struct Data;
00064 struct Dop;
00065 struct ColPipelineData;
00066 struct SyncFun;
00067
00068 template<class T> class Queue;
00069 struct Request;
00070 class Matrix;
00071 class ColObj;
00072 struct Callback;
00073 class Grid;
00074
00075
00076
00077
00078
00079
00080
00081
00082
00104 typedef bool (*PolyIntersectT)( Data *data );
00105
00106
00108 typedef enum
00109 {
00110 LEVEL_BOX,
00111 LEVEL_HULL,
00112 LEVEL_EXACT
00113 } LevelOfDetectionE;
00114
00115
00117 typedef enum
00118 {
00119 ALGO_DEFAULT,
00120 ALGO_DOPTREE,
00121 ALGO_BOXTREE
00122 } AlgoE;
00123
00124
00125
00126
00127
00128
00129
00130
00131 struct COL_EXPORTIMPORT Callback
00132 {
00134 virtual void operator () (const Data *data) throw () = 0;
00135
00136 Callback( osg::NodePtr obj1, osg::NodePtr obj2,
00137 bool always = false,
00138 bool all_polygons_in = false,
00139 LevelOfDetectionE level_of_detection = LEVEL_EXACT );
00140 virtual ~Callback();
00141
00143 osg::NodePtr obj1, obj2;
00144
00146 bool collision;
00147
00151 bool all_polygons;
00152
00161 LevelOfDetectionE level;
00162
00163 };
00164
00165
00166
00167
00168
00169
00170 struct COL_EXPORTIMPORT PolygonIntersectionData
00171 {
00172
00183 const osg::Pnt3f *points[2];
00184 const unsigned int *pgon[2];
00185 unsigned int nvertices[2];
00186
00188 osg::GeometryPtr geom[2];
00189 unsigned int pgon_index[2];
00190
00191 };
00192
00193
00194 struct COL_EXPORTIMPORT Data
00195 {
00196
00197
00198 std::vector<PolygonIntersectionData> polisecdata;
00199
00201 osg::NodePtr node[2];
00202
00204 osg::Matrix m12;
00205
00206
00207 bool all_polygons;
00208
00209
00210
00212 void* client_data;
00213
00215 PolyIntersectT intersect_fun;
00216
00217
00218
00220 const Dop* dop[2];
00221
00222 Data( const osg::NodePtr &node1, const osg::NodePtr &node2 );
00223
00224
00225
00226
00228 void addPolygonIntersectionData( const osg::Pnt3f *points1,
00229 const osg::Pnt3f *points2,
00230 const unsigned int *pgon1,
00231 const unsigned int *pgon2,
00232 unsigned int nvertices1,
00233 unsigned int nvertices2,
00234 const osg::GeometryPtr &geom1,
00235 const osg::GeometryPtr &geom2,
00236 unsigned int pgon_index1,
00237 unsigned int pgon_index2 );
00238
00239 protected:
00240 Data( const Data &source );
00241 Data& operator = ( const Data &source );
00242 };
00243
00244
00245
00246
00247
00248
00249
00250
00251 class COL_EXPORTIMPORT CollisionPipeline : public osg::Thread
00252 {
00253
00254 public:
00256 CollisionPipeline( const osg::Char8 *thread_name = NULL,
00257 unsigned int thread_id = 0 );
00258
00260 void check( unsigned int *num_moved = NULL );
00261
00263 static CollisionPipeline *runConcurrently( char* thread_name = NULL );
00264
00266 static CollisionPipeline *get(char *name);
00267
00269 static CollisionPipeline *find(char *name);
00270
00272 void run(unsigned int number);
00273
00275 void setSyncFun( SyncFun *fun );
00276
00278 void useConvexHulls(bool useconvexhulls);
00279
00281 void addCallback( Callback *callback );
00282
00284 void addCycleCallback( Callback *callback );
00285
00287 void makeCollidable( osg::NodePtr node );
00288
00290 void deactivate( osg::NodePtr node );
00291
00293 void activate( osg::NodePtr node );
00294
00297
00298 unsigned int getCycle( void );
00299
00301 bool getUseGrid ();
00302
00304 void useGrid( unsigned int size[3], float min[3], float max[3] );
00305
00307 static AlgoE getAlgorithm();
00308
00310 void verbose( bool verbPrint, bool verbShowHulls );
00311
00313 bool getVerbPrint();
00314
00316 bool getVerbShowHulls();
00317
00319 unsigned int getNumObjs();
00320
00322 void setUseHulls(bool useHulls);
00323
00325 bool getUseHulls();
00326
00327
00330
00331 static AlgoE M_PipelineAlgorithm;
00332
00334 unsigned int m_thread_id;
00335
00337 static int m_Processor;
00338
00344 unsigned int m_nonEmptyCycles;
00345
00351 Queue<Request> *m_requests;
00352
00354 Matrix *m_collmatrix;
00355
00357 std::vector<ColObj> *m_colobjs;
00358
00360 std::vector<Callback*> m_cycle_callbacks;
00361
00363 ColPipelineData* m_pipelinedata;
00364
00366 Grid *m_grid;
00367
00369 virtual ~CollisionPipeline();
00370
00371 protected:
00372 static osg::MPThreadType m_type;
00373 static osg::BaseThread* create( const osg::Char8 *thread_name, osg::UInt32 thread_id);
00374 virtual void workProc(void);
00375
00376 private:
00378 unsigned int m_cycle;
00379
00381 bool m_verb_print;
00382
00384 bool m_verb_show_hulls;
00385
00387 bool m_useHulls;
00388
00390 unsigned int m_numObjs;
00391
00393 const osg::Char8 *m_thread_name;
00394
00396 SyncFun *m_syncfun;
00397
00399 CollisionPipeline (const CollisionPipeline& source);
00400
00401 void operator = (const CollisionPipeline &source);
00402
00404 void request( const Request &request );
00405
00406
00407 };
00408
00409
00410
00411
00412
00413
00414
00415 struct COL_EXPORTIMPORT SyncFun
00416 {
00421 virtual bool operator () () throw () = 0;
00422
00423 SyncFun( );
00424 virtual ~SyncFun();
00425 };
00426
00427
00428
00429
00430 }
00431
00432 #endif
00433