-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.cpp
201 lines (177 loc) · 6.84 KB
/
target.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "target.h"
#include "globals.h"
Target::Target(Point center)
{
this->center = center;
this->radius = 3;
this->rotation = 0;
this->state = NORMAL;
int choice = rand() % 9;
//Everyone from the Southern Conference except mercer. Of course we'll blow them up and stuff.
if(choice == 0)
{
loadTex("textures/mascots/woffordterriers.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/woffordterriers.png"].textureRef;
}
else if (choice == 1)
{
loadTex("textures/mascots/citadelbulldogs.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/citadelbulldogs.png"].textureRef;
}
else if (choice == 2)
{
loadTex("textures/mascots/chattanoogamocs.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/chattanoogamocs.png"].textureRef;
}
else if (choice == 3)
{
loadTex("textures/mascots/furmanpaladins.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/furmanpaladins.png"].textureRef;
}
else if (choice == 4)
{
loadTex("textures/mascots/samfordbulldogs.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/samfordbulldogs.png"].textureRef;
}
else if (choice == 5)
{
loadTex("textures/mascots/uncgspartans.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/uncgspartans.png"].textureRef;
}
else if (choice == 6)
{
loadTex("textures/mascots/vmilogo.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/vmilogo.png"].textureRef;
}
else if (choice == 7)
{
loadTex("textures/mascots/wcucatamounts.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/wcucatamounts.png"].textureRef;
}
else if (choice == 8)
{
loadTex("textures/mascots/etsubucs.png");
this->mascotChoice = GLOBAL.TEXTURES_LOADED["textures/mascots/etsubucs.png"].textureRef;
}
{
boundingBox.push_back(Polygon3d());
auto &points = boundingBox[boundingBox.size()-1].getPoints();
points.push_back(Point(-radius,0,-radius));
points.push_back(Point( radius,0,-radius));
points.push_back(Point( radius,0, radius));
points.push_back(Point(-radius,0, radius));
points.push_back(Point(-radius,0,-radius));
}
{
boundingBox.push_back(Polygon3d());
auto &points = boundingBox[boundingBox.size()-1].getPoints();
points.push_back(Point( radius, 0, -radius));
points.push_back(Point( radius, .1, -radius));
points.push_back(Point( radius, .1, radius));
points.push_back(Point( radius, 0, radius));
points.push_back(Point( radius, 0, -radius));
}
{
boundingBox.push_back(Polygon3d());
auto &points = boundingBox[boundingBox.size()-1].getPoints();
points.push_back(Point( -radius, 0, radius));
points.push_back(Point( -radius, .1, radius));
points.push_back(Point( radius, .1, radius));
points.push_back(Point( radius, 0, radius));
points.push_back(Point( -radius, 0, radius));
}
{
boundingBox.push_back(Polygon3d());
auto &points = boundingBox[boundingBox.size()-1].getPoints();
points.push_back(Point( -radius, 0, -radius));
points.push_back(Point( -radius, .1, -radius));
points.push_back(Point( radius, .1, -radius));
points.push_back(Point( radius, 0, -radius));
points.push_back(Point( -radius, 0, -radius));
}
{
boundingBox.push_back(Polygon3d());
auto &points = boundingBox[boundingBox.size()-1].getPoints();
points.push_back(Point( -radius, 0, -radius));
points.push_back(Point( -radius, .1, -radius));
points.push_back(Point( -radius, .1, radius));
points.push_back(Point( -radius, 0, radius));
points.push_back(Point( -radius, 0, -radius));
}
{
boundingBox.push_back(Polygon3d());
auto &points = boundingBox[boundingBox.size()-1].getPoints();
points.push_back(Point( -radius, .1, -radius));
points.push_back(Point( radius, .1, -radius));
points.push_back(Point( radius, .1, radius));
points.push_back(Point( -radius, .1, radius));
points.push_back(Point( -radius, .1, -radius));
}
for(int x=0; x<boundingBox.size(); x++){
boundingBox[x].setCenter(center);
}
}
void Target::draw(){
//Do not draw us if we are already hit
if(this->state == DEAD)
return;
glPushMatrix();
// glTranslated(center.x,center.y,center.z);
// glRotated(90, 1, 0, 0);
// glRotated(this->rotation, 0, 1, 0);
// I used disks disk to generate the target.
GLUquadricObj *cylinder = gluNewQuadric();
GLUquadricObj *topDisk = gluNewQuadric();
GLUquadricObj *bottomDisk = gluNewQuadric();
gluQuadricDrawStyle(cylinder, GLU_FILL);
glBindTexture(GL_TEXTURE_2D,this->mascotChoice);
glColor3ub(255,255,255); // make it white so the texture is always perfect
glPushMatrix();
glTranslated(center.x,center.y,center.z);
glRotated(90, 1, 0, 0);
glRotated(180, 0, 0, 1);
glRotated(this->rotation, 0, 1, 0);
//Drawing and texturing a disk works a little differently, but is still very simple
//A quadric object is created as a pointer, then fed into the proper
//quadrick draw function. Objects seen above, function seen below.
gluCylinder(cylinder, this->radius, this->radius, .1, 30, 1);
//Takes the active texture and applies it linearly to the object.
gluQuadricTexture(topDisk, GL_TRUE);
gluDisk(topDisk, 0, this->radius, 30, 1);
glRotated(180, 0, 1, 0);
gluQuadricTexture(bottomDisk, GL_TRUE);
gluDisk(bottomDisk, 0, this->radius, 30, 1);
glPopMatrix();
gluDeleteQuadric(cylinder);
gluDeleteQuadric(topDisk);
gluDeleteQuadric(bottomDisk);
glPopMatrix();
glBindTexture(GL_TEXTURE_2D,0);
}
void Target::draw_map_marker(){
//Do not draw us if we are already hit
if(this->state == DEAD)
return;
glBindTexture(GL_TEXTURE_2D,this->mascotChoice);
glColor3ub(255,255,255); // make it white so the texture is always perfect
GLUquadricObj *topDisk = gluNewQuadric();
glPushMatrix();
glTranslated(center.x,center.y,200);
glRotated(180, 0, 0, 1);
gluQuadricTexture(topDisk, GL_TRUE);
gluDisk(topDisk, 0, this->radius*4, 30, 1);
glPopMatrix();
gluDeleteQuadric(topDisk);
glBindTexture(GL_TEXTURE_2D,0);
}
//Originally for the spinning targets, these would set the rotation of the targets. However, spinning was removed
//So this function is an artifact.
void Target::update(){
}
void Target::setRotation(double rot){
this->rotation = rot;
for(int x=0; x<boundingBox.size(); x++){
Vector temp(0,0,rot);
boundingBox[x].setRotation(temp);
}
}