-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSilo.cpp
More file actions
256 lines (195 loc) · 6.29 KB
/
Silo.cpp
File metadata and controls
256 lines (195 loc) · 6.29 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include "stdafx.h"
#include "Silo.h"
//---------------------------------------------------------------------
// Method: init
// Author: Rick Sanders
// Function: Initializes a 3D Silo.
// The silo is oriented in the the xz plane.
// Compiles a display list to be used when drawing the silo.
// Parameters:
// x - x coordinate of the middle of the silo
// y - y coordinate of the middle of the silo
// z - z coordinate of the middle of the silo
// siloRadius - radius of silo.
// siloHeight - the height of the silo.
//
// Returns: None
// Called By:
// Calls: None
//---------------------------------------------------------------------
void Silo::init(float xPos, float yPos, float zPos, float siloRadius,
float siloHeight, int brickTex, int shingleTex)
{
radius = siloRadius;
height = siloHeight;
x = xPos;
y = yPos;
z = zPos;
explosion = 0;
destroyed = false;
forwardCollided = false;
backwardCollided = false;
damageCapacity = (2.0f * 3.14159f * radius * height) / 100.0f;
pointValue = (int) damageCapacity;
brickTexture = brickTex;
shingleTexture = shingleTex;
//load the brick texture
// loadBrickTexture();
GLUquadricObj *qobj;
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
gluQuadricOrientation(qobj, GLU_OUTSIDE);
gluQuadricNormals(qobj, GLU_SMOOTH);
gluQuadricTexture(qobj, GL_TRUE);
siloList = glGenLists(1);
glNewList(siloList, GL_COMPILE);
glPushMatrix();
//material property values
GLfloat silo_spec[] = {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat silo_mat_dif[] = {0.7f, 0.4f, 0.1f, 1.0f};
// float p[3][3]; // array to hold coords for the silo.
//create the list for generating a silo
//define the color and material properties
GLfloat color1[3] = { 0.5f, 0.5f, 0.5f };
glMaterialfv(GL_FRONT, GL_SPECULAR, silo_spec);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, silo_mat_dif);
// enable texture mapping of the silo
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, brickTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPEAT);
/* glTexGend(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGend(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
*/
// create the quadric
glTranslatef(0.0f, siloHeight, 0.0f);
glRotatef(90, 1.0f, 0.0f, 0.0f);
gluCylinder(qobj, radius, radius, height,
15, 5);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
// loadShingleTexture();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, shingleTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexGend(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGend(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
gluSphere(qobj, radius, 15, 5);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
glEndList();
} // end initSilo
//---------------------------------------------------------------------
// Method: draw
// Function: Draws a house object with the size and location specified
// by the class data members.
// Parameters: None
//
// Returns: Void
// Called By:
// Calls: None
//---------------------------------------------------------------------
void Silo::draw()
{
glCallList(siloList);
} // end draw
GLfloat Silo::getRadius() {
return radius;
} // end getRadius
GLfloat Silo::getX() {
return x;
} // end getX
GLfloat Silo::getZ() {
return z;
} // end getZ
void Silo::loadBrickTexture()
{
int numOfTextures = 1;
glGenTextures(numOfTextures, &brickTexture);
ASSERT(brickTexture != 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glBindTexture(GL_TEXTURE_2D, brickTexture);
AUX_RGBImageRec* m_pRGBImage;
m_pRGBImage = auxDIBImageLoadA("tiles.bmp");
ASSERT (m_pRGBImage != 0);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR );
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB,
m_pRGBImage->sizeX,
m_pRGBImage->sizeY,
GL_RGB, GL_UNSIGNED_BYTE,
m_pRGBImage->data );
LocalFree( m_pRGBImage );
}
void Silo::loadShingleTexture()
{
int numOfTextures = 1;
glGenTextures(numOfTextures, &shingleTexture);
ASSERT(shingleTexture != 0);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glBindTexture(GL_TEXTURE_2D, shingleTexture);
AUX_RGBImageRec* m_pRGBImage;
m_pRGBImage = auxDIBImageLoadA("shingle.bmp");
ASSERT (m_pRGBImage != 0);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR );
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB,
m_pRGBImage->sizeX,
m_pRGBImage->sizeY,
GL_RGB, GL_UNSIGNED_BYTE,
m_pRGBImage->data );
LocalFree( m_pRGBImage );
}
bool Silo::isDestroyed() {
return destroyed;
} // end isDestroyed
void Silo::startExplosion() {
explosion = new Explosion();
explosion->init(radius);
} // end startExplosion
void Silo::destroy() {
destroyed = true;
} // end destroy
Explosion* Silo::getExplosion() {
return explosion;
} // end getExplosion
void Silo::takeDamage(GLfloat damage) {
damageCapacity -= damage;
if (damageCapacity <= 0.0) {
destroyed = true;
} // end if
} // end takeDamage
void Silo::forwardCollide() {
forwardCollided = true;
} // end forwardCollide
void Silo::backwardCollide() {
backwardCollided = true;
} // end backwardCollide
void Silo::unForwardCollide() {
forwardCollided = false;
} // end unForwardCollide
void Silo::unBackwardCollide() {
backwardCollided = false;
} // end unBackwardCollide
bool Silo::isForwardCollided() {
return forwardCollided;
} // end isForwardCollided
bool Silo::isBackwardCollided() {
return backwardCollided;
} // end isBackwardCollided
int Silo::getPointValue() {
return pointValue;
} // end getPointValue
// *********************** END SILO CLASS *****************************