summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2024-03-10 14:58:13 -0700
committerSchark <jordan@schark.online>2024-03-10 14:58:13 -0700
commit34fb121dd1583de307e8ba95cc3ad7fb2abb24e1 (patch)
tree2db66bc942abb7f44f691b62e6856fb7dd4d5f4d
parenta0480410651c65250ddb135cae61482796a9f086 (diff)
downloadgamedev-34fb121dd1583de307e8ba95cc3ad7fb2abb24e1.tar.gz
gamedev-34fb121dd1583de307e8ba95cc3ad7fb2abb24e1.zip
Messing around with real-time map modification
Diffstat (limited to '')
-rwxr-xr-xheight-map-display/height-map-displaybin17512 -> 0 bytes
-rw-r--r--height-map-display/src/main.c40
2 files changed, 23 insertions, 17 deletions
diff --git a/height-map-display/height-map-display b/height-map-display/height-map-display
deleted file mode 100755
index df41c3d..0000000
--- a/height-map-display/height-map-display
+++ /dev/null
Binary files differ
diff --git a/height-map-display/src/main.c b/height-map-display/src/main.c
index 95e6953..5979ed4 100644
--- a/height-map-display/src/main.c
+++ b/height-map-display/src/main.c
@@ -2,6 +2,7 @@
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <math.h>
+#include <stdbool.h>
#define MAP_HEIGHT 10
#define MAP_WIDTH 10
@@ -19,6 +20,8 @@
// {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
//};
+bool draw_grid = true;
+
int height_map[MAP_WIDTH][MAP_HEIGHT] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
@@ -109,23 +112,25 @@ void renderHeightMap() {
// draw grid
- glColor3f(0.0f, 0.0f, 0.0f);
- glLineWidth(1.0f);
- glBegin(GL_LINES);
-
- // Draw vertical grid lines
- for (int x = 0; x <= MAP_WIDTH; x++) {
- for (int y = 0; y < MAP_HEIGHT; y++) {
- glVertex3f(x, height_map[x][y] * scale_factor, y);
- glVertex3f(x, height_map[x][y + 1] * scale_factor, y + 1);
+ if(draw_grid) {
+ glColor3f(0.0f, 0.0f, 0.0f);
+ glLineWidth(1.0f);
+ glBegin(GL_LINES);
+
+ // Draw vertical grid lines
+ for (int x = 0; x <= MAP_WIDTH; x++) {
+ for (int y = 0; y < MAP_HEIGHT; y++) {
+ glVertex3f(x, height_map[x][y] * scale_factor, y);
+ glVertex3f(x, height_map[x][y + 1] * scale_factor, y + 1);
+ }
}
- }
- // Draw horizontal grid lines
- for (int y = 0; y <= MAP_HEIGHT; y++) {
- for (int x = 0; x < MAP_WIDTH; x++) {
- glVertex3f(x, height_map[x][y] * scale_factor, y);
- glVertex3f(x + 1, height_map[x + 1][y] * scale_factor, y);
+ // Draw horizontal grid lines
+ for (int y = 0; y <= MAP_HEIGHT; y++) {
+ for (int x = 0; x < MAP_WIDTH; x++) {
+ glVertex3f(x, height_map[x][y] * scale_factor, y);
+ glVertex3f(x + 1, height_map[x + 1][y] * scale_factor, y);
+ }
}
}
@@ -137,14 +142,15 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
const float camera_speed = 0.5f;
- if (key == GLFW_KEY_W && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_pos_z -= camera_speed; }
- else if (key == GLFW_KEY_S && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_pos_z += camera_speed; }
+ if (key == GLFW_KEY_W && (action == GLFW_PRESS || action == GLFW_REPEAT)) { height_map[5][4] += 1; }
+ else if (key == GLFW_KEY_S && (action == GLFW_PRESS || action == GLFW_REPEAT)) { height_map[5][4] -= 1; }
else if (key == GLFW_KEY_A && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_pos_x -= camera_speed; }
else if (key == GLFW_KEY_D && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_pos_x += camera_speed; }
else if (key == GLFW_KEY_Q && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_pitch -= camera_speed; }
else if (key == GLFW_KEY_E && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_pitch += camera_speed; }
else if (key == GLFW_KEY_Z && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_yaw -= camera_speed; }
else if (key == GLFW_KEY_C && (action == GLFW_PRESS || action == GLFW_REPEAT)) { camera_yaw += camera_speed; }
+ else if (key == GLFW_KEY_X && (action == GLFW_PRESS || action == GLFW_REPEAT)) { draw_grid = !draw_grid; }
}