-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cpp
96 lines (84 loc) · 2.63 KB
/
Bullet.cpp
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
#include "Bullet.h"
int Bullet::PROJECTION = -1;
int Bullet::VIEW = -1;
int Bullet::SIZE = -1;
int Bullet::INNER_RADIUS = -1;
int Bullet::MIDDLE_RADIUS = -1;
int Bullet::OUTER_RADIUS = -1;
int Bullet::INNER_COLOR = -1;
int Bullet::MIDDLE_COLOR = -1;
int Bullet::OUTER_COLOR = -1;
Bullet::Bullet(vec3 position, float innerRadius, float middleRadius, float outerRadius, glm::vec4 innerColor,
glm::vec4 middleColor, glm::vec4 outerColor, glm::vec2 size)
: SceneActor(position) {
this->innerRadius = innerRadius;
this->middleRadius = middleRadius;
this->outerRadius = outerRadius;
this->innerColor = innerColor;
this->middleColor = middleColor;
this->outerColor = outerColor;
this->size = size;
}
Bullet::~Bullet() { }
bool Bullet::SetModel(Model* actorModel){
if (actorModel == nullptr) return false;
this->model = actorModel;
if (PROJECTION == -1) {
PROJECTION = model->GetParameterId("Projection");
VIEW = model->GetParameterId("View");
SIZE = model->GetParameterId("Size");
INNER_RADIUS = model->GetParameterId("InnerRadius");
MIDDLE_RADIUS = model->GetParameterId("MiddleRadius");
OUTER_RADIUS = model->GetParameterId("OuterRadius");
INNER_COLOR = model->GetParameterId("InnerColor");
MIDDLE_COLOR = model->GetParameterId("MiddleColor");
OUTER_COLOR = model->GetParameterId("OuterColor");
}
return true;
}
vec2 Bullet::GetSize()
{
return size;
}
Rectangle2D Bullet::GetEnclosingRectangle()
{
Rectangle2D rect;
rect.min = vec2(Position().x - size.x / 2, Position().y - size.y / 2);
rect.max = vec2(Position().x + size.x / 2, Position().y + size.y / 2);
return rect;
}
void Bullet::Draw(SceneInfo& sceneInfo, int numInstances) {
SetParameterValue(PROJECTION, &sceneInfo.projection);
SetParameterValue(VIEW, &sceneInfo.view);
SetParameterValue(INNER_RADIUS, &innerRadius);
SetParameterValue(MIDDLE_RADIUS, &middleRadius);
SetParameterValue(INNER_COLOR, &innerColor);
SetParameterValue(MIDDLE_COLOR, &middleColor);
SetParameterValue(SIZE, &size);
SetParameterValue(OUTER_COLOR, &outerColor);
SetParameterValue(OUTER_RADIUS, &outerRadius);
model->Draw(numInstances);
}
float Bullet::GetEnclosingRadius()
{
return size.x * outerRadius / 2.0f;
}
void Bullet::SetInnerRadius(float innerRadius) {
this->innerRadius = innerRadius;
}
void Bullet::SetOuterRadius(float outerRadius) {
this->outerRadius = outerRadius;
}
void Bullet::SetInnerColor(glm::vec4 innerColor) {
this->innerColor = innerColor;
}
void Bullet::SetOuterColor(glm::vec4 outerColor) {
this->outerColor = outerColor;
}
void Bullet::SetMiddleColor(glm::vec4 middleColor) {
this->middleColor = middleColor;
}
void Bullet::SetSize(glm::vec2 size)
{
this->size = size;
}