22 #if !defined(AFX_DGPHYSICSWORLD_H__EC18C699_D48D_448F_A510_A865B2CC0789__INCLUDED_) 23 #define AFX_DGPHYSICSWORLD_H__EC18C699_D48D_448F_A510_A865B2CC0789__INCLUDED_ 27 #include "dgContact.h" 28 #include "dgCollision.h" 29 #include "dgCollisionScene.h" 30 #include "dgBodyMasterList.h" 31 #include "dgWorldDynamicUpdate.h" 38 #include "dgBroadPhaseCollision.h" 43 #define DG_REDUCE_CONTACT_TOLERANCE dgFloat32 (1.0e-2f) 44 #define DG_PRUNE_CONTACT_TOLERANCE dgFloat32 (1.0e-2f) 45 #define DG_RESTING_CONTACT_PENETRATION dgFloat32 (1.0f / 256.0f) 46 #define DG_IMPULSIVE_CONTACT_PENETRATION dgFloat32 (1.0f / 256.0f + DG_RESTING_CONTACT_PENETRATION) 48 #define DG_SLEEP_ENTRIES 8 49 #define DG_MAX_DESTROYED_BODIES_BY_FORCE 8 84 enum dgPerformanceCounters {
95 m_dynamicsBuildSpanningTreeTicks,
96 m_dynamicsSolveSpanningTreeTicks,
104 typedef dgUnsigned32(dgApi *OnIslandUpdate)(
const dgWorld *
const world,
void *island, dgInt32 bodyCount);
105 typedef void (dgApi *OnDestroyCollision)(
const dgWorld *
const world,
dgCollision *shape);
106 typedef void (dgApi *OnBodyDestructionByExeciveForce)(
const dgBody *
const body,
const dgContact *joint);
110 dgFloat32 m_maxAccel;
111 dgFloat32 m_maxAlpha;
112 dgFloat32 m_maxVeloc;
113 dgFloat32 m_maxOmega;
117 DG_MSC_VECTOR_ALIGMENT
133 dgFloat32 m_force[DG_MAX_DESTROYED_BODIES_BY_FORCE];
134 const dgBody *m_bodies[DG_MAX_DESTROYED_BODIES_BY_FORCE];
135 const dgContact *m_joint[DG_MAX_DESTROYED_BODIES_BY_FORCE];
139 DG_CLASS_ALLOCATOR(allocator)
147 void SetSolverMode(dgInt32 mode);
148 void SetFrictionMode(dgInt32 mode);
149 void SetHardwareMode(dgInt32 mode);
150 dgInt32 GetHardwareMode(
char *description)
const;
152 void SetThreadsCount(dgInt32 count);
153 dgInt32 GetThreadsCount()
const;
154 dgInt32 GetMaxThreadsCount()
const;
156 void EnableThreadOnSingleIsland(dgInt32 mode);
157 dgInt32 GetThreadOnSingleIsland()
const;
161 void *GetUserData()
const;
162 void SetUserData(
void *
const userData);
164 void Update(dgFloat32 timestep);
165 void UpdateCollision();
167 dgTriplex *
const points,
dgTriplex *
const normals, dgFloat32 *
const penetration, dgInt32 maxSize, dgInt32 threadIndex);
171 dgFloat32 &timeStep,
dgTriplex *
const points,
dgTriplex *
const normals, dgFloat32 *
const penetration, dgInt32 maxSize, dgInt32 threadIndex);
174 dgFloat32 &timeStep,
dgTriplex *
const points,
dgTriplex *
const normals, dgFloat32 *
const penetration, dgInt32 maxSize, dgInt32 threadIndex);
182 void SetFrictionThreshold(dgFloat32 acceletion);
185 dgBody *GetIslandBody(
const void *
const island, dgInt32 index)
const;
188 void SetIslandUpdateCallback(OnIslandUpdate callback);
189 void SetDestroyCollisionCallback(OnDestroyCollision shape);
190 void SetLeavingWorldCallback(OnLeavingWorldAction callback);
191 void SetBodyDestructionByExeciveForce(OnBodyDestructionByExeciveForce callback);
195 void DestroyBody(
dgBody *
const body);
196 void DestroyAllBodies();
199 void AddToBreakQueue(
const dgContact *
const contactJoint,
dgBody *
const body, dgFloat32 maxForce);
206 void ApplyImpulseArray(
dgBody *body, dgInt32 count, dgInt32 strideInBytes,
const dgFloat32 *
const impulseArray,
const dgFloat32 *
const pointArray);
215 dgInt32 GetBodiesCount()
const;
216 dgInt32 GetConstraintsCount()
const;
219 dgUnsigned32 GetBoxID()
const;
220 dgUnsigned32 GetConeID()
const;
221 dgUnsigned32 GetSphereID()
const;
222 dgUnsigned32 GetConvexID()
const;
223 dgUnsigned32 GetEllipseID()
const;
224 dgUnsigned32 GetCapsuleID()
const;
225 dgUnsigned32 GetCylinderID()
const;
226 dgUnsigned32 GetConvexHullID()
const;
227 dgUnsigned32 GetChamferCylinderID()
const;
228 dgUnsigned32 GetConvexHullModifierID()
const;
229 dgUnsigned32 GetPolygonSoupID()
const;
230 dgUnsigned32 GetSceneID()
const;
231 dgUnsigned32 GetCompoundCollisionID()
const;
234 dgCollision *CreateSphere(dgFloat32 radiusdg, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
235 dgCollision *CreateCone(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
236 dgCollision *CreateCapsule(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
237 dgCollision *CreateCylinder(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
238 dgCollision *CreateBox(dgFloat32 dx, dgFloat32 dy, dgFloat32 dz, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
239 dgCollision *CreateEllipse(dgFloat32 rx, dgFloat32 ry, dgFloat32 rz, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
240 dgCollision *CreateConvexHull(dgInt32 count,
const dgFloat32 *vertexArray, dgInt32 strideInBytes, dgFloat32 tolerance, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
241 dgCollision *CreateChamferCylinder(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID,
const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
248 dgCollision *CreateCollisionCompoundBreakable(dgInt32 count,
dgMeshEffect *
const solidArray[],
const dgInt32 *
const idArray,
249 const dgFloat32 *
const densities,
const dgInt32 *
const internalFaceMaterial, dgInt32 debriID, dgFloat32 gap);
254 dgCollision *CreateBVHFieldCollision(dgInt32 width, dgInt32 height, dgInt32 contructionMode,
255 const dgUnsigned16 *
const elevationMap,
const dgInt8 *
const atributeMap, dgFloat32 horizontalScale, dgFloat32 vertcalScale);
259 void Serialize(
const dgCollision *shape, dgSerialize deserialization,
void *
const userData)
const;
260 dgCollision *CreateFromSerialization(dgDeserialize deserialization,
void *
const userData);
262 void RemoveFromCache(
dgCollision *
const collision);
263 void ReleaseCollision(
dgCollision *
const collision);
275 dgUnsigned32 CreateBodyGroupID();
276 void RemoveAllGroupID();
278 dgUnsigned32 GetDefualtBodyGroupID()
const;
279 dgContactMaterial *GetMaterial(dgUnsigned32 bodyGroupId0, dgUnsigned32 bodyGroupId1)
const;
284 OnGetPerformanceCountCallback GetPerformaceFuntion()
const ;
285 void SetPerfomanceCounter(OnGetPerformanceCountCallback callback);
288 dgUnsigned32 GetPerfomanceTicks(dgUnsigned32 entry)
const;
289 dgUnsigned32 GetThreadPerfomanceTicks(dgUnsigned32 threadIndex)
const;
291 void dgGetUserLock()
const;
292 void dgReleasedUserLock()
const;
293 void dgGetIndirectLock(dgInt32 *lockVar);
294 void dgReleaseIndirectLock(dgInt32 *lockVar);
297 dgBody *GetSentinelBody()
const;
304 void SortContacts(
dgContactPoint *
const contact, dgInt32 count)
const;
305 dgInt32 ReduceContacts(dgInt32 count,
dgContactPoint *
const contact, dgInt32 maxCount, dgFloat32 tol, dgInt32 arrayIsSorted = 0)
const;
306 dgInt32 PruneContacts(dgInt32 count,
dgContactPoint *
const contact, dgInt32 maxCount = (DG_CONSTRAINT_MAX_ROWS / 3))
const;
317 dgInt32 ValidateContactCache(
dgBody *
const convexBody,
dgBody *
const otherBody,
dgContact *
const contact)
const;
320 dgInt32 CalculatePolySoupToBoxContactsDescrete(
dgBody *soup,
dgBody *box,
dgContactPoint *
const contact, dgInt32 maxContacts)
const;
343 dgInt32 FilterPolygonEdgeContacts(dgInt32 count,
dgContactPoint *
const contact)
const;
347 void ProcessCachedContacts(
dgContact *
const contact,
const dgContactMaterial *
const material, dgFloat32 timestep, dgInt32 threadIndex)
const;
363 bool AreBodyConnectedByJoints(
dgBody *
const origin,
dgBody *
const target);
365 void AddSentinelBody();
368 static void InitConvexCollision();
369 static dgUnsigned32 dgApi GetPerformanceCount();
371 dgUnsigned32 m_dynamicsLru;
372 dgUnsigned32 m_broadPhaseLru;
373 dgUnsigned32 m_inUpdate;
374 dgUnsigned32 m_solverMode;
375 dgUnsigned32 m_frictionMode;
376 dgUnsigned32 m_bodyGroupID;
377 dgUnsigned32 m_defualtBodyGroupID;
378 dgUnsigned32 m_bodiesUniqueID;
379 dgUnsigned32 m_numberOfTheads;
380 dgUnsigned32 m_maxTheads;
383 dgFloat32 m_freezeAccel2;
384 dgFloat32 m_freezeAlpha2;
385 dgFloat32 m_freezeSpeed2;
386 dgFloat32 m_freezeOmega2;
387 dgFloat32 m_frictiomTheshold;
391 dgInt32 m_genericLRUMark;
392 dgInt32 m_islandMemorySizeInBytes;
393 dgInt32 m_bodiesMemorySizeInBytes;
394 dgInt32 m_jointsMemorySizeInBytes;
395 dgInt32 m_pairMemoryBufferSizeInBytes;
396 void *m_jointsMemory;
397 void *m_bodiesMemory;
398 void *m_islandMemory;
399 void *m_pairMemoryBuffer;
402 dgInt32 m_singleIslandMultithreading;
403 dgInt32 m_contactBuffersSizeInBytes[DG_MAXIMUN_THREADS];
404 dgInt32 m_jacobiansMemorySizeInBytes[DG_MAXIMUN_THREADS];
405 dgInt32 m_internalForcesMemorySizeInBytes[DG_MAXIMUN_THREADS];
406 void *m_jacobiansMemory[DG_MAXIMUN_THREADS];
407 void *m_internalForcesMemory[DG_MAXIMUN_THREADS];
408 void *m_contactBuffers[DG_MAXIMUN_THREADS];
416 OnIslandUpdate m_islandUpdate;
417 OnDestroyCollision m_destroyCollision;
418 OnLeavingWorldAction m_leavingWorldNotify;
419 OnGetPerformanceCountCallback m_getPerformanceCount;
420 OnBodyDestructionByExeciveForce m_destroyBodyByExeciveForce;
423 dgUnsigned32 m_perfomanceCounters[m_counterSize];
441 friend class dgParallelSolverSolve;
461 } DG_GCC_VECTOR_ALIGMENT ;
464 inline void dgWorld::dgGetUserLock()
const {
465 if (m_numberOfTheads > 1) {
466 m_threadsManager.dgGetLock();
470 inline void dgWorld::dgReleasedUserLock()
const {
471 if (m_numberOfTheads > 1) {
472 m_threadsManager.dgReleaseLock();
477 inline void dgWorld::dgGetIndirectLock(dgInt32 *lockVar) {
478 m_threadsManager.dgGetIndirectLock(lockVar);
481 inline void dgWorld::dgReleaseIndirectLock(dgInt32 *lockVar) {
482 m_threadsManager.dgReleaseIndirectLock(lockVar);
489 inline void dgWorld::AddToBreakQueue(
const dgContact *
const contactJoint,
dgBody *
const body, dgFloat32 maxForce) {
491 if (m_destroyeddBodiesPool.m_count < DG_MAX_DESTROYED_BODIES_BY_FORCE) {
492 if (body->m_isInDerstruionArrayLRU != body->m_dynamicsLru) {
493 body->m_isInDerstruionArrayLRU = body->m_dynamicsLru;
494 m_destroyeddBodiesPool.m_force[m_destroyeddBodiesPool.m_count] = maxForce;
495 m_destroyeddBodiesPool.m_bodies[m_destroyeddBodiesPool.m_count] = body;
496 m_destroyeddBodiesPool.m_joint[m_destroyeddBodiesPool.m_count] = contactJoint;
497 m_destroyeddBodiesPool.m_count ++;
499 for (dgInt32 i = 0; i < m_destroyeddBodiesPool.m_count; i ++) {
500 if (m_destroyeddBodiesPool.m_bodies[i] == body) {
501 if (maxForce > m_destroyeddBodiesPool.m_force[i]) {
502 m_destroyeddBodiesPool.m_force[i] = maxForce;
503 m_destroyeddBodiesPool.m_joint[i] = contactJoint;
521 #endif // !defined(AFX_DGPHYSICSWORLD_H__EC18C699_D48D_448F_A510_A865B2CC0789__INCLUDED_) Definition: dgWorldDynamicUpdate.h:226
Definition: dgWorldDynamicUpdate.h:129
Definition: dgWorldDynamicUpdate.h:101
Definition: dgWorldDynamicUpdate.h:143
Definition: dgContact.h:51
Definition: dgBodyMasterList.h:56
Definition: dgBroadPhaseCollision.h:170
Definition: dgWorldDynamicUpdate.h:239
Definition: dgCollisionUserMesh.h:37
Definition: dgWorldDynamicUpdate.h:282
Definition: dgVector.h:86
Definition: dgCorkscrewConstraint.h:32
Definition: dgBroadPhaseCollision.h:66
Definition: dgBroadPhaseCollision.h:136
Definition: dgWorld.h:108
Definition: dgWorldDynamicUpdate.h:158
Definition: dgBallConstraint.h:32
Definition: dgWorldDynamicUpdate.h:203
Definition: dgUserConstraint.h:30
Definition: dgMeshEffect.h:78
Definition: dgBroadPhaseCollision.h:158
Definition: dgWorldDynamicUpdate.h:168
Definition: dgWorldDynamicUpdate.h:342
Definition: dgHingeConstraint.h:32
Definition: dgWorldDynamicUpdate.h:117
Definition: dgWorldDynamicUpdate.h:188
Definition: dgWorld.h:127
Definition: dgWorldDynamicUpdate.h:257
Definition: dgCollisionScene.h:29
Definition: dgCollisionConvex.h:39
Definition: dgUpVectorConstraint.h:32
Definition: dgSlidingConstraint.h:31
Definition: dgCollisionHeightField.h:32
Definition: dgCollisionScene.h:47
Definition: dgCollision.h:178
Definition: dgMatrix.h:41
Definition: dgMemory.h:80
Definition: dgBroadPhaseCollision.h:124
Definition: dgUniversalConstraint.h:32
Definition: dgConstraint.h:169
Definition: dgWorld.h:118
Definition: dgCollisionSphere.h:78
Definition: dgThreads.h:40
Definition: dgContact.h:53
Definition: dgCollisionCompound.h:31
Definition: dgContact.h:102