-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathculture.cpp
218 lines (166 loc) · 3.76 KB
/
culture.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "culture.h"
//temporary please delete
static int x = 0;
static int y = 0;
Culture::Culture()
{
}
void Culture::calcAverage()
{
//number of personalities to loop through
int numOfPersonalities = personalities.size();
//number of attributed a personality has
int numOfAttributes = personalities[0].getAll().size();
//for calculating average of attributes
GLfloat sum = 0;
GLfloat avg = 0;
//clear average so it can be reused
average.clear();
//loop through attributes
for(int i = 0; i < numOfAttributes; i++)
{
//loop through personalities
for(int e = 0; e < numOfPersonalities; e++)
{
//get and hold data from personality at index of current loop iteration
curPersonality = personalities[e].getAll();
//add current personality's current attribute to sum
sum += curPersonality[i];
//clear vector so it can hold values of next personality
curPersonality.clear();
}
//find average of attributes
avg = sum / numOfPersonalities;
//add current attribute to average
average.push_back(avg);
//clear sum
sum = 0;
}
}
void Culture::normalize()
{
//number of personalities to loop through
int numOfPersonalities = personalities.size();
for(int i = 0; i < numOfPersonalities; i++)
{
personalities[i].changeTowardAverage(getAverage());
}
}
//for debugging. remove eventually
vector<GLfloat> Culture::getAverage()
{
return average;
}
void Culture::addPersonality()
{
}
void Culture::birthPersonality()
{
Personality newPers;
newPers.randomize();
//temporary please delete
x += 200;
y += 200;
newPers.setX(x);
newPers.setY(y);
personalities.push_back(newPers);
calcAverage();
}
void Culture::calcMotion()
{
}
void Culture::calcOutline()
{
int curPos = 0;
leftmost = 0;
rightmost = 0;
highest = 0;
lowest = 0;
//left line
for(int i = 0; i < personalities.size(); i++)
{
curPos = personalities[i].getX();
if(i == 0)
{
leftmost = curPos - 25;
}
if(curPos < leftmost)
{
leftmost = curPos - 25;
}
}
//right line
for(int i = 0; i < personalities.size(); i++)
{
curPos = personalities[i].getX();
if(curPos > rightmost)
{
rightmost = curPos + 80;
}
}
//top line
for(int i = 0; i < personalities.size(); i++)
{
curPos = personalities[i].getY();
if(i == 0)
{
highest = curPos;
}
if(curPos < highest)
{
highest = curPos;
}
}
//bottom line
for(int i = 0; i < personalities.size(); i++)
{
curPos = personalities[i].getY();
if(curPos > lowest)
{
lowest = curPos + 100;
}
}
}
void Culture::move()
{
calcMotion();
int size = personalities.size();
//send movements to personalities
for(int i = 0; i < size; i++)
{
personalities[i].move();
}
calcOutline();
}
void Culture::draw()
{
int size = personalities.size();
for(int i = 0; i < size; i++)
{
personalities[i].draw();
}
}
void Culture::drawOutline()
{
//set line width
glLineWidth(1.0f);
//Start lines
glBegin( GL_LINES );
//Set color
glColor4f(0.5f, 0.3f, 0.0f, 0.5f);
//Draw line
glVertex3f(leftmost, highest, 0);
glVertex3f(leftmost, lowest, 0);
glVertex3f(rightmost, highest, 0);
glVertex3f(rightmost, lowest, 0);
glVertex3f(leftmost, lowest, 0);
glVertex3f(rightmost, lowest, 0);
glVertex3f(leftmost, highest, 0);
glVertex3f(rightmost, highest, 0);
//End lines
glEnd();
//Reset
glLoadIdentity();
//Reset color
glColor4f(0.5f, 0.3f, 0.0f, 1.0f);
}