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

My Project

dgCollisionCompoundFractured.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 DG_COLLISION_COMPOUND_FRACTURED_H
23 #define DG_COLLISION_COMPOUND_FRACTURED_H
24
25 #include "dgCollisionCompound.h"
26
27
28 class dgMeshEffect;
29
30
31
32 class dgCollisionCompoundFractured: public dgCollisionCompound
33 {
34 class dgFractureBuilder;
35
36 public:
37 class dgFlatVertex
38 {
39 public:
40 dgFloat32 m_point[10]; // 3 point, 3 normal. 2 uv0, 2 uv1
41 };
42
43 class dgFlatVertexArray: public dgArray<dgFlatVertex>
44 {
45 public:
46 dgFlatVertexArray(dgMemoryAllocator* const allocator)
47 :dgArray<dgFlatVertex> (1024 * 4, allocator)
48 {
49 m_count = 0;
50 }
51
52 dgInt32 m_count;
53 };
54
55 class dgVertexBuffer: public dgRefCounter
56 {
57 public:
58 DG_CLASS_ALLOCATOR(allocator)
59 dgVertexBuffer (dgInt32 count, dgMemoryAllocator* allocator);
60 dgVertexBuffer (dgMemoryAllocator* const allocator, dgDeserialize deserialization, void* const userData);
61 ~dgVertexBuffer ();
62
63 void Serialize(dgSerialize callback, void* const userData) const;
64 const dgFloat32* GetVertexPositions() const {return m_vertex;};
65 const dgFloat32* GetVertexNormals() const {return m_normal;};
66 const dgFloat32* GetVertexUVs() const {return m_uv;};
67
68 dgFloat32 *m_uv;
69 dgFloat32 *m_vertex;
70 dgFloat32 *m_normal;
71 dgMemoryAllocator* m_allocator;
72 dgInt32 m_vertexCount;
73 };
74
75 class dgSubMesh
76 {
77 public:
78 dgSubMesh (dgMemoryAllocator* const allocator);
79 ~dgSubMesh ();
80 void Serialize(dgSerialize callback, void* const userData) const;
81
82 dgInt32 *m_indexes;
83 dgMemoryAllocator* m_allocator;
84 dgInt32 m_material;
85 dgInt32 m_faceCount;
86 dgInt32 m_materialOrdinal;
87 bool m_visibleFaces;
88 };
89
90 class dgMesh: public dgList<dgSubMesh>, public dgRefCounter
91 {
92 public:
93 dgMesh(dgMemoryAllocator* const allocator);
94 dgMesh (dgMemoryAllocator* const allocator, dgDeserialize deserialization, void* const userData);
95 ~dgMesh();
96 void Serialize (dgSerialize callback, void* const userData) const;
97 dgSubMesh* AddgSubMesh (dgInt32 indexCount, dgInt32 material);
98
99 dgInt32 m_vertexOffsetStart;
100 dgInt32 m_vertexCount;
101 bool m_isVisible;
102 };
103
104 class dgDebriNodeInfo
105 {
106 public:
107 dgDebriNodeInfo ();
108 ~dgDebriNodeInfo ();
109
110 dgMesh* m_mesh;
111 dgTreeArray::dgTreeNode* m_shapeNode;
112 dgInt32 m_lru;
113 };
114
115
116 class dgSharedNodeMesh
117 {
118 public:
119 dgSharedNodeMesh ();
120 ~dgSharedNodeMesh ();
121 dgVector m_normal;
122 };
123
124 class dgConectivityGraph: public dgGraph<dgDebriNodeInfo, dgSharedNodeMesh>
125 {
126 public:
127 dgConectivityGraph (dgMemoryAllocator* const allocator);
128 dgConectivityGraph (const dgConectivityGraph& source);
129 ~dgConectivityGraph ();
130
131 dgListNode* AddNode (dgFlatVertexArray& vertexArray, dgMeshEffect* const factureVisualMesh, dgTreeArray::dgTreeNode* const collisionNode, dgInt32 interiorMaterialBase);
132 void Serialize(dgSerialize callback, void* const userData) const;
133 void Deserialize (dgCollisionCompoundFractured* const source, dgDeserialize callback, void* const userData);
134 };
135
136 class dgConectivityGraphMap: public dgTree<dgConectivityGraph::dgListNode*, const dgCollisionInstance*>
137 {
138 public:
139 dgConectivityGraphMap (const dgConectivityGraphMap& source)
140 :dgTree<dgConectivityGraph::dgListNode*, const dgCollisionInstance*>(source.GetAllocator())
141 {
142 }
143
144 dgConectivityGraphMap (dgMemoryAllocator* const allocator)
145 :dgTree<dgConectivityGraph::dgListNode*, const dgCollisionInstance*>(allocator)
146 {
147 }
148
149 void Pupolate(const dgConectivityGraph& graph)
150 {
151 for (dgConectivityGraph::dgListNode* node = graph.GetFirst(); node != graph.GetLast(); node = node->GetNext() ) {
152 dgDebriNodeInfo& nodeInfo = node->GetInfo().m_nodeData;
153 Insert(node, nodeInfo.m_shapeNode->GetInfo()->GetShape());
154 }
155 }
156 };
157
158 public:
159 typedef void (*OnEmitNewCompundFractureCallBack) (dgBody* const body);
160 typedef void (*OnEmitFractureChunkCallBack) (dgBody* const body, dgConectivityGraph::dgListNode* const chunkMeshNode, const dgCollisionInstance* const myInstance);
161 typedef void (*OnReconstructFractureMainMeshCallBack) (dgBody* const body, dgConectivityGraph::dgListNode* const mainMeshNode, const dgCollisionInstance* const myInstance);
162
163 dgCollisionCompoundFractured (const dgCollisionCompoundFractured& source, const dgCollisionInstance* const myInstance);
164 dgCollisionCompoundFractured (dgCollisionCompoundFractured& source, const dgList<dgConectivityGraph::dgListNode*>& island);
165 dgCollisionCompoundFractured (dgWorld* const world, dgMeshEffect* const solidMesh, dgInt32 fracturePhysicsMaterialID, int pointcloudCount, const dgFloat32* const vertexCloud, int strideInBytes, int materialID, const dgMatrix& offsetMatrix,
166 OnEmitFractureChunkCallBack emitFracturedChunk, OnEmitNewCompundFractureCallBack emitNewCompoundFactured, OnReconstructFractureMainMeshCallBack reconstructMainMesh);
167
168 dgCollisionCompoundFractured (dgWorld* const world, dgDeserialize deserialization, void* const userData, const dgCollisionInstance* const myInstance);
169 virtual ~dgCollisionCompoundFractured(void);
170
171 void SetCallbacks(OnEmitFractureChunkCallBack emitFracturedChunk, OnEmitNewCompundFractureCallBack emitNewCompoundFactured, OnReconstructFractureMainMeshCallBack reconstructMainMesh);
172
173 dgConectivityGraph::dgListNode* GetMainMesh() const;
174 dgConectivityGraph::dgListNode* GetFirstMesh() const;
175 dgConectivityGraph::dgListNode* GetNextMesh(dgConectivityGraph::dgListNode* const mesh) const;
176
177 dgInt32 GetVertecCount(dgConectivityGraph::dgListNode* const node) const;
178 const dgFloat32* GetVertexPositions (dgConectivityGraph::dgListNode* const node) const;
179 const dgFloat32* GetVertexNormal (dgConectivityGraph::dgListNode* const node) const;
180 const dgFloat32* GetVertexUVs (dgConectivityGraph::dgListNode* const node) const;
181 dgInt32 GetSegmentIndexStream (dgConectivityGraph::dgListNode* const node, dgMesh::dgListNode* const segment, dgInt32* const index) const;
182
183 void SetImpulseStrength(dgFloat32 impulseStrength);
184 dgFloat32 GetImpulseStrength() const;
185
186 void SetImpulsePropgationFactor(dgFloat32 factor);
187 dgFloat32 GetSetImpulsePropgationFactor() const;
188
189 virtual void BeginAddRemove ();
190 virtual void RemoveCollision (dgTreeArray::dgTreeNode* const node);
191 virtual void EndAddRemove ();
192 bool IsNodeSaseToDetach (dgTreeArray::dgTreeNode* const node) const;
193
194 int GetFirstNiegborghArray (dgTreeArray::dgTreeNode* const node, dgTreeArray::dgTreeNode** const nodesArray, int maxCount) const;
195
196 dgCollisionCompoundFractured* PlaneClip (const dgVector& plane);
197
198 private:
199 void BuildMainMeshSubMehes() const;
200 dgVector GetObbSize() const;
201
202 virtual void Serialize(dgSerialize callback, void* const userData) const;
203 virtual void CalcAABB (const dgMatrix& matrix, dgVector& p0, dgVector& p1) const;
204 dgInt32 CalculateContacts (dgCollidingPairCollector::dgPair* const pair, dgCollisionParamProxy& proxy) const;
205
206 void ColorDisjoinChunksIsland ();
207 bool SpawnChunks (dgBody* const myBody, const dgCollisionInstance* const myInstance, dgConectivityGraph::dgListNode* const rootNode, dgFloat32 impulseStimate2, dgFloat32 impulseStimateCut2);
208 void SpawnDisjointChunks (dgBody* const myBody, const dgCollisionInstance* const myInstance, dgConectivityGraph::dgListNode* const rootNode, dgFloat32 impulseStimate2, dgFloat32 impulseStimateCut2);
209
210 void SpawnSingleChunk (dgBody* const myBody, const dgCollisionInstance* const myInstance, dgConectivityGraph::dgListNode* const chunkNode);
211 void SpawnComplexChunk (dgBody* const myBody, const dgCollisionInstance* const myInstance, dgConectivityGraph::dgListNode* const chunkNode);
212 bool CanChunk (dgConectivityGraph::dgListNode* const node) const;
213
214 bool SanityCheck() const;
215
216 inline bool IsAbovePlane (dgConectivityGraph::dgListNode* const node, const dgVector& plane) const;
217 inline bool IsBelowPlane (dgConectivityGraph::dgListNode* const node, const dgVector& plane) const;
218 inline dgConectivityGraph::dgListNode* FirstAcrossPlane (dgConectivityGraph::dgListNode* const node, const dgVector& plane) const;
219
220 dgConectivityGraph m_conectivity;
221 dgConectivityGraphMap m_conectivityMap;
222 dgVertexBuffer* m_vertexBuffer;
223 dgFloat32 m_impulseStrengthPerUnitMass;
224 dgFloat32 m_impulseAbsortionFactor;
225 dgFloat32 m_density;
226 dgInt32 m_lru;
227 dgInt32 m_materialCount;
228 OnEmitFractureChunkCallBack m_emitFracturedChunk;
229 OnEmitNewCompundFractureCallBack m_emitFracturedCompound;
230 OnReconstructFractureMainMeshCallBack m_reconstructMainMesh;
231 };
232 #endif
dgList< dgGraphNode< dgDebriNodeInfo, dgSharedNodeMesh > >::dgListNode
friend class dgListNode
Definition: dgList.h:249
dgCollisionCompoundFractured::dgFlatVertex
Definition: dgCollisionCompoundFractured.h:37
dgCollisionCompoundFractured::dgDebriNodeInfo::m_lru
dgInt32 m_lru
Definition: dgCollisionCompoundFractured.h:112
dgCollisionCompoundFractured::OnReconstructFractureMainMeshCallBack
void(* OnReconstructFractureMainMeshCallBack)(dgBody *const body, dgConectivityGraph::dgListNode *const mainMeshNode, const dgCollisionInstance *const myInstance)
Definition: dgCollisionCompoundFractured.h:161
dgCollisionCompoundFractured::BeginAddRemove
virtual void BeginAddRemove()
Definition: dgCollisionCompoundFractured.cpp:1311
dgCollidingPairCollector::dgPair
Definition: dgContact.h:52
dgCollisionCompoundFractured::dgSubMesh::m_visibleFaces
bool m_visibleFaces
Definition: dgCollisionCompoundFractured.h:87
dgCollisionCompoundFractured::dgVertexBuffer::m_vertexCount
dgInt32 m_vertexCount
Definition: dgCollisionCompoundFractured.h:72
dgCollisionCompoundFractured::dgConectivityGraphMap::Pupolate
void Pupolate(const dgConectivityGraph &graph)
Definition: dgCollisionCompoundFractured.h:149
dgCollisionCompoundFractured::dgSubMesh::m_material
dgInt32 m_material
Definition: dgCollisionCompoundFractured.h:84
dgCollisionCompoundFractured::dgSubMesh::m_allocator
dgMemoryAllocator * m_allocator
Definition: dgCollisionCompoundFractured.h:83
dgGraph
Definition: dgGraph.h:40
dgCollisionCompoundFractured::SetCallbacks
void SetCallbacks(OnEmitFractureChunkCallBack emitFracturedChunk, OnEmitNewCompundFractureCallBack emitNewCompoundFactured, OnReconstructFractureMainMeshCallBack reconstructMainMesh)
Definition: dgCollisionCompoundFractured.cpp:1097
dgCollisionCompoundFractured::dgConectivityGraphMap::dgConectivityGraphMap
dgConectivityGraphMap(const dgConectivityGraphMap &source)
Definition: dgCollisionCompoundFractured.h:139
dgBody
Definition: dgBody.h:44
userData
void *const userData
Definition: dgBroadPhase.h:35
dgTree< dgNodeBase *, dgInt32 >::dgTreeNode
friend class dgTreeNode
Definition: dgTree.h:291
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
void
typedef void(dgApi *ConstraintsForceFeeback)(const dgConstraint &me
dgCollisionCompoundFractured::dgFlatVertexArray::dgFlatVertexArray
dgFlatVertexArray(dgMemoryAllocator *const allocator)
Definition: dgCollisionCompoundFractured.h:46
dgCollisionCompoundFractured::dgSharedNodeMesh
Definition: dgCollisionCompoundFractured.h:116
dgCollisionCompoundFractured::dgSharedNodeMesh::m_normal
dgVector m_normal
Definition: dgCollisionCompoundFractured.h:121
dgVector
Definition: dgVector.h:639
dgCollisionCompoundFractured
Definition: dgCollisionCompoundFractured.h:32
dgCollisionCompoundFractured::dgSubMesh
Definition: dgCollisionCompoundFractured.h:75
dgCollisionCompoundFractured::GetVertexUVs
const dgFloat32 * GetVertexUVs(dgConectivityGraph::dgListNode *const node) const
Definition: dgCollisionCompoundFractured.cpp:1210
dgCollisionCompoundFractured::dgFlatVertexArray::m_count
dgInt32 m_count
Definition: dgCollisionCompoundFractured.h:52
dgRefCounter
Definition: dgRefCounter.h:25
dgCollisionCompoundFractured::OnEmitFractureChunkCallBack
void(* OnEmitFractureChunkCallBack)(dgBody *const body, dgConectivityGraph::dgListNode *const chunkMeshNode, const dgCollisionInstance *const myInstance)
Definition: dgCollisionCompoundFractured.h:160
dgCollisionCompoundFractured::GetVertexPositions
const dgFloat32 * GetVertexPositions(dgConectivityGraph::dgListNode *const node) const
Definition: dgCollisionCompoundFractured.cpp:1196
dgCollisionCompoundFractured::OnEmitNewCompundFractureCallBack
void(* OnEmitNewCompundFractureCallBack)(dgBody *const body)
Definition: dgCollisionCompoundFractured.h:159
dgCollisionCompoundFractured::GetImpulseStrength
dgFloat32 GetImpulseStrength() const
Definition: dgCollisionCompoundFractured.cpp:1230
DG_CLASS_ALLOCATOR
#define DG_CLASS_ALLOCATOR(allocator)
Definition: dgMemory.h:60
dgCollisionCompoundFractured::SetImpulsePropgationFactor
void SetImpulsePropgationFactor(dgFloat32 factor)
Definition: dgCollisionCompoundFractured.cpp:1235
dgCollisionCompoundFractured::GetSetImpulsePropgationFactor
dgFloat32 GetSetImpulsePropgationFactor() const
Definition: dgCollisionCompoundFractured.cpp:1240
dgList
Definition: dgList.h:33
dgMeshEffect
Definition: dgMeshEffect.h:45
dgList::GetLast
dgListNode * GetLast() const
Definition: dgList.h:313
dgCollisionCompoundFractured::GetNextMesh
dgConectivityGraph::dgListNode * GetNextMesh(dgConectivityGraph::dgListNode *const mesh) const
Definition: dgCollisionCompoundFractured.cpp:1185
dgSerialize
void(dgApi * dgSerialize)(void *const userData, const void *const buffer, size_t size)
Definition: dgTypes.h:280
dgTree
Definition: dgTree.h:88
dgCollisionCompoundFractured::dgFlatVertexArray
Definition: dgCollisionCompoundFractured.h:43
dgCollisionCompoundFractured::dgSubMesh::m_materialOrdinal
dgInt32 m_materialOrdinal
Definition: dgCollisionCompoundFractured.h:86
dgCollisionCompoundFractured::~dgCollisionCompoundFractured
virtual ~dgCollisionCompoundFractured(void)
Definition: dgCollisionCompoundFractured.cpp:1078
dgCollisionCompoundFractured::dgFlatVertex::m_point
dgFloat32 m_point[10]
Definition: dgCollisionCompoundFractured.h:40
dgCollisionCompoundFractured::dgVertexBuffer::m_uv
dgFloat32 * m_uv
Definition: dgCollisionCompoundFractured.h:66
dgDeserialize
void(dgApi * dgDeserialize)(void *const userData, void *buffer, size_t size)
Definition: dgTypes.h:279
dgCollisionCompoundFractured::dgMesh::m_vertexCount
dgInt32 m_vertexCount
Definition: dgCollisionCompoundFractured.h:100
dgCollisionCompoundFractured::SetImpulseStrength
void SetImpulseStrength(dgFloat32 impulseStrength)
Definition: dgCollisionCompoundFractured.cpp:1225
dgArray
Definition: dgArray.h:33
dgCollisionCompoundFractured::dgVertexBuffer::GetVertexPositions
const dgFloat32 * GetVertexPositions() const
Definition: dgCollisionCompoundFractured.h:64
dgCollisionCompoundFractured::dgCollisionCompoundFractured
dgCollisionCompoundFractured(const dgCollisionCompoundFractured &source, const dgCollisionInstance *const myInstance)
Definition: dgCollisionCompoundFractured.cpp:864
dgCollisionCompound.h
dgCollisionCompoundFractured::dgMesh
Definition: dgCollisionCompoundFractured.h:90
dgCollisionInstance
Definition: dgCollisionInstance.h:30
dgCollisionCompoundFractured::EndAddRemove
virtual void EndAddRemove()
Definition: dgCollisionCompoundFractured.cpp:1316
dgCollisionCompoundFractured::dgConectivityGraphMap::dgConectivityGraphMap
dgConectivityGraphMap(dgMemoryAllocator *const allocator)
Definition: dgCollisionCompoundFractured.h:144
dgCollisionCompoundFractured::dgDebriNodeInfo::m_shapeNode
dgTreeArray::dgTreeNode * m_shapeNode
Definition: dgCollisionCompoundFractured.h:111
dgCollisionCompoundFractured::dgVertexBuffer
Definition: dgCollisionCompoundFractured.h:55
dgCollisionCompoundFractured::GetVertecCount
dgInt32 GetVertecCount(dgConectivityGraph::dgListNode *const node) const
Definition: dgCollisionCompoundFractured.cpp:1190
dgCollisionCompoundFractured::dgSubMesh::m_indexes
dgInt32 * m_indexes
Definition: dgCollisionCompoundFractured.h:82
dgCollisionCompoundFractured::dgFractureBuilder
Definition: dgCollisionCompoundFractured.cpp:146
dgCollisionCompoundFractured::dgVertexBuffer::m_normal
dgFloat32 * m_normal
Definition: dgCollisionCompoundFractured.h:70
dgCollisionCompoundFractured::dgVertexBuffer::m_allocator
dgMemoryAllocator * m_allocator
Definition: dgCollisionCompoundFractured.h:71
dgCollisionCompoundFractured::dgSubMesh::m_faceCount
dgInt32 m_faceCount
Definition: dgCollisionCompoundFractured.h:85
dgCollisionCompoundFractured::GetFirstMesh
dgConectivityGraph::dgListNode * GetFirstMesh() const
Definition: dgCollisionCompoundFractured.cpp:1180
dgCollisionCompoundFractured::dgVertexBuffer::m_vertex
dgFloat32 * m_vertex
Definition: dgCollisionCompoundFractured.h:69
dgCollisionCompoundFractured::GetSegmentIndexStream
dgInt32 GetSegmentIndexStream(dgConectivityGraph::dgListNode *const node, dgMesh::dgListNode *const segment, dgInt32 *const index) const
Definition: dgCollisionCompoundFractured.cpp:1216
dgCollisionCompoundFractured::dgMesh::m_isVisible
bool m_isVisible
Definition: dgCollisionCompoundFractured.h:101
dgCollisionCompoundFractured::GetFirstNiegborghArray
int GetFirstNiegborghArray(dgTreeArray::dgTreeNode *const node, dgTreeArray::dgTreeNode **const nodesArray, int maxCount) const
Definition: dgCollisionCompoundFractured.cpp:1355
dgMatrix
Definition: dgMatrix.h:40
dgCollisionCompoundFractured::dgConectivityGraph
Definition: dgCollisionCompoundFractured.h:124
dgMemoryAllocator
Definition: dgMemory.h:73
dgCollisionCompoundFractured::GetMainMesh
dgConectivityGraph::dgListNode * GetMainMesh() const
Definition: dgCollisionCompoundFractured.cpp:1175
dgCollisionCompoundFractured::dgVertexBuffer::GetVertexNormals
const dgFloat32 * GetVertexNormals() const
Definition: dgCollisionCompoundFractured.h:65
dgWorld
Definition: dgWorld.h:129
dgList::GetFirst
dgListNode * GetFirst() const
Definition: dgList.h:307
dgCollisionCompoundFractured::RemoveCollision
virtual void RemoveCollision(dgTreeArray::dgTreeNode *const node)
Definition: dgCollisionCompoundFractured.cpp:1323
dgCollisionCompoundFractured::GetVertexNormal
const dgFloat32 * GetVertexNormal(dgConectivityGraph::dgListNode *const node) const
Definition: dgCollisionCompoundFractured.cpp:1203
dgCollisionCompoundFractured::PlaneClip
dgCollisionCompoundFractured * PlaneClip(const dgVector &plane)
Definition: dgCollisionCompoundFractured.cpp:1490
dgCollisionCompoundFractured::dgDebriNodeInfo
Definition: dgCollisionCompoundFractured.h:104
dgCollisionCompoundFractured::dgMesh::m_vertexOffsetStart
dgInt32 m_vertexOffsetStart
Definition: dgCollisionCompoundFractured.h:99
dgCollisionCompoundFractured::dgConectivityGraphMap
Definition: dgCollisionCompoundFractured.h:136
dgCollisionCompoundFractured::IsNodeSaseToDetach
bool IsNodeSaseToDetach(dgTreeArray::dgTreeNode *const node) const
Definition: dgCollisionCompoundFractured.cpp:1348
dgCollisionCompoundFractured::dgDebriNodeInfo::m_mesh
dgMesh * m_mesh
Definition: dgCollisionCompoundFractured.h:110
dgCollisionCompound
Definition: dgCollisionCompound.h:35
dgCollisionParamProxy
Definition: dgContact.h:93
dgCollision::GetAllocator
dgMemoryAllocator * GetAllocator() const
Definition: dgCollision.h:360