-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildModels.hpp
188 lines (155 loc) · 6.7 KB
/
BuildModels.hpp
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
void SandroRun::initRoadModel() {
const int period = 12;
for (int i = 0; i < NUM_TERRAIN_REPETITIONS * period; i++) {
glm::vec3 surface = glm::vec3({10.0f, 0.0f, (-i * 10.0f) + 5.0f});
glm::vec3 normal = glm::vec3({0.0f, 1.0f, 0.0f});
glm::vec2 UV = glm::vec2({0.0f, 0.0f});
MRoad.vertices.push_back({surface, normal, UV});
surface = glm::vec3({-10.0f, 0.0f, (-i * 10.0f) + 5.0f});
UV = glm::vec2({0.0f, 1.0f});
MRoad.vertices.push_back({surface, normal, UV});
surface = glm::vec3({-10.0f, 0.0f, (-i * 10.0f) - 5.0f});
UV = glm::vec2({1.0f, 1.0f});
MRoad.vertices.push_back({surface, normal, UV});
surface = glm::vec3({10.0f, 0.0f, (-i * 10.0f) - 5.0f});
UV = glm::vec2({1.0f, 0.0f});
MRoad.vertices.push_back({surface, normal, UV});
}
for (int i = 0; i < NUM_TERRAIN_REPETITIONS * period; ++i) {
MRoad.indices.push_back(i * 4);
MRoad.indices.push_back(i * 4 + 2);
MRoad.indices.push_back(i * 4 + 1);
MRoad.indices.push_back(i * 4 + 2);
MRoad.indices.push_back(i * 4);
MRoad.indices.push_back(i * 4 + 3);
}
MRoad.initMesh(this, &VMesh);
TRoad.init(this, "textures/road.png");
}
void SandroRun::initTerrainModel() {
// Right side
float uPos = 0.0f;
int inv = -1;
const int period = 120;
for (int i = 0; i <= NUM_TERRAIN_REPETITIONS * period; i++) {
for (int j = 0; j <= 60; j++) {
float x = (float) j + 10.0f;
float z = (float) -i + 5.0f;
float y = sin((x - 10.0f) * M_PI_(30.0f)) * sin((z + 5.0f) * M_PI_(30.0f)) * 5;
glm::vec3 normal;
if (y < 0) {
y = 0;
normal = glm::vec3({0, 1, 0});
} else {
glm::vec3 d_surface_x = glm::vec3(
{1, M_PI_(6.0f) * cos(M_PI_(30.0f) * (x - 10.0f)) * sin(M_PI_(30.0f) * (z + 5.0f)), 0});
glm::vec3 d_surface_z = glm::vec3(
{0, M_PI_(6.0f) * sin(M_PI_(30.0f) * (x - 10.0f)) * cos(M_PI_(30.0f) * (z + 5.0f)), 1});
normal = cross(d_surface_z, d_surface_x);
normal = glm::normalize(normal);
}
glm::vec3 surface = glm::vec3({x, y, z});
MTerrain.vertices.push_back({surface, normal, {uPos, j / 60.0f}});
}
if (i % 60 == 0) {
inv *= -1;
}
uPos += inv * 1.0f / 60.0f;
}
for (int i = 0; i < NUM_TERRAIN_REPETITIONS * period; ++i) {
for (int j = 0; j < 60; ++j) {
MTerrain.indices.push_back(i * 61 + j);
MTerrain.indices.push_back(i * 61 + j + 1);
MTerrain.indices.push_back((i + 1) * 61 + j);
MTerrain.indices.push_back((i + 1) * 61 + j);
MTerrain.indices.push_back(i * 61 + j + 1);
MTerrain.indices.push_back((i + 1) * 61 + j + 1);
}
}
uPos = 0.0f;
inv = -1;
// Left side
for (int i = 0; i <= NUM_TERRAIN_REPETITIONS * period; i++) {
for (int j = 0; j <= 60; j++) {
float x = (float) -j - 10.0f;
float z = (float) -i + 5.0f;
float y = sin((x + 10.0f) * M_PI_(30.0f)) * sin((z + 5.0f) * M_PI_(30.0f)) * 5;
if (y < 0) { y = 0; }
glm::vec3 surface = glm::vec3({x, y, z});
glm::vec3 d_surface_x = glm::vec3(
{1, M_PI_(6.0f) * cos(M_PI_(30.0f) * (x + 10.0f)) * sin(M_PI_(30.0f) * (z + 5.0f)), 0});
glm::vec3 d_surface_z = glm::vec3(
{0, M_PI_(6.0f) * sin(M_PI_(30.0f) * (x + 10.0f)) * cos(M_PI_(30.0f) * (z + 5.0f)), 1});
glm::vec3 normal = cross(d_surface_z, d_surface_x);
normal = glm::normalize(normal);
MTerrain.vertices.push_back({surface, normal, {uPos, j / 60.0f}});
}
if (i % 60 == 0) {
inv *= -1;
}
uPos += inv * 1.0f / 60.0f;
}
int offset = (NUM_TERRAIN_REPETITIONS * period + 1) * 61;
for (int i = 0; i < NUM_TERRAIN_REPETITIONS * period; ++i) {
for (int j = 0; j < 60; ++j) {
MTerrain.indices.push_back(offset + i * 61 + j);
MTerrain.indices.push_back(offset + (i + 1) * 61 + j);
MTerrain.indices.push_back(offset + i * 61 + j + 1);
MTerrain.indices.push_back(offset + (i + 1) * 61 + j);
MTerrain.indices.push_back(offset + (i + 1) * 61 + j + 1);
MTerrain.indices.push_back(offset + i * 61 + j + 1);
}
}
MTerrain.initMesh(this, &VMesh);
TTerrain.init(this, "textures/grass.jpg");
}
void SandroRun::initSkyboxModel() {
MSkybox.init(this, &VMesh, "models/skyboxCube.obj", OBJ);
const char *T2fn_day[] = {
"textures/skybox/day/left.png",
"textures/skybox/day/right.png",
"textures/skybox/day/top.png",
"textures/skybox/day/bottom.png",
"textures/skybox/day/back.png",
"textures/skybox/day/front.png"
};
TSkybox[0].initCubic(this, T2fn_day);
const char *T2fn_sunset[] = {
"textures/skybox/sunset/left.png",
"textures/skybox/sunset/right.png",
"textures/skybox/sunset/top.png",
"textures/skybox/sunset/bottom.png",
"textures/skybox/sunset/back.png",
"textures/skybox/sunset/front.png"
};
TSkybox[1].initCubic(this, T2fn_sunset);
const char *T2fn_night[] = {
"textures/skybox/night/left.png",
"textures/skybox/night/right.png",
"textures/skybox/night/top.png",
"textures/skybox/night/bottom.png",
"textures/skybox/night/back.png",
"textures/skybox/night/front.png"
};
TSkybox[2].initCubic(this, T2fn_night);
}
void SandroRun::initSplashModel() {
MSplash.vertices = {{{-1.0f, -1.0f}, {0.0f, 0.0f}},
{{-1.0f, 1.0f}, {0.0f, 1.0f}},
{{1.0f, -1.0f}, {1.0f, 0.0f}},
{{1.0f, 1.0f}, {1.0f, 1.0f}}};
MSplash.indices = {0, 1, 2, 1, 2, 3};
MSplash.initMesh(this, &VOverlay);
TSplashStart.init(this, "textures/splash_screens/splashScreenStart.png");
TSplashEnd.init(this, "textures/splash_screens/splashScreenEnd.png");
}
void SandroRun::initHUD() {
MSpeedometer.vertices = {{{-1.0f, -1.0f}, {0.0f, 0.0f}},
{{-1.0f, 1.0f}, {0.0f, 1.0f}},
{{1.0f, -1.0f}, {1.0f, 0.0f}},
{{1.0f, 1.0f}, {1.0f, 1.0f}}};
MSpeedometer.indices = {0, 1, 2, 1, 2, 3};
MSpeedometer.initMesh(this, &VOverlay);
TSpeedometer.init(this, "textures/hud/speedometer.png");
TSpeedometerHand.init(this, "textures/hud/speedometer_hand.png");
}