2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/physics/phclsn.h,v 1.18 2000/01/29 13:32:38 adurant Exp $
23 typedef struct sSphrContactData sSphrContactData
;
25 class cPhysSphereModel
;
28 ///////////////////////////////////////////////////////////////////////////////
31 // Result of a collision
33 enum ePhysClsnResultEnum
49 ///////////////////////////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////////////////////////
73 typedef cDList
<cPhysClsn
, 0> cPhysClsnsBase
;
74 typedef cDListNode
<cPhysClsn
, 0> cPhysClsnNodeBase
;
76 ///////////////////////////////////////////////////////////////////////////////
78 // STRUCT: sPhysClsnTerr
80 // describes terrain for a collision
85 cPhysTerrPolyList m_polyList
;
86 mxs_vector m_normal
; // computed normal of polys
89 ///////////////////////////////////////////////////////////////////////////////
93 // Instance of a collision, implemented as a struct so we can (eventually)
100 ePhysClsnResult result
;
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
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
);
143 ////////////////////////////////////
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;
178 void MonoPrint() const;
182 #define AssertObjectCollision() Assert_(type & kPC_Object)
183 void CreateTerrainInfo(ePhysClsnType type
,
184 sSphrContactData
* pContactData
,
185 cPhysTerrPolyList
* pList
);
186 void GenerateClsnPt();
189 ///////////////////////////////////////////////////////////////////////////////
193 // List of collisions
196 class cPhysClsns
: public cPhysClsnsBase
199 void New(const cPhysModel
* pModel
,
200 tPhysSubModId subModId
,
202 const Location
& hitLoc
,
203 const mxs_vector
* pNormals
);
204 void Insert(cPhysClsn
* pClsn
);
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
234 ///////////////////////////////////////
236 inline mxs_real
cPhysClsn::GetTime() const
241 ///////////////////////////////////////
243 inline mxs_real
cPhysClsn::GetT0() const
248 ///////////////////////////////////////
250 inline mxs_real
cPhysClsn::GetDT() const
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
277 ///////////////////////////////////////
279 inline void cPhysClsn::SetResult(ePhysClsnResult _result
)
284 ///////////////////////////////////////
286 inline const sPhysSubModInst
& cPhysClsn::GetInstance() const
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
351 ///////////////////////////////////////////////////////////////////////////////
355 #endif /* !__PHCLSN_H */