forked from hkust-psan1/psan1-rendering-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
collider.h
76 lines (55 loc) · 1.72 KB
/
collider.h
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
#ifndef COLLIDER_
#define COLLIDER_
#include <btBulletDynamicsCommon.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision\CollisionShapes\btShapeHull.h>
#include <ConvexDecomposition\ConvexDecomposition.h>
#include <ConvexDecomposition\cd_wavefront.h>
#include "HACD\hacdCircularList.h"
#include "HACD\hacdVector.h"
#include "HACD\hacdICHull.h"
#include "HACD\hacdGraph.h"
#include "HACD\hacdHACD.h"
class SceneObject;
class Collider {
public:
Collider(bool f = false);
void initPhysics(std::string obj_path);
void setInitialPosition(btVector3 pos);
void setInitialRotation(btQuaternion q);
void step();
inline btRigidBody* getRigidBody() const { return m_rigidBody; };
inline void setParent(SceneObject* p) { m_parent = p; };
std::string m_physicsObjFilename;
inline void setMass(int m) { m_mass = m; };
static float focus_x;
static float focus_y;
static float focus_z;
protected:
SceneObject* m_parent;
btRigidBody* m_rigidBody;
btScalar m_mass;
bool focus;
};
class SphereCollider : public Collider {
public:
SphereCollider(bool f = false) : Collider(f){};
void initPhysics(float radius);
protected:
float m_radius;
};
class CylinderCollider : public Collider {
public:
CylinderCollider() {
m_mass = 1;
}
void initPhysics(float radius, float halfHeight) {
btCollisionShape* cylinderShape = new btCylinderShape(btVector3(radius, halfHeight, radius));
btDefaultMotionState* state = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
btVector3 inertia(0, 0, 0);
cylinderShape->calculateLocalInertia(m_mass, inertia);
btRigidBody::btRigidBodyConstructionInfo info(m_mass, state, cylinderShape, inertia);
m_rigidBody = new btRigidBody(info);
}
};
#endif