From 6bfe217fee558953f8daafada197d63b7639d1d4 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Fri, 6 Mar 2026 12:52:47 +0100 Subject: [PATCH] update color scheme --- include/config.hpp | 34 +++++++++++++++++----------------- include/input_handler.hpp | 2 ++ src/cpu_spring_system.cpp | 4 ++-- src/input_handler.cpp | 15 +++++++++++++-- src/orbit_camera.cpp | 6 +++++- src/renderer.cpp | 2 +- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 32bb99e..6f81771 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -3,7 +3,6 @@ #include - // TODO: Using the octree from the last frame completely breaks the physics :/ // #define ASYNC_OCTREE @@ -46,12 +45,14 @@ constexpr int FONT_SIZE = 26; // Camera Controls constexpr float CAMERA_FOV = 90.0; constexpr float FOV_SPEED = 1.0; +constexpr float FOV_MULTIPLIER = 4.0; constexpr float MIN_FOV = 10.0; -constexpr float MAX_FOV = 180.0; +constexpr float MAX_PERSP_FOV = 120.0; +constexpr float MAX_ORTHO_FOV = 540.0; constexpr float CAMERA_DISTANCE = 150.0; -constexpr float ZOOM_SPEED = 2.5; constexpr float MIN_CAMERA_DISTANCE = 2.0; constexpr float MAX_CAMERA_DISTANCE = 2000.0; +constexpr float ZOOM_SPEED = 2.5; constexpr float ZOOM_MULTIPLIER = 4.0; constexpr float PAN_SPEED = 2.0; constexpr float PAN_MULTIPLIER = 10.0; @@ -63,26 +64,26 @@ constexpr float TARGET_UPS = 90; // How often to update physics constexpr float TIMESTEP = 1.0 / TARGET_UPS; // Update interval in seconds constexpr float SIM_SPEED = 4.0; // How large each update should be constexpr float MASS = 1.0; // Mass spring system -constexpr float SPRING_CONSTANT = 5.0; // Mass spring system -constexpr float DAMPENING_CONSTANT = 1.0; // Mass spring system +constexpr float SPRING_K = 4.0; // Mass spring system +constexpr float DAMPENING_K = 1.0; // Mass spring system constexpr float REST_LENGTH = 3.0; // Mass spring system -constexpr float VERLET_DAMPENING = 0.05; // [0, 1] +constexpr float VERLET_DAMPENING = 0.1; // [0, 1] constexpr float BH_FORCE = 2.5; // Barnes-Hut [1.0, 3.0] constexpr float THETA = 0.8; // Barnes-Hut [0.5, 1.0] -constexpr float SOFTENING = 0.01; // Barnes-Hut [0.01, 1.0] +constexpr float SOFTENING = 0.05; // Barnes-Hut [0.01, 1.0] // Graph Drawing -static const Color EDGE_COLOR = Fade(PURPLE, 0.75); +static const Color EDGE_COLOR = Fade(BLUE, 0.3); constexpr float VERTEX_SIZE = 0.75; -static const Color VERTEX_COLOR = Fade(BLUE, 0.5); -constexpr Color VERTEX_VISITED_COLOR = DARKPURPLE; -constexpr Color VERTEX_PATH_COLOR = GREEN; -constexpr Color VERTEX_TARGET_COLOR = RED; -constexpr Color VERTEX_START_COLOR = ORANGE; -constexpr Color VERTEX_CURRENT_COLOR = DARKBLUE; -static const Color VERTEX_CLOSEST_COLOR = Fade(PINK, 0.85); -static const Color VERTEX_FARTHEST_COLOR = Fade(BLUE, 0.5); constexpr int DRAW_VERTICES_LIMIT = 1000000; +static const Color VERTEX_COLOR = Fade(BLUE, 0.8); +constexpr Color VERTEX_VISITED_COLOR = ORANGE; +constexpr Color VERTEX_START_COLOR = ORANGE; +constexpr Color VERTEX_CURRENT_COLOR = ORANGE; +constexpr Color VERTEX_PATH_COLOR = GREEN; +constexpr Color VERTEX_TARGET_COLOR = GREEN; +static const Color VERTEX_CLOSEST_COLOR = Fade(PINK, 1.0); +static const Color VERTEX_FARTHEST_COLOR = Fade(DARKBLUE, 0.8); // Klotski Drawing constexpr int BOARD_PADDING = 10; @@ -97,5 +98,4 @@ constexpr Color WALL_COLOR = BLACK; static constexpr int SMALL_TASK_BLOCK_SIZE = 256; // Weirdly larger blocks decrease performance... static constexpr int LARGE_TASK_BLOCK_SIZE = 256; - #endif \ No newline at end of file diff --git a/include/input_handler.hpp b/include/input_handler.hpp index b852b63..6d29be2 100644 --- a/include/input_handler.hpp +++ b/include/input_handler.hpp @@ -75,6 +75,7 @@ public: bool mark_path = false; bool mark_solutions = false; bool connect_solutions = false; + bool color_by_distance = false; // Camera bool camera_lock = true; @@ -139,6 +140,7 @@ public: auto clear_graph() -> void; auto toggle_mark_solutions() -> void; auto toggle_connect_solutions() -> void; + auto toggle_color_by_distance() -> void; auto toggle_mark_path() -> void; auto goto_optimal_next_state() const -> void; auto goto_most_distant_state() const -> void; diff --git a/src/cpu_spring_system.cpp b/src/cpu_spring_system.cpp index 4387a8a..64869e9 100644 --- a/src/cpu_spring_system.cpp +++ b/src/cpu_spring_system.cpp @@ -87,8 +87,8 @@ auto cpu_spring_system::calculate_spring_force(const size_t s) -> void const float inv_len = 1.0f / sqrt(sq_len); const float len = sq_len * inv_len; - const float hooke = SPRING_CONSTANT * (len - REST_LENGTH); - const float dampening = DAMPENING_CONSTANT * Vector3DotProduct(delta_vel, delta_pos) * inv_len; + const float hooke = SPRING_K * (len - REST_LENGTH); + const float dampening = DAMPENING_K * Vector3DotProduct(delta_vel, delta_pos) * inv_len; const Vector3 a_force = Vector3Scale(delta_pos, -(hooke + dampening) * inv_len); const Vector3 b_force = a_force * -1.0f; diff --git a/src/input_handler.cpp b/src/input_handler.cpp index 17f7733..976e2b0 100644 --- a/src/input_handler.cpp +++ b/src/input_handler.cpp @@ -42,6 +42,7 @@ auto input_handler::init_handlers() -> void register_key_pressed_handler(KEY_C, &input_handler::clear_graph); register_key_pressed_handler(KEY_I, &input_handler::toggle_mark_solutions); register_key_pressed_handler(KEY_O, &input_handler::toggle_connect_solutions); + register_key_pressed_handler(KEY_Z, &input_handler::toggle_color_by_distance); register_key_pressed_handler(KEY_TAB, &input_handler::toggle_editing); register_key_pressed_handler(KEY_F, &input_handler::toggle_restricted_movement); @@ -142,12 +143,17 @@ auto input_handler::camera_zoom() const -> void auto input_handler::camera_fov() const -> void { - if (!mouse_in_graph_pane() || !IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_LEFT_SHIFT)) { + if (!mouse_in_graph_pane() || !IsKeyDown(KEY_LEFT_CONTROL)) { return; } const float wheel = GetMouseWheelMove(); - camera.fov -= wheel * FOV_SPEED; + + if (IsKeyDown(KEY_LEFT_SHIFT)) { + camera.fov -= wheel * FOV_SPEED * FOV_MULTIPLIER; + } else { + camera.fov -= wheel * FOV_SPEED; + } } auto input_handler::select_block() -> void @@ -407,6 +413,11 @@ auto input_handler::toggle_connect_solutions() -> void connect_solutions = !connect_solutions; } +auto input_handler::toggle_color_by_distance() -> void +{ + color_by_distance = !color_by_distance; +} + auto input_handler::toggle_mark_path() -> void { mark_path = !mark_path; diff --git a/src/orbit_camera.cpp b/src/orbit_camera.cpp index 6619d6e..59fad2e 100644 --- a/src/orbit_camera.cpp +++ b/src/orbit_camera.cpp @@ -63,7 +63,11 @@ auto orbit_camera::update(const Vector3& current_target, const Vector3& mass_cen const float y = sin(angle_y) * actual_distance; const float z = cos(angle_y) * cos(angle_x) * actual_distance; - fov = Clamp(fov, MIN_FOV, MAX_FOV); + if (projection == CAMERA_ORTHOGRAPHIC) { + fov = Clamp(fov, MIN_FOV, MAX_ORTHO_FOV); + } else { + fov = Clamp(fov, MIN_FOV, MAX_PERSP_FOV); + } camera.position = Vector3Add(target, Vector3(x, y, z)); camera.target = target; diff --git a/src/renderer.cpp b/src/renderer.cpp index 0da9964..41af966 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -104,7 +104,7 @@ auto renderer::draw_mass_springs(const std::vector& masses) -> void } else if (state.get_visit_counts().at(mass) > 0) { // Visited vertex c = VERTEX_VISITED_COLOR; - } else if (distances.size() == masses.size()) { + } else if (input.color_by_distance && distances.size() == masses.size()) { c = lerp_color(VERTEX_FARTHEST_COLOR, VERTEX_CLOSEST_COLOR, static_cast(distances[mass]));