aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/camera.hpp
diff options
context:
space:
mode:
authorVaino Kauppila <vaino@vke.fi>2026-07-02 22:58:25 +0300
committerVaino Kauppila <vaino@vke.fi>2026-07-02 23:47:07 +0300
commitcd0c08dc7ce754473178ad3f32f7740a1dddc1eb (patch)
tree589c676b41d6f3d322ea5ce339ddb0811f29ec31 /src/engine/camera.hpp
downloadforts_clone-cd0c08dc7ce754473178ad3f32f7740a1dddc1eb.tar.gz
forts_clone-cd0c08dc7ce754473178ad3f32f7740a1dddc1eb.zip
Initial import: LibreForts (M0-M5 in progress)
Open-source Forts clone: custom C++20 engine + data-driven (Lua) 2D physics artillery RTS. - Building: node/strut graph on a stiff mass-spring solver (canon Forts model), triangulation rigidity, axial + 30-degree angle-stress breaking, cascading collapse, fire (DoT + spread), ground destroys debris. - Weapons (M4): cannon (ballistic) + laser (beam/ignite) with select-and-aim-in- arc UX; splash / beam damage; bg-brace passthrough. - Devices + economy (M5): reactors + win/loss + restart, mines/turbines/battery, metal deposits, storage caps, per-shot energy cost. - Data-driven via Lua/sol2 with a layered mod loader; enemy-fort scenario mod. - Renderer: SDL3 + textures + ImGui dev UI. stb_image + ImGui vendored. - Assets: CC0 placeholders only; real game art loaded at runtime from the user's own install via forts: paths (bring-your-own; nothing copyrighted committed). See README.md / CLAUDE.md and research/ + requirements/ for detail.
Diffstat (limited to 'src/engine/camera.hpp')
-rw-r--r--src/engine/camera.hpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/engine/camera.hpp b/src/engine/camera.hpp
new file mode 100644
index 0000000..ecaadc1
--- /dev/null
+++ b/src/engine/camera.hpp
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+
+// 2D orthographic camera. Works in world-space coordinates (Box2D space).
+// x+ = right, y+ = up.
+
+class Camera {
+public:
+ Camera() = default;
+
+ // Set the viewport size in pixels (window size).
+ void set_viewport(int width, int height);
+
+ // World-space position the camera is looking at.
+ void set_position(glm::vec2 pos);
+ glm::vec2 position() const { return pos_; }
+
+ // Zoom: higher = more zoomed in. Clamped to [min_zoom, max_zoom].
+ void set_zoom(float zoom);
+ float zoom() const { return zoom_; }
+
+ // Pan by delta in world units (not pixels).
+ void pan(glm::vec2 delta);
+
+ // Zoom by delta at the given screen position (world-space under cursor).
+ void zoom_at(float delta, glm::vec2 world_cursor);
+
+ // Build view-projection matrix. Call once per frame.
+ void compute_view_proj();
+
+ const float* view_proj() const { return &vp_[0][0]; }
+ glm::mat4 view() const { return view_; }
+ glm::mat4 proj() const { return proj_; }
+
+ // Convert screen coordinates (pixels, y-down) to world coordinates.
+ glm::vec2 screen_to_world(glm::vec2 screen) const;
+
+ int viewport_width() const { return vp_width_; }
+ int viewport_height() const { return vp_height_; }
+
+ // Config
+ float min_zoom = 0.1f;
+ float max_zoom = 200.0f;
+ float zoom_speed = 0.1f;
+ float pan_speed = 500.0f; // pixels per second
+
+private:
+ glm::vec2 pos_ = {0.0f, 5.0f}; // world center at start
+ float zoom_ = 10.0f; // pixels per world unit
+
+ int vp_width_ = 1280;
+ int vp_height_ = 720;
+
+ glm::mat4 view_ = glm::mat4(1.0f);
+ glm::mat4 proj_ = glm::mat4(1.0f);
+ float vp_[4][4] = {}; // column-major for bgfx
+};