doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CollisionModel.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __COLLISIONMODELMANAGER_H__
30 #define __COLLISIONMODELMANAGER_H__
31 
32 /*
33 ===============================================================================
34 
35  Trace model vs. polygonal model collision detection.
36 
37  Short translations are the least expensive. Retrieving contact points is
38  about as cheap as a short translation. Position tests are more expensive
39  and rotations are most expensive.
40 
41  There is no position test at the start of a translation or rotation. In other
42  words if a translation with start != end or a rotation with angle != 0 starts
43  in solid, this goes unnoticed and the collision result is undefined.
44 
45  A translation with start == end or a rotation with angle == 0 performs
46  a position test and fills in the trace_t structure accordingly.
47 
48 ===============================================================================
49 */
50 
51 // contact type
52 typedef enum {
53  CONTACT_NONE, // no contact
54  CONTACT_EDGE, // trace model edge hits model edge
55  CONTACT_MODELVERTEX, // model vertex hits trace model polygon
56  CONTACT_TRMVERTEX // trace model vertex hits model polygon
58 
59 // contact info
60 typedef struct {
61  contactType_t type; // contact type
62  idVec3 point; // point of contact
63  idVec3 normal; // contact plane normal
64  float dist; // contact plane distance
65  int contents; // contents at other side of surface
66  const idMaterial * material; // surface material
67  int modelFeature; // contact feature on model
68  int trmFeature; // contact feature on trace model
69  int entityNum; // entity the contact surface is a part of
70  int id; // id of clip model the contact surface is part of
72 
73 // trace result
74 typedef struct trace_s {
75  float fraction; // fraction of movement completed, 1.0 = didn't hit anything
76  idVec3 endpos; // final position of trace model
77  idMat3 endAxis; // final axis of trace model
78  contactInfo_t c; // contact information, only valid if fraction < 1.0
79 } trace_t;
80 
81 typedef int cmHandle_t;
82 
83 #define CM_CLIP_EPSILON 0.25f // always stay this distance away from any model
84 #define CM_BOX_EPSILON 1.0f // should always be larger than clip epsilon
85 #define CM_MAX_TRACE_DIST 4096.0f // maximum distance a trace model may be traced, point traces are unlimited
86 
88 public:
89  virtual ~idCollisionModelManager( void ) {}
90 
91  // Loads collision models from a map file.
92  virtual void LoadMap( const idMapFile *mapFile ) = 0;
93  // Frees all the collision models.
94  virtual void FreeMap( void ) = 0;
95 
96  // Gets the clip handle for a model.
97  virtual cmHandle_t LoadModel( const char *modelName, const bool precache ) = 0;
98  // Sets up a trace model for collision with other trace models.
99  virtual cmHandle_t SetupTrmModel( const idTraceModel &trm, const idMaterial *material ) = 0;
100  // Creates a trace model from a collision model, returns true if succesfull.
101  virtual bool TrmFromModel( const char *modelName, idTraceModel &trm ) = 0;
102 
103  // Gets the name of a model.
104  virtual const char * GetModelName( cmHandle_t model ) const = 0;
105  // Gets the bounds of a model.
106  virtual bool GetModelBounds( cmHandle_t model, idBounds &bounds ) const = 0;
107  // Gets all contents flags of brushes and polygons of a model ored together.
108  virtual bool GetModelContents( cmHandle_t model, int &contents ) const = 0;
109  // Gets a vertex of a model.
110  virtual bool GetModelVertex( cmHandle_t model, int vertexNum, idVec3 &vertex ) const = 0;
111  // Gets an edge of a model.
112  virtual bool GetModelEdge( cmHandle_t model, int edgeNum, idVec3 &start, idVec3 &end ) const = 0;
113  // Gets a polygon of a model.
114  virtual bool GetModelPolygon( cmHandle_t model, int polygonNum, idFixedWinding &winding ) const = 0;
115 
116  // Translates a trace model and reports the first collision if any.
117  virtual void Translation( trace_t *results, const idVec3 &start, const idVec3 &end,
118  const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
119  cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
120  // Rotates a trace model and reports the first collision if any.
121  virtual void Rotation( trace_t *results, const idVec3 &start, const idRotation &rotation,
122  const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
123  cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
124  // Returns the contents touched by the trace model or 0 if the trace model is in free space.
125  virtual int Contents( const idVec3 &start,
126  const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
127  cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
128  // Stores all contact points of the trace model with the model, returns the number of contacts.
129  virtual int Contacts( contactInfo_t *contacts, const int maxContacts, const idVec3 &start, const idVec6 &dir, const float depth,
130  const idTraceModel *trm, const idMat3 &trmAxis, int contentMask,
131  cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis ) = 0;
132 
133  // Tests collision detection.
134  virtual void DebugOutput( const idVec3 &origin ) = 0;
135  // Draws a model.
136  virtual void DrawModel( cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis,
137  const idVec3 &viewOrigin, const float radius ) = 0;
138  // Prints model information, use -1 handle for accumulated model info.
139  virtual void ModelInfo( cmHandle_t model ) = 0;
140  // Lists all loaded models.
141  virtual void ListModels( void ) = 0;
142  // Writes a collision model file for the given map entity.
143  virtual bool WriteCollisionModelForMapEntity( const idMapEntity *mapEnt, const char *filename, const bool testTraceModel = true ) = 0;
144 };
145 
147 
148 #endif /* !__COLLISIONMODELMANAGER_H__ */
virtual void FreeMap(void)=0
virtual bool TrmFromModel(const char *modelName, idTraceModel &trm)=0
virtual bool GetModelContents(cmHandle_t model, int &contents) const =0
contactType_t
virtual void LoadMap(const idMapFile *mapFile)=0
virtual void ListModels(void)=0
virtual void Translation(trace_t *results, const idVec3 &start, const idVec3 &end, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)=0
Definition: Vector.h:316
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glext.h:2878
contactType_t type
int cmHandle_t
virtual const char * GetModelName(cmHandle_t model) const =0
virtual int Contents(const idVec3 &start, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)=0
virtual int Contacts(contactInfo_t *contacts, const int maxContacts, const idVec3 &start, const idVec6 &dir, const float depth, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)=0
virtual void DrawModel(cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis, const idVec3 &viewOrigin, const float radius)=0
contactInfo_t c
float fraction
virtual bool GetModelVertex(cmHandle_t model, int vertexNum, idVec3 &vertex) const =0
idVec3 endpos
const idMaterial * material
virtual cmHandle_t LoadModel(const char *modelName, const bool precache)=0
virtual bool GetModelPolygon(cmHandle_t model, int polygonNum, idFixedWinding &winding) const =0
GLuint GLuint end
Definition: glext.h:2845
virtual void Rotation(trace_t *results, const idVec3 &start, const idRotation &rotation, const idTraceModel *trm, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)=0
virtual bool GetModelEdge(cmHandle_t model, int edgeNum, idVec3 &start, idVec3 &end) const =0
idMat3 endAxis
virtual void DebugOutput(const idVec3 &origin)=0
virtual bool WriteCollisionModelForMapEntity(const idMapEntity *mapEnt, const char *filename, const bool testTraceModel=true)=0
Definition: Matrix.h:333
virtual ~idCollisionModelManager(void)
virtual void ModelInfo(cmHandle_t model)=0
struct trace_s trace_t
virtual cmHandle_t SetupTrmModel(const idTraceModel &trm, const idMaterial *material)=0
virtual bool GetModelBounds(cmHandle_t model, idBounds &bounds) const =0
idCollisionModelManager * collisionModelManager
GLuint start
Definition: glext.h:2845