diff options
author | Schark <jordan@schark.online> | 2024-03-17 23:38:26 -0700 |
---|---|---|
committer | Schark <jordan@schark.online> | 2024-03-17 23:38:26 -0700 |
commit | 69de9b320ad3c45e0a19845c88ae8323cfb59bf1 (patch) | |
tree | 1cd395c82347b4a2d89319ce234cc58963299986 /height-map-display/src | |
parent | a47debc60dbb096018add871432d8578081917f4 (diff) | |
download | gamedev-69de9b320ad3c45e0a19845c88ae8323cfb59bf1.tar.gz gamedev-69de9b320ad3c45e0a19845c88ae8323cfb59bf1.zip |
Debug changes
Diffstat (limited to 'height-map-display/src')
-rw-r--r-- | height-map-display/src/main.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/height-map-display/src/main.c b/height-map-display/src/main.c index 98b7198..19c5c2b 100644 --- a/height-map-display/src/main.c +++ b/height-map-display/src/main.c @@ -17,7 +17,12 @@ float camera_pos_z = 0.0f; float camera_yaw = 50.0f; // rotation around y-axis float camera_pitch = -50.0f; // rotation aroudn x-axis +float camera_speed = 0.1f; +float yaw_speed = 0.5f; +float pitch_speed = 0.5f; + bool draw_grid = true; +bool debug_spin = false; bool DEBUG = false; void logger(const char* msg) { @@ -31,9 +36,9 @@ void renderHeightMap(Square **squares) { logger("Init colors..."); float colors[4][3] = { {0.0f, 0.0f, 0.0f}, // init - {0.0f, 1.0f, 0.0f}, // default green + {0.2f, 0.7f, 0.2f}, // fairway green {0.0f, 0.5f, 0.0f}, // rough green - {0.5f, 1.0f, 0.5f}, // light green + {0.3f, 0.8f, 0.3f}, // green green }; float scale_factor = 1.0f; @@ -156,6 +161,36 @@ void free_squares(Square **squares, int X) { free(squares); } +// TODO: Move into controller struct, avoid key rollover +void process_input(GLFWwindow* window, Square* square) { + if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) + camera_pos_y -= camera_speed; + if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) + camera_pos_y += camera_speed; + if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) + camera_pos_x -= camera_speed; + if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) + camera_pos_x += camera_speed; + if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) + debug_spin = !debug_spin; + if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) + draw_grid = !draw_grid; + if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS) + square->terrain = TERRAIN_GREEN; + if (glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS) + square->terrain = TERRAIN_FAIRWAY; + if (glfwGetKey(window, GLFW_KEY_J) == GLFW_PRESS) + square->terrain = TERRAIN_ROUGH; + if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) + camera_pitch += pitch_speed; + if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) + camera_pitch -= pitch_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; +} + int main(int argc, char *argv[]) { logger("Initializing window..."); GLFWwindow* window; @@ -194,14 +229,18 @@ int main(int argc, char *argv[]) { Square **squares = initialize_squares(nodes, MAP_WIDTH, MAP_HEIGHT); // Debug stuff - squares[0][0].node_tl->elevation = 20.0f; + squares[1][1].node_tl->elevation = 5.0f; change_square_height(&squares[3][3], 5.0f); - change_square_terrain(&squares[2][5], TERRAIN_FAIRWAY); - change_square_terrain(&squares[3][5], TERRAIN_FAIRWAY); change_square_height(&squares[5][5], -5.0f); - change_square_terrain(&squares[5][5], TERRAIN_FAIRWAY); + change_square_terrain(&squares[1][6], TERRAIN_FAIRWAY); + change_square_terrain(&squares[1][5], TERRAIN_FAIRWAY); + change_square_terrain(&squares[1][4], TERRAIN_FAIRWAY); + change_square_terrain(&squares[1][3], TERRAIN_GREEN); while (!glfwWindowShouldClose(window)) { + logger("Processing input..."); + process_input(window, &squares[3][3]); + logger("Entering main loop..."); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -210,7 +249,9 @@ int main(int argc, char *argv[]) { glfwSwapBuffers(window); // Swap buffers to display the rendered image - camera_yaw = camera_yaw + 0.1f; + if (debug_spin) { + camera_yaw = camera_yaw + 0.1f; + } // Poll for and process events, wait for events if none are pending glfwWaitEventsTimeout(0.01); // Add a slight delay to reduce CPU usage } |