add basic input handling for klotski board/graph + populate graph based on klotski moves

This commit is contained in:
2026-02-17 15:12:32 +01:00
parent 9d0afffb57
commit 8d5a6a827c
6 changed files with 255 additions and 56 deletions

View File

@ -13,12 +13,18 @@ constexpr Color EDGE_COLOR = DARKGREEN;
constexpr float SIM_SPEED = 4.0;
constexpr float ROTATION_SPEED = 1.0;
constexpr float CAMERA_DISTANCE = 2.2;
constexpr float CULLING_TOLERANCE = 0.1; // percentage
constexpr float DEFAULT_SPRING_CONSTANT = 1.5;
constexpr float DEFAULT_DAMPENING_CONSTANT = 0.1;
constexpr float DEFAULT_REST_LENGTH = 0.5;
constexpr float DEFAULT_REPULSION_FORCE = 0.002;
constexpr int BOARD_PADDING = 5;
constexpr int BLOCK_PADDING = 5;
constexpr Color BLOCK_COLOR = DARKGREEN;
constexpr Color HL_BLOCK_COLOR = GREEN;
constexpr Color TARGET_BLOCK_COLOR = RED;
constexpr Color HL_TARGET_BLOCK_COLOR = ORANGE;
#endif

View File

@ -4,6 +4,8 @@
#include <cstddef>
#include <raylib.h>
#include <raymath.h>
#include <string>
#include <unordered_map>
#include <vector>
class Mass {
@ -88,7 +90,7 @@ using SpringList = std::vector<Spring>;
class MassSpringSystem {
public:
MassList masses;
std::unordered_map<std::string, Mass> masses;
SpringList springs;
public:
@ -102,19 +104,23 @@ public:
~MassSpringSystem() {};
public:
auto AddMass(float mass, Vector3 position, bool fixed) -> void;
auto AddMass(float mass, Vector3 position, bool fixed, std::string state)
-> void;
auto GetMass(const size_t index) -> Mass &;
auto GetMass(const std::string &state) -> Mass &;
auto AddSpring(int massA, int massB, float spring_constant,
float dampening_constant, float rest_length) -> void;
auto AddSpring(const std::string &massA, const std::string &massB,
float spring_constant, float dampening_constant,
float rest_length) -> void;
auto GetSpring(const size_t index) -> Spring &;
auto Clear() -> void;
auto ClearForces() -> void;
auto CalculateSpringForces() -> void;
auto CalculateRepulsionForces() -> void;
auto EulerUpdate(const float delta_time) -> void;
auto VerletUpdate(const float delta_time) -> void;

View File

@ -42,7 +42,8 @@ private:
auto Rotate(const Vector3 &a, const float cos_angle, const float sin_angle)
-> Vector3;
auto Translate(const Vector3 &a, const float distance) -> Vector3;
auto Translate(const Vector3 &a, const float distance, const float horizontal,
const float vertical) -> Vector3;
auto Project(const Vector3 &a) -> Vector2;
@ -51,12 +52,14 @@ private:
public:
auto Transform(Edge2Set &edges, Vertex2Set &vertices,
const MassSpringSystem &mass_springs, const float angle,
const float distance) -> void;
const float distance, const float horizontal,
const float vertical) -> void;
auto DrawMassSprings(const Edge2Set &edges, const Vertex2Set &vertices)
-> void;
auto DrawKlotski(State &state) -> void;
auto DrawKlotski(State &state, int hov_x, int hov_y, int sel_x, int sel_y)
-> void;
auto DrawTextures() -> void;
};