From a0480410651c65250ddb135cae61482796a9f086 Mon Sep 17 00:00:00 2001 From: Schark Date: Wed, 6 Mar 2024 02:43:51 -0800 Subject: Modified keybinds and colors for heightmap --- height-map-display/src/main.c | 55 ++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'height-map-display/src') diff --git a/height-map-display/src/main.c b/height-map-display/src/main.c index 5ad5c78..95e6953 100644 --- a/height-map-display/src/main.c +++ b/height-map-display/src/main.c @@ -6,16 +6,29 @@ #define MAP_HEIGHT 10 #define MAP_WIDTH 10 +//int height_map[MAP_WIDTH][MAP_HEIGHT] = { +// {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, +// {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}, +// {0, 1, 3, 3, 3, 3, 3, 3, 1, 0}, +// {0, 1, 3, 5, 5, 5, 5, 3, 1, 0}, +// {0, 1, 3, 5, 8, 8, 5, 3, 1, 0}, +// {0, 1, 3, 5, 8, 8, 5, 3, 1, 0}, +// {0, 1, 3, 5, 5, 5, 5, 3, 1, 0}, +// {0, 1, 3, 3, 3, 3, 3, 3, 1, 0}, +// {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}, +// {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, +//}; + int height_map[MAP_WIDTH][MAP_HEIGHT] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}, - {0, 1, 3, 3, 3, 3, 3, 3, 1, 0}, - {0, 1, 3, 5, 5, 5, 5, 3, 1, 0}, - {0, 1, 3, 5, 8, 8, 5, 3, 1, 0}, - {0, 1, 3, 5, 8, 8, 5, 3, 1, 0}, - {0, 1, 3, 5, 5, 5, 5, 3, 1, 0}, - {0, 1, 3, 3, 3, 3, 3, 3, 1, 0}, - {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}, + {0, 1, 1, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 0, 0, 0, -1, -2, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, -1, 0, 0}, + {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 2, 1, 0, 0, 0, 0}, + {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }; @@ -49,9 +62,9 @@ float camera_pitch = 0.0f; // rotation aroudn x-axis void renderHeightMap() { float colors[3][3] = { - {0.0f, 1.0f, 0.0f}, // Green - {0.5f, 0.5f, 0.5f}, // Gray - {1.0f, 1.0f, 1.0f} // White + {0.0f, 1.0f, 0.0f}, // default green + {0.0f, 0.0f, 1.0f}, // blue + {0.5f, 1.0f, 0.5f} // light green }; float scale_factor = 1.0f; @@ -82,8 +95,8 @@ void renderHeightMap() { float z1 = y; float* color = colors[0]; - if (y0 < 1.0f) { color = colors[1]; } - if (y0 < 0.5f) { color = colors[2]; } + if (y0 > 0.5f) { color = colors[2]; } + if (y0 < -0.5f) { color = colors[1]; } glColor3fv(color); glVertex3f(x0, y0, z0); @@ -124,14 +137,14 @@ 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) { camera_pos_z -= camera_speed; } - else if (key == GLFW_KEY_S && action == GLFW_PRESS) { camera_pos_z += camera_speed; } - else if (key == GLFW_KEY_A && action == GLFW_PRESS) { camera_pos_x -= camera_speed; } - else if (key == GLFW_KEY_D && action == GLFW_PRESS) { camera_pos_x += camera_speed; } - else if (key == GLFW_KEY_Q && action == GLFW_PRESS) { camera_pitch -= camera_speed; } - else if (key == GLFW_KEY_E && action == GLFW_PRESS) { camera_pitch += camera_speed; } - else if (key == GLFW_KEY_Z && action == GLFW_PRESS) { camera_yaw -= camera_speed; } - else if (key == GLFW_KEY_C && action == GLFW_PRESS) { camera_yaw += camera_speed; } + 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; } + 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; } } -- cgit v1.2.3-18-g5258