-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathCollisionDetection.h
More file actions
98 lines (77 loc) · 3.58 KB
/
CollisionDetection.h
File metadata and controls
98 lines (77 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef _COLLISIONDETECTION_H
#define _COLLISIONDETECTION_H
#include "Common/Common.h"
#include "SimulationModel.h"
#include "AABB.h"
namespace PBD
{
class CollisionDetection
{
public:
static const unsigned int RigidBodyContactType; // = 0;
static const unsigned int ParticleContactType; // = 1;
static const unsigned int ParticleRigidBodyContactType; // = 2;
static const unsigned int ParticleSolidContactType; // = 3;
typedef void (*ContactCallbackFunction)(const unsigned int contactType, const unsigned int bodyIndex1, const unsigned int bodyIndex2,
const Vector3r &cp1, const Vector3r &cp2,
const Vector3r &normal, const Real dist,
const Real restitutionCoeff, const Real frictionCoeff, void *userData);
typedef void (*SolidContactCallbackFunction)(const unsigned int contactType, const unsigned int bodyIndex1, const unsigned int bodyIndex2,
const unsigned int tetIndex, const Vector3r &bary,
const Vector3r &cp1, const Vector3r &cp2,
const Vector3r &normal, const Real dist,
const Real restitutionCoeff, const Real frictionCoeff, void *userData);
struct CollisionObject
{
static const unsigned int RigidBodyCollisionObjectType; // = 0;
static const unsigned int TriangleModelCollisionObjectType; // = 1;
static const unsigned int TetModelCollisionObjectType; // = 2;
AABB m_aabb;
unsigned int m_bodyIndex;
unsigned int m_bodyType;
virtual ~CollisionObject() {}
virtual int &getTypeId() const = 0;
};
struct CollisionObjectWithoutGeometry : public CollisionObject
{
static int TYPE_ID;
virtual int &getTypeId() const { return TYPE_ID; }
virtual ~CollisionObjectWithoutGeometry() {}
};
protected:
Real m_tolerance;
ContactCallbackFunction m_contactCB;
SolidContactCallbackFunction m_solidContactCB;
void *m_contactCBUserData;
void *m_solidContactCBUserData;
std::vector<CollisionObject *> m_collisionObjects;
void updateAABB(const Vector3r &p, AABB &aabb);
public:
CollisionDetection();
virtual ~CollisionDetection();
void cleanup();
Real getTolerance() const { return m_tolerance; }
void setTolerance(Real val) { m_tolerance = val; }
void addRigidBodyContact(const unsigned int rbIndex1, const unsigned int rbIndex2,
const Vector3r &cp1, const Vector3r &cp2,
const Vector3r &normal, const Real dist,
const Real restitutionCoeff, const Real frictionCoeff);
void addParticleRigidBodyContact(const unsigned int particleIndex, const unsigned int rbIndex,
const Vector3r &cp1, const Vector3r &cp2,
const Vector3r &normal, const Real dist,
const Real restitutionCoeff, const Real frictionCoeff);
void addParticleSolidContact(const unsigned int particleIndex, const unsigned int solidIndex,
const unsigned int tetIndex, const Vector3r &bary,
const Vector3r &cp1, const Vector3r &cp2,
const Vector3r &normal, const Real dist,
const Real restitutionCoeff, const Real frictionCoeff);
virtual void addCollisionObject(const unsigned int bodyIndex, const unsigned int bodyType);
std::vector<CollisionObject *> &getCollisionObjects() { return m_collisionObjects; }
virtual void collisionDetection(SimulationModel &model) = 0;
void setContactCallback(CollisionDetection::ContactCallbackFunction val, void *userData);
void setSolidContactCallback(CollisionDetection::SolidContactCallbackFunction val, void *userData);
void updateAABBs(SimulationModel &model);
void updateAABB(SimulationModel &model, CollisionDetection::CollisionObject *co);
};
}
#endif