ScummVM API documentation
dgCollisionCompoundBreakable.h
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_DGCOLLISIONCOMPOUND_BREAKABLE_H__INCLUDED_
23 #define AFX_DGCOLLISIONCOMPOUND_BREAKABLE_H__INCLUDED_
24 
25 #include "dgCollisionCompound.h"
26 #include "dgCollisionConvex.h"
27 
28 class dgMeshEffect;
29 
31 public:
32  class dgFlatVertex {
33  public:
34  dgFloat32 m_point[10]; // 3 point, 3 normal. 2 uv0, 2 uv1
35  };
36 
37  class dgFlatVertexArray : public dgArray<dgFlatVertex> {
38  public:
39  dgFlatVertexArray(dgMemoryAllocator *const allocator)
40  : dgArray<dgFlatVertex>(1024 * 4, allocator) {
41  m_count = 0;
42  }
43 
44  dgInt32 m_count;
45  };
46 
47  class dgVertexBuffer : public dgRefCounter {
48  public:
49  DG_CLASS_ALLOCATOR(allocator)
50  dgVertexBuffer(dgInt32 count, dgMemoryAllocator *allocator);
51  dgVertexBuffer(dgMemoryAllocator *const allocator, dgDeserialize deserialization, void *const userData);
52  ~dgVertexBuffer();
53 
54  void Serialize(dgSerialize callback, void *const userData) const;
55  void GetVertexStreams(dgInt32 vertexStrideInByte, dgFloat32 *vertex, dgInt32 normalStrideInByte, dgFloat32 *normal,
56  dgInt32 uvStrideInByte, dgFloat32 *uv) const;
57 
58  dgInt32 m_vertexCount;
59  dgFloat32 *m_uv;
60  dgFloat32 *m_vertex;
61  dgFloat32 *m_normal;
62  dgMemoryAllocator *m_allocator;
63  };
64 
65  class dgSubMesh {
66  public:
67  dgSubMesh(dgMemoryAllocator *const allocator);
68  ~dgSubMesh();
69  void Serialize(dgSerialize callback, void *const userData) const;
70 
71  dgInt32 m_faceOffset;
72  dgInt32 m_visibleFaces;
73  dgInt32 m_material;
74  dgInt32 m_faceCount;
75  dgInt32 *m_indexes;
76  dgMemoryAllocator *m_allocator;
77  };
78 
79  class dgMesh : public dgList<dgSubMesh>, public dgRefCounter {
80  public:
81  dgMesh(dgMemoryAllocator *const allocator);
82  dgMesh(dgMemoryAllocator *const allocator, dgDeserialize deserialization, void *const userData);
83  ~dgMesh();
84  void Serialize(dgSerialize callback, void *const userData) const;
85  dgSubMesh *AddgSubMesh(dgInt32 indexCount, dgInt32 material);
86 
87  dgInt32 m_IsVisible;
88  };
89 
91  public:
93  ~dgDebriNodeInfo();
94 
95  struct PackedSaveData {
96  union {
97  dgInt32 m_lru;
98  dgInt32 m_shapeID;
99  };
100  dgInt32 m_distanceToFixNode;
101  dgInt32 m_islandIndex;
102  } m_commonData;
103 
104  dgMesh *m_mesh;
105  dgCollisionConvex *m_shape;
106  };
107 
109  public:
111  ~dgSharedNodeMesh();
112  };
113 
114  class dgDebriGraph : public dgGraph<dgDebriNodeInfo, dgSharedNodeMesh> {
115  public:
116  dgDebriGraph(dgMemoryAllocator *const allocator);
117  dgDebriGraph(const dgDebriGraph &source);
118  dgDebriGraph(dgMemoryAllocator *const allocator, dgDeserialize deserialization, void *const userData);
119  ~dgDebriGraph();
120 
121  // void AddToHeap (dgDownHeap<dgMeshEffect*, dgFloat32>& heap, dgMeshEffect* front);
122  void AddNode(dgFlatVertexArray &vertexArray, dgMeshEffect *solid, dgInt32 clipperMaterial, dgInt32 id, dgFloat32 density, dgFloat32 padding);
123  // void SplitAndAddNodes (dgFlatVertexArray& vertexArray, dgMeshEffect* solid, dgMeshEffect* const clipper,
124  // dgInt32 clipperMaterial, dgInt32 id, dgFloat32 density, dgCollisionCompoundBreakableCallback callback, void* buildUsedData);
125 
126  // void AddMeshes (dgFlatVertexArray& vertexArray, dgInt32 count, dgMeshEffect* const solidArray[], dgMeshEffect* const clipperArray[],
127  // dgMatrix* const matrixArray, dgInt32* const idArray, dgFloat32* const densities, dgCollisionCompoundBreakableCallback callback, void* buildUsedData);
128  void AddMeshes(dgFlatVertexArray &vertexArray, dgInt32 count, dgMeshEffect *const solidArray[],
129  const dgInt32 *const idArray, const dgFloat32 *const densities, const dgInt32 *const internalFaceMaterial, dgFloat32 gaps);
130 
131  void Serialize(dgSerialize callback, void *const userData) const;
132  };
133 
134  class dgIsland : public dgList<dgDebriGraph::dgListNode *> {
135  public:
136  dgIsland(dgMemoryAllocator *const allocator)
138  }
139  };
140 
142  public:
143  dgCollisionConvexIntance(dgWorld *const world, dgDeserialize deserialization, void *const userData);
144  dgCollisionConvexIntance(const dgCollisionConvexIntance &source, dgDebriGraph::dgListNode *node);
145  dgCollisionConvexIntance(dgCollisionConvex *convexChild, dgDebriGraph::dgListNode *node, dgFloat32 density);
146  virtual ~dgCollisionConvexIntance();
147 
148  protected:
149  virtual dgFloat32 GetVolume() const;
150  virtual bool OOBBTest(const dgMatrix &matrix, const dgCollisionConvex *const shape, void *const cacheOrder) const;
151  virtual dgVector SupportVertex(const dgVector &dir) const;
152  virtual dgVector SupportVertexSimd(const dgVector &dir) const;
153  virtual void CalcAABB(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const;
154  virtual void CalcAABBSimd(const dgMatrix &matrix, dgVector &p0, dgVector &p1) const;
155  virtual void DebugCollision(const dgMatrix &matrix, OnDebugCollisionMeshCallback callback, void *const userData) const;
156  virtual dgFloat32 RayCast(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
157  virtual dgFloat32 RayCastSimd(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
158  virtual dgVector CalculateVolumeIntegral(const dgMatrix &globalMatrix, GetBuoyancyPlane bouyancyPlane, void *const context) const;
159 
160  private:
161  virtual dgInt32 CalculateSignature() const;
162  virtual void SetCollisionBBox(const dgVector &p0, const dgVector &p1);
163  virtual dgFloat32 GetBoxMinRadius() const;
164  virtual dgFloat32 GetBoxMaxRadius() const;
165  virtual dgInt32 CalculatePlaneIntersection(const dgVector &normal, const dgVector &point, dgVector *const contactsOut) const;
166  virtual dgInt32 CalculatePlaneIntersectionSimd(const dgVector &normal, const dgVector &point, dgVector *const contactsOut) const;
167  virtual void GetCollisionInfo(dgCollisionInfo *info) const;
168  virtual void Serialize(dgSerialize callback, void *const userData) const;
169 
170  virtual void SetBreakImpulse(dgFloat32 force);
171  virtual dgFloat32 GetBreakImpulse() const;
172 
173  dgNodeBase *m_treeNode;
174  dgCollisionConvex *m_myShape;
175  dgDebriGraph::dgListNode *m_graphNode;
176  dgVector m_inertia;
177  dgFloat32 m_destructionImpulse;
178 
179 #ifdef _DEBUG
180  dgInt32 m_ordinal;
181 #endif
182  friend class dgCollisionCompoundBreakable;
183  };
184 
186  public:
187  dgInt32 m_index;
188  dgDebriGraph::dgListNode *m_node;
189  };
190 
191  // class dgSegmenList: public dgList<dgMeshEffect*>
192  // {
193  // public:
194  // dgSegmenList(dgMeshEffect* const source);
195  // ~dgSegmenList();
196  // };
197 
199  // dgCollisionCompoundBreakable (dgInt32 count, dgMeshEffect* const solidArray[], dgMeshEffect* const clipperArray[],
200  // dgMatrix* const matrixArray, dgInt32* const idArray, dgFloat32* const densities, dgInt32 debriiId,
201  // dgCollisionCompoundBreakableCallback callback, void* buildUsedData, dgWorld* world);
202 
203  dgCollisionCompoundBreakable(dgInt32 count, dgMeshEffect *const solidArray[], const dgInt32 *const idArray,
204  const dgFloat32 *const densities, const dgInt32 *const internalFaceMaterial,
205  dgInt32 debriiId, dgFloat32 gaps, dgWorld *world);
206 
207  dgCollisionCompoundBreakable(dgWorld *const world, dgDeserialize deserialization, void *const userData);
208  virtual ~dgCollisionCompoundBreakable(void);
209 
210  void DeleteComponentBegin();
211  dgBody *CreateComponentBody(dgDebriGraph::dgListNode *node) const;
212  void DeleteComponent(dgDebriGraph::dgListNode *node);
213  void DeleteComponentEnd();
214 
215  dgDebriGraph::dgListNode *GetMainMesh() const {
216  return m_conectivity.GetLast();
217  }
218  dgDebriGraph::dgListNode *GetFirstComponentMesh() const {
219  return (m_conectivity.GetCount() > 2) ? m_conectivity.GetFirst()->GetNext() : NULL;
220  }
221  dgInt32 GetSegmentsInRadius(const dgVector &origin, dgFloat32 radius, dgDebriGraph::dgListNode **segments, dgInt32 maxCount) const;
222 
223  void ResetAnchor();
224  void SetAnchoredParts(dgInt32 count, const dgMatrix *const matrixArray, dgCollision * const *collisionArray);
225  void EnumerateIslands();
226  // dgInt32 GetSegmentsInRadius (const dgVector& origin, dgFloat32 radius, dgDebriGraph::dgListNode** segments, dgInt32 maxCount);
227  // dgInt32 GetDetachedPieces (dgCollision** shapes, dgInt32 maxCount);
228 
229  dgInt32 GetSegmentIndexStream(dgDebriGraph::dgListNode *const node, dgMesh::dgListNode *segment, dgInt32 *const index) const;
230  dgInt32 GetSegmentIndexStreamShort(const dgDebriGraph::dgListNode *const node, dgMesh::dgListNode *segment, dgInt16 *const index) const;
231 
232  dgInt32 GetVertecCount() const {
233  return m_vertexBuffer->m_vertexCount;
234  }
235  void GetVertexStreams(dgInt32 vertexStrideInByte, dgFloat32 *vertex,
236  dgInt32 normalStrideInByte, dgFloat32 *normal,
237  dgInt32 uvStrideInByte, dgFloat32 *uv) const {
238  m_vertexBuffer->GetVertexStreams(vertexStrideInByte, vertex, normalStrideInByte, normal, uvStrideInByte, uv);
239  }
240 
241 private:
242  void LinkNodes();
243 
244  virtual void GetCollisionInfo(dgCollisionInfo *info) const;
245  virtual void Serialize(dgSerialize callback, void *const userData) const;
246 
247  dgInt32 m_lru;
248  dgInt32 m_lastIslandColor;
249  dgInt32 m_visibilityMapIndexCount;
250  dgInt8 *m_visibilityMap;
251  dgInt32 *m_visibilityInderectMap;
252  dgVertexBuffer *m_vertexBuffer;
253  dgDebriGraph m_conectivity;
254  dgIsland m_detachedIslands;
255 };
256 
257 #endif
Definition: dgCollisionCompoundBreakable.h:95
Definition: dgCollisionCompoundBreakable.h:47
Definition: dgGraph.h:39
Definition: dgCollision.h:73
Definition: dgBody.h:85
Definition: dgCollisionCompoundBreakable.h:37
Definition: dgVector.h:86
Definition: dgRefCounter.h:25
Definition: dgCollisionCompoundBreakable.h:114
Definition: dgCollisionCompoundBreakable.h:134
Definition: dgList.h:33
Definition: dgMeshEffect.h:78
Definition: dgContact.h:88
Definition: dgCollisionCompoundBreakable.h:79
Definition: dgCollisionCompoundBreakable.h:30
Definition: dgArray.h:33
Definition: dgCollisionCompoundBreakable.h:108
Definition: dgCollisionCompoundBreakable.h:185
Definition: dgCollisionCompoundBreakable.h:90
Definition: dgCollisionCompoundBreakable.h:65
Definition: dgCollisionConvex.h:39
Definition: dgCollisionCompoundBreakable.h:32
Definition: dgCollision.h:178
Definition: dgMatrix.h:41
Definition: dgMemory.h:80
Definition: dgCollisionCompound.h:58
Definition: dgWorld.h:118
Definition: dgCollisionCompoundBreakable.h:141
Definition: dgCollisionCompound.h:31