aboutsummaryrefslogtreecommitdiff
path: root/src/scene
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-23 21:55:36 +0200
committerhachem <im@hachem.wtf>2026-08-23 21:55:36 +0200
commit5ea6c14c0e14bacee766ce1280ab2c71564e05ec (patch)
tree34620051e8eaf65db4ff9cd40ffd982a03e1ccc8 /src/scene
parent8742482311b86bb705d93336805ab26881e96070 (diff)
[feat]: implement ui layer arch
Diffstat (limited to 'src/scene')
-rw-r--r--src/scene/scene.cpp65
-rw-r--r--src/scene/scene.h39
-rw-r--r--src/scene/scene_types.h32
3 files changed, 136 insertions, 0 deletions
diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp
new file mode 100644
index 0000000..db70a8d
--- /dev/null
+++ b/src/scene/scene.cpp
@@ -0,0 +1,65 @@
+#include "scene.h"
+
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+#include <algorithm>
+#include <cmath>
+#include <numbers>
+
+namespace Donut
+{
+ Scene::Scene()
+ {
+ // Black-hole camera: large-scale orbital viewer outside the disk.
+ sim_camera.set_camera_mode(CameraMode::Orbital);
+ sim_camera.set_orbital_target(glm::vec3(0.0f));
+ sim_camera.set_orbital_radius(4e11); // ~31 r_s: outside the 12 r_s disk
+ sim_camera.set_orbital_limits(2.2e11, 1.5e12);
+ sim_camera.set_orbital_speed(0.01f);
+ sim_camera.set_zoom_speed(3e10);
+ sim_camera.set_azimuth(0.0f);
+ sim_camera.set_elevation(1.25f);
+
+ // Scene camera: normal-scale orbital world-builder viewer.
+ scene_camera.set_camera_mode(CameraMode::Orbital);
+ scene_camera.set_orbital_target(glm::vec3(0.0f));
+ scene_camera.set_orbital_radius(15.0);
+ scene_camera.set_orbital_limits(2.0, 200.0);
+ scene_camera.set_orbital_speed(0.01f);
+ scene_camera.set_zoom_speed(2.0);
+ scene_camera.set_azimuth(0.0f);
+ scene_camera.set_elevation((float)std::numbers::pi / 3.0f);
+ scene_camera.update_orbital();
+ }
+
+ auto Scene::reset_sim_camera() -> void
+ {
+ sim_camera.set_camera_mode(CameraMode::Orbital);
+ sim_camera.set_orbital_radius(4e11);
+ sim_camera.set_azimuth(0.0f);
+ sim_camera.set_elevation(1.25f);
+ }
+
+ auto Scene::set_free_fly(bool enabled) -> void
+ {
+ const bool is_fps = sim_camera.get_camera_mode() == CameraMode::FPS;
+ if (enabled == is_fps) return;
+ if (enabled)
+ {
+ // Seed the fly pose from the current orbital framing so the view is continuous.
+ glm::vec3 pos = sim_camera.get_orbital_position();
+ glm::vec3 fwd = glm::normalize(sim_camera.get_orbital_target() - pos);
+ float pitch = glm::degrees(asin(glm::clamp(fwd.y, -1.0f, 1.0f)));
+ float yaw = glm::degrees(atan2(fwd.z, fwd.x));
+ sim_camera.set_camera_mode(CameraMode::FPS);
+ sim_camera.set_movement_speed(2.0e10f);
+ sim_camera.set_mouse_sensitivity(0.15f);
+ sim_camera.set_position(pos);
+ sim_camera.set_rotation(glm::vec3(pitch, yaw, 0.0f));
+ }
+ else
+ {
+ sim_camera.set_camera_mode(CameraMode::Orbital); // orbital state was left intact
+ }
+ }
+}
diff --git a/src/scene/scene.h b/src/scene/scene.h
new file mode 100644
index 0000000..27d1327
--- /dev/null
+++ b/src/scene/scene.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "scene_types.h"
+#include "core/camera.h"
+
+#include <string>
+#include <vector>
+
+namespace Donut
+{
+ // The document: everything the app edits and renders, independent of any
+ // backend or UI. Workspaces (tabs) read and mutate this; the RenderPath reads
+ // it to draw. It owns the two viewpoints (cameras) as scene state, plus small
+ // camera-framing helpers, since a viewpoint is part of the document.
+ class Scene
+ {
+ public:
+ Scene();
+
+ // world-builder content
+ std::vector<SceneObject> objects{ SceneObject{} };
+ int selected_object = 0;
+
+ // black hole / accretion disk
+ BlackHoleParams black_hole;
+
+ // environment
+ std::string hdri_path = "assets/hdri/hdr_blue_nebulae_1.hdr";
+
+ // viewpoints
+ Camera sim_camera{ 60.0f, 16.0f / 9.0f, 0.1f, 100.0f }; // black-hole view
+ Camera scene_camera{ 45.0f, 16.0f / 9.0f, 0.1f, 1000.0f }; // world-builder view
+
+ // Camera framing helpers (the sim view supports orbital + free-fly).
+ auto reset_sim_camera() -> void;
+ auto set_free_fly(bool enabled) -> void;
+ auto is_free_fly() const -> bool { return sim_camera.get_camera_mode() == CameraMode::FPS; }
+ };
+}
diff --git a/src/scene/scene_types.h b/src/scene/scene_types.h
new file mode 100644
index 0000000..d34983f
--- /dev/null
+++ b/src/scene/scene_types.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <glm/glm.hpp>
+
+namespace Donut
+{
+ // Backend-agnostic scene/black-hole data shared by the Application and the
+ // portable renderers (SceneRenderer, BlackHoleRenderer). The rendering itself
+ // is written once on the RHI (rendering/rhi.h); these are just the inputs.
+
+ // A placeable/editable sphere in the world-builder scene view. The app owns
+ // the list; SceneRenderer draws it the same way on every backend.
+ struct SceneObject
+ {
+ glm::vec3 position = { 0.0f, 2.0f, 0.0f };
+ float radius = 2.0f;
+ glm::vec3 color = { 0.85f, 0.35f, 0.2f };
+ };
+
+ // Live-tunable black-hole / accretion-disk parameters. Radii are in
+ // Schwarzschild radii; the inner edge is clamped to the ISCO (3 r_s).
+ struct BlackHoleParams
+ {
+ float disk_inner_rs = 3.0f; // inner edge (x r_s)
+ float disk_outer_rs = 12.0f; // outer edge (x r_s)
+ float temperature = 4800.0f; // Kelvin at the flux peak (disk colour)
+ float brightness = 0.9f; // disk exposure
+ float turbulence = 0.4f; // 0 = smooth physical disk
+ int quality_steps = 15000; // geodesic integration steps
+ float fov_degrees = 60.0f; // camera field of view
+ };
+}