home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / cm / CollisionModel.h
C/C++ Source or Header  |  2005-11-14  |  7KB  |  154 lines

  1.  
  2. #ifndef __COLLISIONMODELMANAGER_H__
  3. #define __COLLISIONMODELMANAGER_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Trace model vs. polygonal model collision detection.
  9.  
  10.     Short translations are the least expensive. Retrieving contact points is
  11.     about as cheap as a short translation. Position tests are more expensive
  12.     and rotations are most expensive.
  13.  
  14.     There is no position test at the start of a translation or rotation. In other
  15.     words if a translation with start != end or a rotation with angle != 0 starts
  16.     in solid, this goes unnoticed and the collision result is undefined.
  17.  
  18.     A translation with start == end or a rotation with angle == 0 performs
  19.     a position test and fills in the trace_t structure accordingly.
  20.  
  21. ===============================================================================
  22. */
  23.  
  24. // contact type
  25. enum contactType_t {
  26.     CONTACT_NONE,                            // no contact
  27.     CONTACT_EDGE,                            // trace model edge hits model edge
  28.     CONTACT_MODELVERTEX,                    // model vertex hits trace model polygon
  29.     CONTACT_TRMVERTEX                        // trace model vertex hits model polygon
  30. };
  31.  
  32. // contact info
  33. struct contactInfo_t {
  34.     contactType_t            type;            // contact type
  35.     idVec3                    point;            // point of contact
  36.     idVec3                    normal;            // contact plane normal
  37.     float                    dist;            // contact plane distance
  38.     float                    separation;        // contact feature separation at initial position
  39.     int                        contents;        // contents at other side of surface
  40.     const idMaterial *        material;        // surface material
  41.     int                        modelFeature;    // contact feature on model
  42.     int                        trmFeature;        // contact feature on trace model
  43.     int                        entityNum;        // entity the contact surface is a part of
  44.     int                        id;                // id of clip model the contact surface is part of
  45. // RAVEN BEGIN
  46. // jscott: for material type code
  47.     const rvDeclMatType        *materialType;    // material type of texture (possibly indirected though a hit map)
  48. // RAVEN END
  49. };
  50.  
  51. // trace result
  52. struct trace_t {
  53.     float                    fraction;        // fraction of movement completed, 1.0 = didn't hit anything
  54.     idVec3                    endpos;            // final position of trace model
  55.     idMat3                    endAxis;        // final axis of trace model
  56.     contactInfo_t            c;                // contact information, only valid if fraction < 1.0
  57. };
  58.  
  59. #define WORLD_MODEL_NAME    "worldMap"        // name of world model
  60. #define CM_CLIP_EPSILON        0.25f            // always stay this distance away from any model
  61. #define CM_BOX_EPSILON        1.0f            // should always be larger than clip epsilon
  62. #define CM_MAX_TRACE_DIST    4096.0f            // maximum distance a trace model may be traced, point traces are unlimited
  63.  
  64. // collision model
  65. class idCollisionModel {
  66. public:
  67.     virtual                        ~idCollisionModel() { }
  68.                                 // Returns the name of the model.
  69.     virtual const char *        GetName( void ) const = 0;
  70.                                 // Gets the bounds of the model.
  71.     virtual bool                GetBounds( idBounds &bounds ) const = 0;
  72.                                 // Gets all contents flags of brushes and polygons of the model ored together.
  73.     virtual bool                GetContents( int &contents ) const = 0;
  74.                                 // Gets a vertex of the model.
  75.     virtual bool                GetVertex( int vertexNum, idVec3 &vertex ) const = 0;
  76.                                 // Gets an edge of the model.
  77.     virtual bool                GetEdge( int edgeNum, idVec3 &start, idVec3 &end ) const = 0;
  78.                                 // Gets a polygon of the model.
  79.     virtual bool                GetPolygon( int polygonNum, idFixedWinding &winding ) const = 0;
  80. };
  81.  
  82. // collision model manager
  83. class idCollisionModelManager {
  84. public:
  85.     virtual                        ~idCollisionModelManager( void ) {}
  86.  
  87.     virtual void                Init( void ) = 0;
  88.     virtual void                Shutdown( void ) = 0;
  89.  
  90.                                 // Loads collision models from a map file.
  91.     virtual void                LoadMap( const idMapFile *mapFile, bool forceReload ) = 0;
  92.                                 // Frees all the collision models for the given map.
  93.     virtual void                FreeMap( const char *mapName ) = 0;
  94.  
  95.                                 // Loads a collision model.
  96.     virtual idCollisionModel *    LoadModel( const char *mapName, const char *modelName ) = 0;
  97. // RAVEN BEGIN
  98. // mwhitlock: conversion from idRenderModel to MD5R fixes (to keep redundant collision surfaces out of the MD5R files).
  99.     virtual idCollisionModel *    ExtractCollisionModel( idRenderModel *renderModel, const char *modelName ) = 0;
  100. // RAVEN END
  101.                                 // Precaches a collision model.
  102.     virtual void                PreCacheModel( const char *mapName, const char *modelName ) = 0;
  103.                                 // Free the given model.
  104.     virtual void                FreeModel( idCollisionModel *model ) = 0;
  105.                                 // Purge all unused models.
  106.     virtual void                PurgeModels( void ) = 0;
  107.  
  108.                                 // Sets up a trace model for collision with other trace models.
  109.     virtual idCollisionModel *    ModelFromTrm( const char *mapName, const char *modelName, const idTraceModel &trm, const idMaterial *material ) = 0;
  110.                                 // Creates a trace model from a collision model, returns true if succesfull.
  111.     virtual bool                TrmFromModel( const char *mapName, const char *modelName, idTraceModel &trm ) = 0;
  112.                                 // Creates a trace model for each primitive of the collision model, returns the number of trace models.
  113.     virtual int                    CompoundTrmFromModel( const char *mapName, const char *modelName, idTraceModel *trms, int maxTrms ) = 0;
  114.  
  115.                                 // Translates a trace model and reports the first collision if any.
  116.     virtual void                Translation( trace_t *results, const idVec3 &start, const idVec3 &end,
  117.                                     const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
  118.                                     idCollisionModel *model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
  119.                                 // Rotates a trace model and reports the first collision if any.
  120.     virtual void                Rotation( trace_t *results, const idVec3 &start, const idRotation &rotation,
  121.                                     const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
  122.                                     idCollisionModel *model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
  123.                                 // Returns the contents touched by the trace model or 0 if the trace model is in free space.
  124.     virtual int                    Contents( const idVec3 &start,
  125.                                     const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
  126.                                     idCollisionModel *model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
  127.                                 // Stores all contact points of the trace model with the model, returns the number of contacts.
  128.     virtual int                    Contacts( contactInfo_t *contacts, const int maxContacts, const idVec3 &start, const idVec6 &dir, const float depth,
  129.                                     const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
  130.                                     idCollisionModel *model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
  131.  
  132.                                 // Tests collision detection.
  133.     virtual void                DebugOutput( const idVec3 &viewOrigin, const idMat3 &viewAxis ) = 0;
  134.                                 // Draws a model.
  135.     virtual void                DrawModel( idCollisionModel *model, const idVec3 &modelOrigin, const idMat3 &modelAxis,
  136.                                                 const idVec3 &viewOrigin, const idMat3 &viewAxis, const float radius ) = 0;
  137.                                 // Lists all loaded models.
  138.     virtual void                ListModels( void ) = 0;
  139.                                 // Prints model information, use -1 for accumulated model info.
  140.     virtual void                ModelInfo( int num ) = 0;
  141. // RAVEN BEGIN
  142. // jscott: added for memory profiling
  143.     virtual void                PrintMemInfo( MemInfo *mi ) = 0;
  144. // cdr: AASTactical
  145.     virtual bool                IsLoaded( void ) = 0;
  146. // RAVEN END
  147.                                 // Writes a collision model file for the given map entity.
  148.     virtual bool                WriteCollisionModelForMapEntity( const idMapEntity *mapEnt, const char *filename, const bool testTraceModel = true ) = 0;
  149. };
  150.  
  151. extern idCollisionModelManager *collisionModelManager;
  152.  
  153. #endif /* !__COLLISIONMODELMANAGER_H__ */
  154.