ScummVM API documentation
dgCollisionBVH.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 __DGCOLLIIONBVH__
23 #define __DGCOLLIIONBVH__
24 
25 #include "dgCollision.h"
26 #include "dgCollisionMesh.h"
27 
28 class dgCollisionBVH;
29 
30 typedef dgFloat32(*dgCollisionBVHUserRayCastCallback)(const dgBody *const body, const dgCollisionBVH *const heightFieldCollision, dgFloat32 interception, dgFloat32 *normal, dgInt32 faceId, void *usedData);
31 
33 public:
34  DG_MSC_VECTOR_ALIGMENT
35  struct dgBVHRay: public dgFastRayTest {
36  dgBVHRay(const dgVector &l0, const dgVector &l1)
37  : dgFastRayTest(l0, l1) {
38  }
39 
40  dgMatrix m_matrix;
41  dgVector m_normal;
42  dgUnsigned32 m_id;
43  dgFloat32 m_t;
44  void *m_userData;
45  const dgBody *m_myBody;
46  const dgCollisionBVH *m_me;
47  } DG_GCC_VECTOR_ALIGMENT;
48 
49  dgCollisionBVH(dgMemoryAllocator *const allocator);
50  dgCollisionBVH(dgWorld *const world, dgDeserialize deserialization, void *const userData);
51  virtual ~dgCollisionBVH(void);
52 
53  void BeginBuild();
54  void AddFace(dgInt32 vertexCount, const dgFloat32 *const vertexPtr, dgInt32 strideInBytes, dgInt32 faceAttribute);
55  void EndBuild(dgInt32 optimize);
56 
57  void SetCollisionRayCastCallback(dgCollisionBVHUserRayCastCallback rayCastCallback);
58  dgCollisionBVHUserRayCastCallback GetDebugRayCastCallback() const {
59  return m_userRayCastCallback;
60  }
61 
62  void GetVertexListIndexList(const dgVector &p0, const dgVector &p1, dgGetVertexListIndexList &data) const;
63 
64 
65 private:
66 
67 
68  static dgFloat32 RayHit(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
69  static dgFloat32 RayHitSimd(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
70  static dgFloat32 RayHitUser(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
71  static dgFloat32 RayHitUserSimd(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
72  static dgIntersectStatus GetPolygon(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
73  static dgIntersectStatus ShowDebugPolygon(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
74  static dgIntersectStatus GetTriangleCount(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
75  static dgIntersectStatus CollectVertexListIndexList(void *context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount);
76 
77  void Serialize(dgSerialize callback, void *const userData) const;
78  virtual dgVector SupportVertex(const dgVector &dir) const;
79  virtual dgFloat32 RayCast(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
80  virtual dgFloat32 RayCastSimd(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
81  virtual void GetCollidingFaces(dgPolygonMeshDesc *const data) const;
82  virtual void GetCollidingFacesSimd(dgPolygonMeshDesc *const data) const;
83  virtual void GetCollisionInfo(dgCollisionInfo *info) const;
84 
85  void DebugCollision(const dgMatrix &matrixPtr, OnDebugCollisionMeshCallback callback, void *const userData) const;
86 
88  dgCollisionBVHUserRayCastCallback m_userRayCastCallback;
89 
90  friend class dgCollisionCompound;
91 };
92 
93 
94 #endif
Definition: dgCollisionBVH.h:35
Definition: dgCollisionBVH.h:32
Definition: dgIntersections.h:35
Definition: dgCollision.h:73
Definition: dgBody.h:85
Definition: dgCollisionMesh.h:39
Definition: dgVector.h:86
Definition: dgPolygonSoupBuilder.h:45
Definition: dgContact.h:88
Definition: dgCollisionMesh.h:101
Definition: dgCollisionMesh.h:90
Definition: dgMatrix.h:41
Definition: dgMemory.h:80
Definition: dgWorld.h:118
Definition: dgAABBPolygonSoup.h:37
Definition: dgCollisionCompound.h:31