-
Notifications
You must be signed in to change notification settings - Fork 0
/
building.cpp
88 lines (76 loc) · 2.32 KB
/
building.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
#include "building.h"
#include "buildings/apartmentHighrise.cpp"
#include "buildings/generic1.cpp"
#include "buildings/genericOctogon.cpp"
const double Building::sidewalkWidth = 3;
const double Building::sidewalkThickness = 0.15;
const double Building::maxBuildingWidth = 40;
const double Building::distanceBetweenBuildings = 60;
const double Building::streetWidth = 60 - 40; // distanceBetweenBuildings - maxBuildingWidth;
Building::Building(Point center){
this->center = center;
const int numOfBuildings = 2;
switch(rand() % numOfBuildings){
case 0:
// createGeneric1Building(model,boundingBox);
apartmentHighriseBuilding(DrawableObject::model,DrawableObject::boundingBox,subLists,sideNorth,sideEast,sideSouth,sideWest);
for(int x=0; x<boundingBox.size(); x++)
boundingBox[x].setCenter(center);
break;
case 1:
createGenericOctogonBuilding(DrawableObject::model,DrawableObject::boundingBox);
for(int x=0; x<boundingBox.size(); x++)
boundingBox[x].setCenter(center);
break;
// === insert new building before here ===
default:
createGeneric1Building(DrawableObject::model,DrawableObject::boundingBox);
for(int x=0; x<boundingBox.size(); x++)
boundingBox[x].setCenter(center);
printf("Building selection out of range\n");
break;
}
listName = glGenLists(1);
glNewList(listName,GL_COMPILE);
this->draw_CPU();
glEndList();
}
void Building::draw(){
int dx = GLOBAL.CAMERA_POS.x - this->center.x;
int dy = GLOBAL.CAMERA_POS.y - this->center.y;
if( abs(dx) > 2*distanceBetweenBuildings &&
abs(dy) > 2*distanceBetweenBuildings )
return;
glPushMatrix();
glTranslated(center.x,center.y,center.z);
glCallList(listName);
if(dy>0){
for(int x=0; x<sideNorth.size(); x++)
glCallList(sideNorth[x]);
}else{
for(int x=0; x<sideSouth.size(); x++)
glCallList(sideSouth[x]);
}
if(dx>0){
for(int x=0; x<sideEast.size(); x++)
glCallList(sideEast[x]);
}else{
for(int x=0; x<sideWest.size(); x++)
glCallList(sideWest[x]);
}
glPopMatrix();
// this->draw_CPU();
}
void Building::draw_simple(){
glPushMatrix();
glTranslated(center.x,center.y,center.z);
glCallList(listName);
glPopMatrix();
// this->draw_CPU();
}
void Building::draw_CPU(){
for(int x=0; x<model.size(); x++)
this->model[x].getTransform().draw_static();
for(int x=0; x<subLists.size(); x++)
glCallList(subLists[x]);
}