implement option to lock camera to graph's center of mass

This commit is contained in:
2026-02-27 14:06:30 +01:00
parent e8bd90911d
commit b01cfdecfe
10 changed files with 85 additions and 38 deletions

View File

@ -24,7 +24,8 @@ public:
auto Pan(Vector2 last_mouse, Vector2 mouse) -> void;
auto Update(const Vector3 &current_target, bool lock) -> void;
auto Update(const Vector3 &current_target, const Vector3 &mass_center,
bool lock, bool mass_center_lock) -> void;
};
#endif

View File

@ -23,12 +23,14 @@ constexpr const char *FONT = "fonts/SpaceMono.ttf";
constexpr int FONT_SIZE = 26;
// Camera Controls
constexpr float CAMERA_FOV = 120.0;
constexpr float CAMERA_FOV = 90.0;
constexpr float FOV_SPEED = 1.0;
constexpr float MIN_FOV = 10.0;
constexpr float MAX_FOV = 180.0;
constexpr float CAMERA_DISTANCE = 20.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 FOV_SPEED = 1.0;
constexpr float ZOOM_MULTIPLIER = 4.0;
constexpr float PAN_SPEED = 2.0;
constexpr float PAN_MULTIPLIER = 10.0;
@ -42,16 +44,21 @@ 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 REST_LENGTH = 2.0; // Mass spring system
constexpr float REST_LENGTH = 3.0; // Mass spring system
constexpr float VERLET_DAMPENING = 0.05; // [0, 1]
constexpr float BH_FORCE = 2.0; // Barnes-Hut [1.0, 3.0]
constexpr float THETA = 0.9; // Barnes-Hut [0.5, 1.0]
constexpr float SOFTENING = 0.01; // Barnes-Hut [0.01, 1.0]
// Graph Drawing
constexpr Color EDGE_COLOR = DARKBLUE;
constexpr float VERTEX_SIZE = 0.5;
constexpr Color VERTEX_COLOR = GREEN;
constexpr Color EDGE_COLOR = DARKGREEN;
static const Color VERTEX_COLOR = Fade(BLUE, 0.5);
constexpr Color VERTEX_VISITED_COLOR = DARKBLUE;
constexpr Color VERTEX_PATH_COLOR = GREEN;
constexpr Color VERTEX_TARGET_COLOR = RED;
constexpr Color VERTEX_START_COLOR = ORANGE;
constexpr Color VERTEX_CURRENT_COLOR = PURPLE;
constexpr int DRAW_VERTICES_LIMIT = 1000000;
// Klotski Drawing
@ -62,6 +69,5 @@ constexpr Color BOARD_COLOR_FREE = RAYWHITE;
constexpr Color BLOCK_COLOR = DARKBLUE;
constexpr Color TARGET_BLOCK_COLOR = RED;
constexpr Color WALL_COLOR = BLACK;
constexpr Color GOAL_COLOR = ORANGE;
#endif

View File

@ -54,6 +54,7 @@ public:
// Camera
bool camera_lock = true;
bool camera_mass_center_lock = false;
bool camera_panning = false;
bool camera_rotating = false;
@ -102,6 +103,7 @@ public:
// Key actions
auto ToggleCameraLock() -> void;
auto ToggleCameraMassCenterLock() -> void;
auto ToggleCameraProjection() -> void;
auto MoveBlockNor() -> void;
auto MoveBlockWes() -> void;

View File

@ -68,13 +68,13 @@ public:
class MassSpringSystem {
private:
Octree octree;
#ifdef THREADPOOL
BS::thread_pool<BS::tp::none> threads;
#endif
public:
Octree octree;
// This is the main ownership of all the states/masses/springs.
std::vector<Mass> masses;
std::vector<Spring> springs;
@ -151,6 +151,7 @@ class ThreadedPhysics {
#endif
std::condition_variable_any data_ready_cnd;
std::condition_variable_any data_consumed_cnd;
Vector3 mass_center = Vector3Zero();
unsigned int ups = 0;
std::vector<Vector3> masses; // Read by renderer
bool data_ready = false;