convert line ends
[canaan.git] / prj / cam / src / physics / phclsn.h
blob655d953f34c4c171bda6aa0b33472b71178188fd
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/physics/phclsn.h,v 1.18 2000/01/29 13:32:38 adurant Exp $
8 //
9 // Physics collisions
11 #pragma once
13 #ifndef __PHCLSN_H
14 #define __PHCLSN_H
16 #include <objtype.h>
18 #include <phystyp2.h>
19 #include <phmod.h>
20 #include <phsubmod.h>
21 #include <phterr.h>
23 typedef struct sSphrContactData sSphrContactData;
25 class cPhysSphereModel;
26 class cPhysOBBModel;
28 ///////////////////////////////////////////////////////////////////////////////
31 // Result of a collision
33 enum ePhysClsnResultEnum
35 kPCR_Nothing,
36 kPCR_Bounce,
37 kPCR_Die1,
38 kPCR_Die2,
39 kPCR_DieBoth,
40 kPCR_NonPhys1,
41 kPCR_NonPhys2,
42 kPCR_NonPhysBoth,
43 kPCR_Stop,
44 kPCR_NewControl,
47 //#pragma pack(4)
49 ///////////////////////////////////////////////////////////////////////////////
51 enum ePhysClsnType
53 kPC_StationaryObject = 0x0001,
54 kPC_MoveableObject = 0x0002,
55 kPC_OBBObject = 0x0004,
56 kPC_SphereHatObject = 0x0008,
58 kPC_Object = kPC_StationaryObject | kPC_MoveableObject | kPC_OBBObject | kPC_SphereHatObject,
60 kPC_TerrainFace = 0x0010,
61 kPC_TerrainEdge = 0x0020,
62 kPC_TerrainVertex = 0x0040,
64 kPC_Terrain = kPC_TerrainFace | kPC_TerrainEdge | kPC_TerrainVertex,
66 kPC_Invalid = 0xffffffffL
69 ///////////////////////////////////////////////////////////////////////////////
71 class cPhysClsn;
73 typedef cDList<cPhysClsn, 0> cPhysClsnsBase;
74 typedef cDListNode<cPhysClsn, 0> cPhysClsnNodeBase;
76 ///////////////////////////////////////////////////////////////////////////////
78 // STRUCT: sPhysClsnTerr
80 // describes terrain for a collision
83 struct sPhysClsnTerr
85 cPhysTerrPolyList m_polyList;
86 mxs_vector m_normal; // computed normal of polys
89 ///////////////////////////////////////////////////////////////////////////////
91 // STRUCT: sPhysClsn
93 // Instance of a collision, implemented as a struct so we can (eventually)
94 // pass it to C
97 struct sPhysClsn
99 ePhysClsnType type;
100 ePhysClsnResult result;
101 mxs_real t0;
102 mxs_real dt;
103 mxs_vector clsn_pt;
104 sPhysSubModInst instance;
105 void * pData; // either a pointer to another sub-model instance or collision terrain struct
108 ///////////////////////////////////////////////////////////////////////////////
110 class cPhysClsn : public sPhysClsn, public cPhysClsnNodeBase
112 public:
113 ////////////////////////////////////
115 // Constructors/Destructor
118 // Make a copy of the clsn
119 cPhysClsn(cPhysClsn *pClsn);
121 // A sphere-sphere collision
122 cPhysClsn(ePhysClsnType type, mxs_real t0, mxs_real dt,
123 const cPhysSphereModel * pSphereModel1, tPhysSubModId subModId1, const mxs_vector & locVec1,
124 const cPhysSphereModel * pSphereModel2, tPhysSubModId subModId2, const mxs_vector & locVec2);
126 // A sphere-obb collision
127 cPhysClsn(ePhysClsnType type, mxs_real t0, mxs_real dt,
128 const cPhysSphereModel * pSphereModel, tPhysSubModId subModId1, const mxs_vector & locVec1,
129 const cPhysOBBModel * pOBBModel, int side, const mxs_vector & locVec2);
131 // A sphere object-terrain collision
132 cPhysClsn(ePhysClsnType type, mxs_real t0, mxs_real dt, const mxs_vector & clsn_pt,
133 const cPhysModel * pModel, tPhysSubModId subModId, const mxs_vector & locVec,
134 sSphrContactData aContactData[], int contactID);
136 // A point object-terrain collision
137 cPhysClsn(ePhysClsnType type, mxs_real t0, mxs_real dt, const mxs_vector & clsn_pt,
138 const cPhysModel * pModel, tPhysSubModId subModId, const mxs_vector & locVec,
139 int cell_id, int poly_id);
141 ~cPhysClsn();
143 ////////////////////////////////////
145 // Access functions
147 ePhysClsnType GetType() const;
148 mxs_real GetTime() const;
149 mxs_real GetT0() const;
150 mxs_real GetDT() const;
152 const mxs_vector & GetLoc() const;
153 const mxs_vector & GetLoc2() const;
155 void SetResult(ePhysClsnResult result);
156 ePhysClsnResult GetResult() const;
158 const sPhysSubModInst & GetInstance() const;
159 ObjID GetObjID() const;
160 tPhysSubModId GetSubModId() const;
161 cPhysModel * GetModel() const;
162 int GetTexture() const;
164 const sPhysSubModInst & GetInstance2() const;
165 ObjID GetObjID2() const;
166 tPhysSubModId GetSubModId2() const;
167 cPhysModel * GetModel2() const;
169 cPhysTerrPoly * GetTerrainPoly(int index = 0) const;
170 int GetCellID(int index = 0) const;
171 int GetPolyID(int index = 0) const;
172 const mxs_vector GetNormal(int index = -1) const;
174 // Note that collision points for non-terrain collisions are NOT EXACT
175 const mxs_vector & GetClsnPt() const;
177 #ifdef DBG_ON
178 void MonoPrint() const;
179 #endif
181 private:
182 #define AssertObjectCollision() Assert_(type & kPC_Object)
183 void CreateTerrainInfo(ePhysClsnType type,
184 sSphrContactData * pContactData,
185 cPhysTerrPolyList * pList);
186 void GenerateClsnPt();
189 ///////////////////////////////////////////////////////////////////////////////
191 // CLASS: cPhysClsns
193 // List of collisions
196 class cPhysClsns : public cPhysClsnsBase
198 public:
199 void New(const cPhysModel * pModel,
200 tPhysSubModId subModId,
201 mxs_real time,
202 const Location & hitLoc,
203 const mxs_vector * pNormals);
204 void Insert(cPhysClsn * pClsn);
205 void Sort();
206 private:
209 ///////////////////////////////////////////////////////////////////////////////
211 // Non-member inline functions
214 inline void InitSubModelInstance(sPhysSubModInst * pInstance, tPhysSubModId subModId, const cPhysModel * pModel,
215 const mxs_vector & locVec)
217 // This isn't a member function, because this is a structure we want to expose to c functions
218 pInstance->objID = pModel->GetObjID();
219 pInstance->subModId = subModId;
220 pInstance->pModel = (cPhysModel *) pModel;
221 pInstance->locVec = locVec;
224 ///////////////////////////////////////////////////////////////////////////////
226 // CLASS: cPhysClsn, inline functions
229 inline ePhysClsnType cPhysClsn::GetType() const
231 return type;
234 ///////////////////////////////////////
236 inline mxs_real cPhysClsn::GetTime() const
238 return t0 + dt;
241 ///////////////////////////////////////
243 inline mxs_real cPhysClsn::GetT0() const
245 return t0;
248 ///////////////////////////////////////
250 inline mxs_real cPhysClsn::GetDT() const
252 return dt;
255 ///////////////////////////////////////
257 inline const mxs_vector & cPhysClsn::GetLoc() const
259 return instance.locVec;
262 ///////////////////////////////////////
264 inline const mxs_vector & cPhysClsn::GetLoc2() const
266 Assert_(type & kPC_Object);
267 return ((sPhysSubModInst *) pData)->locVec;
270 ///////////////////////////////////////
272 inline ePhysClsnResult cPhysClsn::GetResult() const
274 return result;
277 ///////////////////////////////////////
279 inline void cPhysClsn::SetResult(ePhysClsnResult _result)
281 result = _result;
284 ///////////////////////////////////////
286 inline const sPhysSubModInst & cPhysClsn::GetInstance() const
288 return instance;
291 ///////////////////////////////////////
293 inline ObjID cPhysClsn::GetObjID() const
295 return instance.objID;
298 ////////////////////////////////////////
300 inline tPhysSubModId cPhysClsn::GetSubModId() const
302 return instance.subModId;
305 ///////////////////////////////////////
307 inline cPhysModel *cPhysClsn::GetModel() const
309 return instance.pModel;
312 ///////////////////////////////////////
314 inline const sPhysSubModInst & cPhysClsn::GetInstance2() const
316 AssertObjectCollision();
317 return *(sPhysSubModInst *) pData;
320 ///////////////////////////////////////
322 inline ObjID cPhysClsn::GetObjID2() const
324 AssertObjectCollision();
325 return ((sPhysSubModInst *) pData)->objID;
328 ///////////////////////////////////////
330 inline tPhysSubModId cPhysClsn::GetSubModId2() const
332 AssertObjectCollision();
333 return ((sPhysSubModInst *) pData)->subModId;
336 ///////////////////////////////////////
338 inline cPhysModel *cPhysClsn::GetModel2() const
340 AssertObjectCollision();
341 return ((sPhysSubModInst *) pData)->pModel;
344 ////////////////////////////////////////
346 inline const mxs_vector &cPhysClsn::GetClsnPt() const
348 return clsn_pt;
351 ///////////////////////////////////////////////////////////////////////////////
353 #pragma pack()
355 #endif /* !__PHCLSN_H */