-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBird.h
More file actions
199 lines (165 loc) · 3.56 KB
/
Bird.h
File metadata and controls
199 lines (165 loc) · 3.56 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
#ifndef __BIRD_H_INCLUDE__
#define __BIRD_H_INCLUDE__
#include "MobileObject.h"
#include <ctime>
#include <algorithm>
//#include <stdlib.h>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
class Bird : public MobileObject
{
float wingAngle; // this will go between -90 & 90
int wingDirection; // says if the wing is going down or up
float wingSpan;
float tipHeight; // use as an alternative to wingAngle. affects the vertical positio of the wing tip
float tipBoundary;
float r, g, blue; // color
public:
Bird();
Bird(float a, float b, float c, float di, float size);
//~Bird();
void update(float X, float Y, float Z, float Direction);
void draw();
void updateWings(float incrementAmount);
private:
void drawWing(int wing);
};
Bird::Bird()
{
srand(time(0));
wingAngle = rand() % 90; // start them off in random positions
// randomly set wing direction
if ((int)wingAngle % 2 == 0)
wingDirection = -1;
else
wingDirection = 1;
directionAngle = 0.0;
wingSpan = rand() % 5; // random wing length
x = 0.0; y = 0.0; z = 0.0;
gone = false;
distanceTraveled = 0;
destroy = false;
// size of bird
radius = 0.5;
goneDistance = radius * 6;
}
Bird::Bird(float a, float b, float c, float di, float size)
{
srand(time(0));
wingAngle = rand() % 90; // start them off in random positions
// randomly set wing direction
if ((int)wingAngle % 2 == 0)
wingDirection = -1;
else
wingDirection = 1;
directionAngle = di;
wingSpan = rand() % 3; // random wing length
int temp = 3 * size;
tipHeight = rand() % temp;
if ((int)tipHeight % 2 == 0)
tipHeight = -tipHeight;
tipBoundary = size;
x = a;
y = b;
z = c;
gone = false;
distanceTraveled = 0;
destroy = false;
// size of bird
radius = size;
goneDistance = radius * 6;
r = (rand() % 7) / 10.0;
if (r < 0.2)
r = 0.4;
g = (rand() % 6) / 10.0;
if (g < 0.2)
g = 0.4;
blue = (rand() % 7) / 10.0;
if (blue < 0.2)
blue = 0.4;
}
void Bird::update(float X, float Y, float Z, float Direction)
{
x = X;
y = Y;
z = Z;
directionAngle = Direction;
}
void Bird::draw()
{
GLUquadric *quadd = gluNewQuadric();
// Draw body
glPushMatrix();
srand(time(0));
glTranslatef(x, y, z);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//glColor3f(1.0 - r, 1.0 - g, 1.0 - blue);
glColor3f(r, g, blue);
// Cull the back faces of the sphere.
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
gluSphere(quadd, radius, 20, 20);
glDisable(GL_CULL_FACE);
// draw wings
drawWing(0);
drawWing(1);
glPopMatrix();
}
//Bird::~Bird()
//{
//}
void Bird::drawWing(int wing)
{
float zOffset = 0.5 * radius;
float constant = 1;
switch (wing)
{
case 0:
break;
case 1:
constant = -constant;
break;
default:
return;
break;
}
glBegin(GL_POLYGON);
glVertex3f(constant*radius, 0.0, zOffset); // front hinge
glVertex3f(constant*(radius + wingSpan), tipHeight, zOffset); // front tip
glVertex3f(constant*(radius + wingSpan), tipHeight, -zOffset); // rear tip
glVertex3f(constant*radius, 0.0, -zOffset); // rear hinge
glVertex3f(constant*radius, 0.0, zOffset); // front hinge
glEnd();
}
void Bird::updateWings(float incrementAmount)
{
if (rand() % 2 == 0)
incrementAmount = incrementAmount * 0.8;
switch (wingDirection)
{
case -1:
if (tipHeight - incrementAmount >= -tipBoundary)
tipHeight -= incrementAmount;
else
{
wingDirection = 1;
tipHeight = -tipBoundary;
}
break;
case 1:
if (tipHeight + incrementAmount <= tipBoundary)
tipHeight += incrementAmount;
else
{
wingDirection = -1;
tipHeight = tipBoundary;
}
break;
default:
break;
}
}
#endif