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

My Project

dgCollisionBVH.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 __DGCOLLISION_BVH__
23 #define __DGCOLLISION_BVH__
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
32 class dgCollisionBVH: public dgCollisionMesh, public dgAABBPolygonSoup
33 {
34 public:
35 DG_MSC_VECTOR_ALIGMENT
36 struct dgBVHRay: public dgFastRayTest
37 {
38 dgBVHRay(const dgVector& l0, const dgVector& l1)
39 : dgFastRayTest (l0, l1)
40 {
41 }
42
43 dgMatrix m_matrix;
44 dgVector m_normal;
45 dgUnsigned32 m_id;
46 dgFloat32 m_t;
47 void* m_userData;
48 const dgBody* m_myBody;
49 const dgCollisionBVH* m_me;
50 } DG_GCC_VECTOR_ALIGMENT;
51
52 dgCollisionBVH(dgWorld* const world);
53 dgCollisionBVH (dgWorld* const world, dgDeserialize deserialization, void* const userData);
54 virtual ~dgCollisionBVH(void);
55
56 void BeginBuild();
57 void AddFace (dgInt32 vertexCount, const dgFloat32* const vertexPtr, dgInt32 strideInBytes, dgInt32 faceAttribute);
58 void EndBuild(dgInt32 optimize);
59
60 void SetCollisionRayCastCallback (dgCollisionBVHUserRayCastCallback rayCastCallback);
61 dgCollisionBVHUserRayCastCallback GetDebugRayCastCallback() const { return m_userRayCastCallback;}
62 void GetVertexListIndexList (const dgVector& p0, const dgVector& p1, dgMeshVertexListIndexList &data) const;
63
64 void ForEachFace (dgAABBIntersectCallback callback, void* const context) const;
65
66 private:
67 static dgFloat32 RayHit (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount);
68 static dgFloat32 RayHitUser (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount);
69 static dgIntersectStatus GetPolygon (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount, dgFloat32 hitDistance);
70 static dgIntersectStatus ShowDebugPolygon (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount, dgFloat32 hitDistance);
71 static dgIntersectStatus GetTriangleCount (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount, dgFloat32 hitDistance);
72 static dgIntersectStatus CollectVertexListIndexList (void* const context, const dgFloat32* const polygon, dgInt32 strideInBytes, const dgInt32* const indexArray, dgInt32 indexCount, dgFloat32 hitDistance);
73
74 void Serialize(dgSerialize callback, void* const userData) const;
75 virtual dgVector SupportVertex (const dgVector& dir) const;
76
77 virtual dgFloat32 RayCast (const dgVector& localP0, const dgVector& localP1, dgFloat32 maxT, dgContactPoint& contactOut, const dgBody* const body, void* const userData, OnRayPrecastAction preFilter) const;
78 virtual void GetCollidingFaces (dgPolygonMeshDesc* const data) const;
79 virtual void GetCollisionInfo(dgCollisionInfo* const info) const;
80
81 virtual void GetLocalAABB (const dgVector& p0, const dgVector& p1, dgVector& boxP0, dgVector& boxP1) const;
82 virtual void DebugCollision (const dgMatrix& matrixPtr, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const;
83 virtual dgVector SupportVertex (const dgVector& dir, dgInt32* const vertexIndex) const;
84
85 dgPolygonSoupDatabaseBuilder* m_builder;
86 dgCollisionBVHUserRayCastCallback m_userRayCastCallback;
87
88 friend class dgCollisionCompound;
89 friend class dgCollisionDeformableMesh;
90 };
91
92
93 #endif
dgCollisionBVH::DG_GCC_VECTOR_ALIGMENT
dgCollisionBVH::dgBVHRay DG_GCC_VECTOR_ALIGMENT
dgCollisionBVH::dgBVHRay
Definition: dgCollisionBVH.h:36
dgCollision::OnDebugCollisionMeshCallback
void(dgApi * OnDebugCollisionMeshCallback)(void *userData, int vertexCount, const dgFloat32 *FaceArray, int faceId)
Definition: dgCollision.h:220
dgCollisionBVH
Definition: dgCollisionBVH.h:32
dgFastRayTest
Definition: dgIntersections.h:52
dgCollisionInfo
Definition: dgCollision.h:82
dgBody
Definition: dgBody.h:44
userData
void *const userData
Definition: dgBroadPhase.h:35
dgCollisionBVH::dgBVHRay::m_userData
void * m_userData
Definition: dgCollisionBVH.h:47
dgCollisionBVH::BeginBuild
void BeginBuild()
Definition: dgCollisionBVH.cpp:61
dgCollisionBVH::EndBuild
void EndBuild(dgInt32 optimize)
Definition: dgCollisionBVH.cpp:86
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgCollisionBVH::dgBVHRay::dgBVHRay
dgBVHRay(const dgVector &l0, const dgVector &l1)
Definition: dgCollisionBVH.h:38
dgPolygonMeshDesc
Definition: dgCollisionMesh.h:42
dgCollisionBVH::dgBVHRay::m_myBody
const dgBody * m_myBody
Definition: dgCollisionBVH.h:48
dgVector
Definition: dgVector.h:639
dgPolygonSoupDatabaseBuilder
Definition: dgPolygonSoupBuilder.h:46
dgContactPoint
Definition: dgContact.h:78
dgSerialize
void(dgApi * dgSerialize)(void *const userData, const void *const buffer, size_t size)
Definition: dgTypes.h:280
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgDeserialize
void(dgApi * dgDeserialize)(void *const userData, void *buffer, size_t size)
Definition: dgTypes.h:279
dgCollisionBVH::SetCollisionRayCastCallback
void SetCollisionRayCastCallback(dgCollisionBVHUserRayCastCallback rayCastCallback)
Definition: dgCollisionBVH.cpp:80
dgCollisionBVH::dgBVHRay::m_t
dgFloat32 m_t
Definition: dgCollisionBVH.h:46
dgCollisionBVH::dgBVHRay::m_matrix
dgMatrix m_matrix
Definition: dgCollisionBVH.h:43
dgCollisionBVH::~dgCollisionBVH
virtual ~dgCollisionBVH(void)
Definition: dgCollisionBVH.cpp:51
dgAABBIntersectCallback
dgIntersectStatus(* dgAABBIntersectCallback)(void *const context, const dgFloat32 *const polygon, dgInt32 strideInBytes, const dgInt32 *const indexArray, dgInt32 indexCount, dgFloat32 hitDistance)
Definition: dgIntersections.h:41
dgCollisionMesh.h
dgCollisionBVH::ForEachFace
void ForEachFace(dgAABBIntersectCallback callback, void *const context) const
Definition: dgCollisionBVH.cpp:125
OnRayPrecastAction
dgUnsigned32(dgApi * OnRayPrecastAction)(const dgBody *const body, const dgCollisionInstance *const collision, void *const userData)
Definition: dgBroadPhase.h:36
dgCollisionBVH::GetVertexListIndexList
void GetVertexListIndexList(const dgVector &p0, const dgVector &p1, dgMeshVertexListIndexList &data) const
Definition: dgCollisionBVH.cpp:183
dgCollisionMesh
Definition: dgCollisionMesh.h:147
dgCollisionDeformableMesh
Definition: dgCollisionDeformableMesh.h:36
dgCollisionBVH::AddFace
void AddFace(dgInt32 vertexCount, const dgFloat32 *const vertexPtr, dgInt32 strideInBytes, dgInt32 faceAttribute)
Definition: dgCollisionBVH.cpp:67
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgCollisionBVH::dgBVHRay::m_id
dgUnsigned32 m_id
Definition: dgCollisionBVH.h:45
dgCollisionBVH::dgCollisionBVH
dgCollisionBVH(dgWorld *const world)
Definition: dgCollisionBVH.cpp:28
dgCollision.h
dgCollisionMesh::dgMeshVertexListIndexList
Definition: dgCollisionMesh.h:152
dgCollisionBVH::dgBVHRay::m_normal
dgVector m_normal
Definition: dgCollisionBVH.h:44
dgMatrix
Definition: dgMatrix.h:40
dgIntersectStatus
dgIntersectStatus
Definition: dgIntersections.h:35
dgWorld
Definition: dgWorld.h:129
dgCollisionBVH::GetDebugRayCastCallback
dgCollisionBVHUserRayCastCallback GetDebugRayCastCallback() const
Definition: dgCollisionBVH.h:61
dgCollisionBVHUserRayCastCallback
dgFloat32(* dgCollisionBVHUserRayCastCallback)(const dgBody *const body, const dgCollisionBVH *const heightFieldCollision, dgFloat32 interception, dgFloat32 *normal, dgInt32 faceId, void *usedData)
Definition: dgCollisionBVH.h:30
dgAABBPolygonSoup
Definition: dgAABBPolygonSoup.h:33
dgCollisionBVH::dgBVHRay::m_me
const dgCollisionBVH * m_me
Definition: dgCollisionBVH.h:49
dgCollisionCompound
Definition: dgCollisionCompound.h:35