My Project: dynamics.mod/NewtonDynamics/source/physics/dgBroadPhase.h Source File

My Project

dgBroadPhase.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef __AFX_BROADPHASE_H_
23 #define __AFX_BROADPHASE_H_
24
25 #include "dgPhysicsStdafx.h"
26
27
28 class dgBody;
29 class dgWorld;
30 class dgContact;
31 class dgCollision;
32 class dgCollisionInstance;
33 class dgBroadphaseSyncDescriptor;
34
35 typedef dgInt32 (dgApi *OnBodiesInAABB) (dgBody* body, void* const userData);
36 typedef dgUnsigned32 (dgApi *OnRayPrecastAction) (const dgBody* const body, const dgCollisionInstance* const collision, void* const userData);
37 typedef dgFloat32 (dgApi *OnRayCastAction) (const dgBody* const body, const dgCollisionInstance* const collision, const dgVector& contact, const dgVector& normal, dgInt64 collisionID, void* const userData, dgFloat32 intersetParam);
38
39
40 #define DG_CACHE_DIST_TOL dgFloat32 (1.0e-3f)
41
42 DG_MSC_VECTOR_ALIGMENT
43 struct dgLineBox
44 {
45 dgVector m_l0;
46 dgVector m_l1;
47 dgVector m_boxL0;
48 dgVector m_boxL1;
49 } DG_GCC_VECTOR_ALIGMENT;
50
51
52 class dgConvexCastReturnInfo
53 {
54 public:
55 dgFloat32 m_point[4]; // collision point in global space
56 dgFloat32 m_normal[4]; // surface normal at collision point in global space
57 //dgFloat32 m_normalOnHitPoint[4]; // surface normal at the surface of the hit body,
58 // is the same as the normal calculate by a raycast passing by the hit point in the direction of the cast
59 dgInt64 m_contaID; // collision ID at contact point
60 const dgBody* m_hitBody; // body hit at contact point
61 dgFloat32 m_penetration; // contact penetration at collision point
62 };
63
64
65 class dgBroadPhase
66 {
67 public:
68 DG_CLASS_ALLOCATOR(allocator);
69
70 enum dgType
71 {
72 m_generic = 0,
73 m_persistent,
74 };
75
76 class dgNode;
77 class dgSpliteInfo;
78
79 dgBroadPhase(dgWorld* const world);
80 virtual ~dgBroadPhase();
81
82 dgUnsigned32 GetLRU () const;
83 void GetWorldSize (dgVector& p0, dgVector& p1) const;
84 void RayCast (const dgVector& p0, const dgVector& p1, OnRayCastAction filter, OnRayPrecastAction prefilter, void* const userData) const;
85 void ConvexRayCast (dgCollisionInstance* const shape, const dgMatrix& matrx, const dgVector& p1, OnRayCastAction filter, OnRayPrecastAction prefilter, void* const userData, dgInt32 threadId) const;
86
87 dgInt32 ConvexCast (dgCollisionInstance* const shape, const dgMatrix& p0, const dgVector& p1, dgFloat32& timetoImpact, OnRayPrecastAction prefilter, void* const userData, dgConvexCastReturnInfo* const info, dgInt32 maxContacts, dgInt32 threadIndex) const;
88 void ForEachBodyInAABB (const dgVector& q0, const dgVector& q1, OnBodiesInAABB callback, void* const userData) const;
89
90 dgInt32 GetBroadPhaseType () const;
91 void SelectBroadPhaseType (dgInt32 algorthmType);
92
93 void ResetEntropy ();
94
95 protected:
96 class dgFitnessList: public dgList <dgNode*>
97 {
98 public:
99 dgFitnessList (dgMemoryAllocator* const allocator);
100 dgFloat64 TotalCost () const;
101 };
102
103 void Add (dgBody* const body);
104 void Remove (dgBody* const body);
105 void InvalidateCache ();
106 void UpdateContacts (dgFloat32 timestep);
107 void AddInternallyGeneratedBody(dgBody* const body);
108 void UpdateBodyBroadphase(dgBody* const body, dgInt32 threadIndex);
109
110 void ImproveFitness();
111 void ImproveNodeFitness (dgNode* const node);
112 dgNode* InsertNode (dgNode* const node);
113 dgFloat32 CalculateSurfaceArea (const dgNode* const node0, const dgNode* const node1, dgVector& minBox, dgVector& maxBox) const;
114
115 void AddPair (dgBody* const body0, dgBody* const body1, const dgVector& timestep2, dgInt32 threadID);
116
117 static void ForceAndToqueKernel (void* const descriptor, void* const worldContext, dgInt32 threadID);
118 static void CollidingPairsKernel (void* const descriptor, void* const worldContext, dgInt32 threadID);
119 static void UpdateContactsKernel (void* const descriptor, void* const worldContext, dgInt32 threadID);
120 // static void UpdateSoftBodyForcesKernel (void* const descriptor, void* const worldContext, dgInt32 threadID);
121 static void AddGeneratedBodyesContactsKernel (void* const descriptor, void* const worldContext, dgInt32 threadID);
122
123 void UpdateContactsBroadPhaseEnd ();
124 void ApplyForceAndtorque (dgBroadphaseSyncDescriptor* const desctiptor, dgInt32 threadID);
125 void ApplyDeformableForceAndtorque (dgBroadphaseSyncDescriptor* const desctiptor, dgInt32 threadID);
126 void CalculatePairContacts (dgBroadphaseSyncDescriptor* const descriptor, dgInt32 threadID);
127 // void UpdateSoftBodyForcesKernel (dgBroadphaseSyncDescriptor* const descriptor, dgInt32 threadID);
128
129 dgNode* BuildTopDown (dgNode** const leafArray, dgInt32 firstBox, dgInt32 lastBox, dgFitnessList::dgListNode** const nextNode);
130
131 void FindCollidingPairsGeneric (dgBroadphaseSyncDescriptor* const desctiptor, dgInt32 threadID);
132 void FindCollidingPairsPersistent (dgBroadphaseSyncDescriptor* const desctiptor, dgInt32 threadID);
133 void SubmitPairsPersistent (dgNode* const body, dgNode* const node, const dgVector& timeStepBound, dgInt32 threadID);
134
135 void FindGeneratedBodiesCollidingPairs (dgBroadphaseSyncDescriptor* const desctiptor, dgInt32 threadID);
136
137 void KinematicBodyActivation (dgContact* const contatJoint) const;
138
139 bool TestOverlaping (const dgBody* const body0, const dgBody* const body1) const;
140 dgFloat64 CalculateEmptropy ();
141
142 dgWorld* m_world;
143 dgNode* m_rootNode;
144 dgFloat64 m_treeEntropy;
145 dgUnsigned32 m_lru;
146 dgFitnessList m_fitness;
147 dgList<dgBody*> m_generatedBodies;
148 dgType m_broadPhaseType;
149 dgThread::dgCriticalSection m_contacJointLock;
150 dgThread::dgCriticalSection m_criticalSectionLock;
151 bool m_recursiveChunks;
152
153 static dgVector m_conservativeRotAngle;
154 friend class dgBody;
155 friend class dgWorld;
156 friend class dgWorldDynamicUpdate;
157 friend class dgCollisionCompoundFractured;
158 };
159 #endif
dgApi
#define dgApi
Definition: dgTypes.h:263
dgInt64
long long dgInt64
Definition: dgTypes.h:222
dgContact
Definition: dgContact.h:195
dgLineBox
Definition: dgBroadPhase.h:43
OnRayCastAction
dgFloat32(dgApi * OnRayCastAction)(const dgBody *const body, const dgCollisionInstance *const collision, const dgVector &contact, const dgVector &normal, dgInt64 collisionID, void *const userData, dgFloat32 intersetParam)
Definition: dgBroadPhase.h:37
dgLineBox::m_l1
dgVector m_l1
Definition: dgBroadPhase.h:46
dgBroadPhase::m_generatedBodies
dgList< dgBody * > m_generatedBodies
Definition: dgBroadPhase.h:147
dgBroadPhase::dgSpliteInfo
Definition: dgBroadPhase.cpp:285
dgBody
Definition: dgBody.h:44
userData
void *const userData
Definition: dgBroadPhase.h:35
dgBroadPhase::dgType
dgType
Definition: dgBroadPhase.h:70
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgVector
Definition: dgVector.h:639
dgCollisionCompoundFractured
Definition: dgCollisionCompoundFractured.h:32
dgConvexCastReturnInfo::m_contaID
dgInt64 m_contaID
Definition: dgBroadPhase.h:59
dgBroadPhase::m_recursiveChunks
bool m_recursiveChunks
Definition: dgBroadPhase.h:151
dgConvexCastReturnInfo
Definition: dgBroadPhase.h:52
dgBroadPhase::m_criticalSectionLock
dgThread::dgCriticalSection m_criticalSectionLock
Definition: dgBroadPhase.h:150
DG_CLASS_ALLOCATOR
#define DG_CLASS_ALLOCATOR(allocator)
Definition: dgMemory.h:60
dgFloat64
double dgFloat64
Definition: dgTypes.h:224
dgList
Definition: dgList.h:33
dgLineBox::m_boxL0
dgVector m_boxL0
Definition: dgBroadPhase.h:47
dgBroadPhase::m_world
dgWorld * m_world
Definition: dgBroadPhase.h:142
dgWorldDynamicUpdate
Definition: dgWorldDynamicUpdate.h:252
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgBroadPhase::m_rootNode
dgNode * m_rootNode
Definition: dgBroadPhase.h:143
dgBroadPhase
Definition: dgBroadPhase.h:65
dgBroadPhase::m_fitness
dgFitnessList m_fitness
Definition: dgBroadPhase.h:146
dgBroadPhase::m_broadPhaseType
dgType m_broadPhaseType
Definition: dgBroadPhase.h:148
OnRayPrecastAction
dgUnsigned32(dgApi * OnRayPrecastAction)(const dgBody *const body, const dgCollisionInstance *const collision, void *const userData)
Definition: dgBroadPhase.h:36
dgLineBox::m_l0
dgVector m_l0
Definition: dgBroadPhase.h:45
dgBroadPhase::m_persistent
Definition: dgBroadPhase.h:73
dgInt32
typedef dgInt32(dgApi *OnBodiesInAABB)(dgBody *body
dgCollisionInstance
Definition: dgCollisionInstance.h:30
dgConvexCastReturnInfo::m_hitBody
const dgBody * m_hitBody
Definition: dgBroadPhase.h:60
dgBroadPhase::dgNode
Definition: dgBroadPhase.cpp:43
dgBroadPhase::m_conservativeRotAngle
static dgVector m_conservativeRotAngle
Definition: dgBroadPhase.h:153
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
DG_GCC_VECTOR_ALIGMENT
DG_MSC_VECTOR_ALIGMENT struct dgLineBox DG_GCC_VECTOR_ALIGMENT
threadIndex
dgFloat32 dgInt32 threadIndex
Definition: dgConstraint.h:44
timestep
dgFloat32 timestep
Definition: dgBallConstraint.h:34
dgBroadPhase::dgFitnessList
Definition: dgBroadPhase.h:96
dgCollision
Definition: dgCollision.h:217
dgBroadPhase::m_lru
dgUnsigned32 m_lru
Definition: dgBroadPhase.h:145
dgBroadphaseSyncDescriptor
Definition: dgBroadPhase.cpp:159
dgLineBox::m_boxL1
dgVector m_boxL1
Definition: dgBroadPhase.h:48
dgMatrix
Definition: dgMatrix.h:40
dgMemoryAllocator
Definition: dgMemory.h:73
dgBroadPhase::m_treeEntropy
dgFloat64 m_treeEntropy
Definition: dgBroadPhase.h:144
dgPhysicsStdafx.h
dgWorld
Definition: dgWorld.h:129
dgThread::dgCriticalSection
Definition: dgThread.h:35
dgConvexCastReturnInfo::m_penetration
dgFloat32 m_penetration
Definition: dgBroadPhase.h:61
dgBroadPhase::m_contacJointLock
dgThread::dgCriticalSection m_contacJointLock
Definition: dgBroadPhase.h:149