2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/physics/phystest.cpp,v 1.36 2000/02/19 12:32:29 toml Exp $
48 #include <dbmem.h> // must be last header!
50 //#define PHYS_TEST_APPLY_FORCES
51 //#define PHYS_TEST_ROTATIONAL_VELOCITY
52 #define PHYS_TEST_VELOCITY
55 BOOL
OpenPos(ObjID objID
)
57 PhysAxisControlRotationalVelocity(objID
, 2, -3);
61 BOOL
ClosePos(ObjID objID
)
63 PhysAxisControlRotationalVelocity(objID
, 2, 3);
67 void PhysicsTestRaycast(ObjID objID
)
75 CameraGetLocation(PlayerCamera(), &loc
.vec
, &ang
);
80 mx_ang2mat(&mat
, &ang
);
82 mxs_real length
= 10.0;
83 config_get_float("physcast_length", &length
);
85 mx_scale_vec(&dir
, &mat
.vec
[0], length
);
87 mx_add_vec(&end
.vec
, &loc
.vec
, &dir
);
89 MakeLocationFromVector(&loc
, &loc
.vec
);
90 MakeLocationFromVector(&end
, &end
.vec
);
92 int result
= PhysRaycast(loc
, end
, &hit
, &hit_obj
, kCollideAll
);
94 if (result
!= kCollideNone
)
96 ObjPosUpdate(objID
, &hit
.vec
, &ang
);
100 ObjPosUpdate(objID
, &end
.vec
, &ang
);
104 void PhysicsLaunchSphere(mxs_real speed
)
106 AutoAppIPtr(ObjectSystem
);
110 objID
= pObjectSystem
->Create(-506, kObjectConcrete
);
112 ObjSetCollisionType(objID
, COLLISION_BOUNCE
| COLLISION_NO_SOUND
);
113 ObjSetModelName(objID
, "wcratec");
115 ObjPosUpdate(objID
, &PlayerCamera()->pos
, &PlayerCamera()->ang
);
117 PhysDeregisterModel(objID
);
118 PhysRegisterSphereHat(objID
, 0, 1);
119 g_PhysModels
.GetActive(objID
)->SetRotAxes(XAxis
| YAxis
| ZAxis
);
120 g_PhysModels
.GetActive(objID
)->SetRestAxes(XAxis
| YAxis
| ZAxis
| NegXAxis
| NegYAxis
| NegZAxis
);
121 PhysAxisSetVelocity(objID
, 0, speed
);
123 PhysSetMass(objID
, 20);
124 PhysSetDensity(objID
, .9);
125 PhysSetElasticity(objID
, 0);
128 void PhysicsLaunchOBB(mxs_real speed
)
130 IObjectSystem
*pObjSys
= AppGetObj(IObjectSystem
);
132 objID
= pObjSys
->Create(ROOT_ARCHETYPE
, kObjectConcrete
);
133 ObjSetCollisionType(objID
, COLLISION_BOUNCE
);
134 ObjSetModelName(objID
, "table");
135 ObjPosUpdate(objID
, &(PlayerCamera()->pos
), &(PlayerCamera()->ang
));
136 PhysRegisterOBBDefault(objID
);
138 PhysAxisSetVelocity(objID
, 0, speed
);
141 void PhysicsJoyride()
143 static BOOL status
= TRUE
;
145 if (!PlayerObjectExists())
148 cPhysModel
*pModel
= g_PhysModels
.GetActive(PlayerObject());
155 pModel
->SetSpringTension(0, .8);
156 pModel
->SetSpringDamping(0, .94);
162 pModel
->SetSpringTension(0, .4);
163 pModel
->SetSpringDamping(0, .2);
169 #ifdef PHYS_TEST_VELOCITY
170 void PhysicsSetControl(mxs_real speed
)
173 cPhysCtrlData
*pCtrl
;
174 mxs_vector pos
, unit
, ctrl
;
178 if (!PhysObjHasPhysics(4))
181 CameraGetLocation(PlayerCamera(), &pos
, &ang
);
182 mx_ang2mat(&m
, &ang
);
183 mx_unit_vec(&unit
, 0);
184 mx_mat_mul_vec(&ctrl
, &m
, &unit
);
185 mx_scaleeq_vec(&ctrl
, speed
);
187 pModel
= g_PhysModels
.GetActive(4);
188 if (pModel
->IsControllable())
190 pCtrl
= pModel
->GetControls(0);
192 pCtrl
->SetControlVelocity(ctrl
);
197 void PhysicsStopControl()
199 if (!PhysObjHasPhysics(4))
202 cPhysModel
*pModel
= g_PhysModels
.GetActive(4);
203 if (pModel
->IsControllable())
205 cPhysCtrlData
*pCtrl
= pModel
->GetControls(0);
207 pCtrl
->StopControlVelocity();
212 #ifdef PHYS_TEST_APPLY_FORCES
213 void PhysicsSetControl(mxs_real speed
)
215 mxs_vector pos
, end
, force
, unit
, offset
;
223 if (!PhysObjHasPhysics(4))
226 CameraGetLocation(PlayerCamera(), &pos
, &ang
);
227 mx_ang2mat(&m
, &ang
);
228 mx_unit_vec(&unit
, 0);
229 mx_mat_mul_vec(&offset
, &m
, &unit
);
230 mx_scaleeq_vec(&offset
, speed
);
231 mx_addeq_vec(&pos
, &offset
);
233 PhysGetForceList(4, 0, &flist
, &nforces
);
234 result
= PhysApplyForceList(4, 0, NULL
, 0, .3, &pos
, &end
, &force
, &time
);
238 cPhysModel
*pModel
= g_PhysModels
.GetActive(4);
240 ObjUpdateLocation(pModel
->GetObjID(), OBJID_TO_PTR(pModel
->GetObjID()),
241 pModel
->GetLocationVec(0).x
,
242 pModel
->GetLocationVec(0).y
,
243 pModel
->GetLocationVec(0).z
);
247 PhysClearForceList(4, 0);
251 void PhysicsStopControl()
253 if (!PhysObjHasPhysics(4))
256 cPhysModel
*pModel
= g_PhysModels
.GetActive(4);
257 cPhysCtrlData
*pCtrl
= pModel
->GetControls(0);
259 pCtrl
->StopControlLocation();
264 #ifdef PHYS_TEST_ROTATIONAL_VELOCITY
265 void PhysicsSetControl(mxs_real speed
)
267 cPhysModel
*pModel
, *pModelNext
;
268 cPhysCtrlData
*pCtrl
;
269 mxs_vector rot_speed
= {speed
* rand() / 32768, speed
* rand() / 32768, speed
* rand() / 32768};
271 pModel
= g_PhysModels
.GetFirstActive();
272 while (pModel
!= NULL
)
274 pModelNext
= g_PhysModels
.GetNextActive(pModel
);
275 pCtrl
= pModel
->GetControls(0);
276 pCtrl
->SetControlRotationalVelocity(rot_speed
);
281 void PhysicsStopControl()
283 cPhysModel
*pModel
, *pModelNext
;
284 cPhysCtrlData
*pCtrl
;
286 pModel
= g_PhysModels
.GetFirstActive();
287 while (pModel
!= NULL
)
289 pModelNext
= g_PhysModels
.GetNextActive(pModel
);
290 pCtrl
= pModel
->GetControls(0);
291 pCtrl
->StopControlRotationalVelocity();
298 ///////////////////////////////////////
300 // Set debugging info for specific model/type of event
303 void PhysicsDebugObj(ObjID objID
)
305 g_PhysicsDebug
.SetDebugObj(objID
, kPhysicsDebugAll
);
308 ///////////////////////////////////////
310 void PhysicsDebug(int what
)
312 g_PhysicsDebug
.SetDebugAll(what
);