summaryrefslogtreecommitdiff
path: root/height-map-display/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'height-map-display/src/main.c')
-rw-r--r--height-map-display/src/main.c54
1 files changed, 47 insertions, 7 deletions
diff --git a/height-map-display/src/main.c b/height-map-display/src/main.c
index 19c5c2b..aeb599d 100644
--- a/height-map-display/src/main.c
+++ b/height-map-display/src/main.c
@@ -82,12 +82,43 @@ void renderHeightMap(Square **squares) {
// draw grid
logger("Init grid...");
if (draw_grid) {
- glColor3f(0.0f, 0.0f, 0.0f);
+
+ for (int x = 0; x <= MAP_WIDTH - 2; x++) {
+ for (int y = 0; y < MAP_HEIGHT - 2; y++) {
+ if (squares[x][y].selected) {
+
+ glColor3f(1.0f, 1.0f, 0.0f);
+ glLineWidth(3.0f);
+ glBegin(GL_LINES);
+
+ // Top edge
+ glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
+ glVertex3f(x + 1, squares[x][y].node_tr->elevation * scale_factor, y);
+
+ // Bottom edge
+ glVertex3f(x, squares[x][y].node_bl->elevation * scale_factor, y + 1);
+ glVertex3f(x + 1, squares[x][y].node_br->elevation * scale_factor, y + 1);
+
+ // Left edge
+ glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
+ glVertex3f(x, squares[x][y].node_bl->elevation * scale_factor, y + 1);
+
+ // Right edge
+ glVertex3f(x + 1, squares[x][y].node_tr->elevation * scale_factor, y);
+ glVertex3f(x + 1, squares[x][y].node_br->elevation * scale_factor, y + 1);
+
+ glEnd();
+ }
+ }
+ }
+
glLineWidth(3.0f);
glBegin(GL_LINES);
+ glColor3f(0.0f, 0.0f, 0.0f);
for (int x = 0; x <= MAP_WIDTH - 2; x++) {
for (int y = 0; y < MAP_HEIGHT - 2; y++) {
+ if (squares[x][y].selected) { continue; }
glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
glVertex3f(x, squares[x][y + 1].node_tl->elevation * scale_factor, y + 1);
}
@@ -95,16 +126,17 @@ void renderHeightMap(Square **squares) {
for (int y = 0; y <= MAP_HEIGHT - 2; y++) {
for (int x = 0; x < MAP_WIDTH - 2; x++) {
+ if (squares[x][y].selected) { continue; }
glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
glVertex3f(x + 1, squares[x + 1][y].node_tl->elevation * scale_factor, y);
}
}
+ logger("Init end...");
+ glEnd();
// TODO: Draw final column of grid manually
}
- logger("Init end...");
- glEnd();
}
// Function to initialize nodes
@@ -118,6 +150,7 @@ Node*** initialize_nodes(int X, int Y) {
nodes[i][j]->x = i;
nodes[i][j]->y = j;
nodes[i][j]->elevation = 0.0f;
+ nodes[i][j]->selected = false;
}
}
return nodes;
@@ -135,6 +168,7 @@ Square** initialize_squares(Node ***nodes, int X, int Y) {
squares[i][j].node_bl = nodes[i][j+1];
squares[i][j].node_br = nodes[i+1][j+1];
squares[i][j].terrain = TERRAIN_ROUGH;
+ squares[i][j].selected = false;
}
}
return squares;
@@ -181,13 +215,18 @@ void process_input(GLFWwindow* window, Square* square) {
square->terrain = TERRAIN_FAIRWAY;
if (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS)
square->terrain = TERRAIN_ROUGH;
+ if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
+ camera_yaw -= yaw_speed;
+ if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
+ camera_yaw += yaw_speed;
+
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
- camera_pitch += pitch_speed;
+ camera_yaw += yaw_speed;
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
- camera_pitch -= pitch_speed;
+ camera_yaw += yaw_speed;
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
- camera_yaw -= yaw_speed;
- if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
+ camera_yaw += yaw_speed;
+ if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
camera_yaw += yaw_speed;
}
@@ -236,6 +275,7 @@ int main(int argc, char *argv[]) {
change_square_terrain(&squares[1][5], TERRAIN_FAIRWAY);
change_square_terrain(&squares[1][4], TERRAIN_FAIRWAY);
change_square_terrain(&squares[1][3], TERRAIN_GREEN);
+ squares[3][3].selected = true;
while (!glfwWindowShouldClose(window)) {
logger("Processing input...");