-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGameObject.h
125 lines (95 loc) · 2.42 KB
/
GameObject.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include <btBulletDynamicsCommon.h>
#include "Mesh.h"
#include "Path.h"
#include <glm/gtc/type_ptr.hpp>
#include "Helper.h"
#include "Trigger.h"
#include <glm/gtc/matrix_transform.hpp>
enum Shape { /*None,*/ Box, Cylinder, SHAPE_NUMITEMS };
class GameObject
{
private:
Mesh* mesh;
bool collidable;
int collisionFlagsDefault;
float mass;
public:
static int nextID;
btRigidBody* rigidbody;
bool drawable = true;
glm::vec4 color;
glm::vec4 trueColor;
Shape shapeType;
int ID;
GLuint textureID;
//Components
Path motion;
Trigger trigger;
bool dof[6] = { true, true, true, true, true, true };
GameObject(Mesh* p_mesh, Shape p_shapeType, glm::vec3 p_translation,
glm::quat p_orientation, glm::vec3 p_scale, glm::vec4 p_color,
GLuint p_texID, float p_mass = 0, bool bCollidable = true,
Path p_motion = Path());
~GameObject();
//Cloning doesn't copy trigger, for now
GameObject(GameObject& p) :
GameObject(p.mesh,
p.shapeType,
p.GetTranslation(),
p.GetOrientation(),
p.GetScale(),
p.trueColor,
p.textureID,
p.mass,
p.collidable,
p.motion) {}
glm::mat4 GetModelMatrix();
glm::quat GetOrientation()
{
return convert(rigidbody->getOrientation());
}
glm::vec3 GetTranslation()
{
return convert(rigidbody->getWorldTransform().getOrigin());
}
glm::vec3 GetScale()
{
return convert(rigidbody->getCollisionShape()->getLocalScaling());
}
bool GetCollidable() { return collidable; }
void SetCollidable(bool set)
{
collidable = set;
if (collidable)
rigidbody->setCollisionFlags(
rigidbody->getCollisionFlags()
&~ rigidbody->CF_NO_CONTACT_RESPONSE);
else
rigidbody->setCollisionFlags(
rigidbody->getCollisionFlags()
| rigidbody->CF_NO_CONTACT_RESPONSE);
}
void SetShape(Shape p_shapeType);
void SetMesh(Mesh* p_mesh) { mesh = p_mesh; }
private:
void SetShape(glm::vec3 translation, glm::quat orientation,
glm::vec3 scale, Shape p_shapeType);
public:
void Render();
void Update(float deltaTime);
float GetMass() { return mass; }
void SetMass(float p_mass)
{
Physics::dynamicsWorld->removeRigidBody(rigidbody);
btVector3 inertia;
rigidbody->getCollisionShape()->
calculateLocalInertia(p_mass, inertia);
if (motion.Points.size() == 0)
rigidbody->setMassProps(p_mass, inertia);
else
rigidbody->setMassProps(p_mass, btVector3(0, 0, 0));
Physics::dynamicsWorld->addRigidBody(rigidbody);
mass = p_mass;
}
};