hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/states
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-15 03:18:29 +0200
committerhachem <im@hachem.wtf>2025-08-15 03:18:29 +0200
commita6655eebe2a69ee427264bd43df5747851ed96df (patch)
treefa8c6ef862898a3d8e19250698dca0d9aaf4f9c2 /src/states
parent3d8d3259e1cf5a7d88e5d1e530cc8c9bf9140734 (diff)
feat: complete first geodesic 3D raytracing
Diffstat (limited to 'src/states')
-rw-r--r--src/states/config_state.cpp2
-rw-r--r--src/states/simulation_state.cpp58
-rw-r--r--src/states/simulation_state.h2
3 files changed, 38 insertions, 24 deletions
diff --git a/src/states/config_state.cpp b/src/states/config_state.cpp
index 403f667..d29408b 100644
--- a/src/states/config_state.cpp
+++ b/src/states/config_state.cpp
@@ -22,7 +22,7 @@ namespace Donut
void ConfigState::on_render()
{
- Renderer::set_clear_color({ 0.1f, 0.1f, 0.2f, 1.0f });
+ Renderer::set_clear_color({ 0.1f, 0.1f, 0.1f, 1.0f });
Renderer::clear();
}
diff --git a/src/states/simulation_state.cpp b/src/states/simulation_state.cpp
index fc235ff..e59f1fa 100644
--- a/src/states/simulation_state.cpp
+++ b/src/states/simulation_state.cpp
@@ -22,11 +22,11 @@ namespace Donut
void SimulationState::on_update(float delta_time)
{
-
+ m_engine.update_performance(delta_time);
m_engine.update_window_dimensions();
m_engine.update_physics(delta_time);
-
- if (m_engine.get_camera().is_dragging())
+
+ if (m_engine.get_camera().is_dragging())
{
GLFWwindow* window = static_cast<GLFWwindow*>(Application::get().get_window().get_native_window());
double xpos, ypos;
@@ -37,34 +37,28 @@ namespace Donut
void SimulationState::on_render()
{
- if (!m_initialized) return;
-
RenderCommand::set_clear_color(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
RenderCommand::clear();
-
- m_engine.generate_grid(m_engine.get_objects());
-
- glm::mat4 view = glm::lookAt(m_engine.get_camera().get_orbital_position(), m_engine.get_camera().get_target(), glm::vec3(0,1,0));
- glm::mat4 proj = glm::perspective(glm::radians(60.0f), float(m_engine.get_width())/m_engine.get_height(), 1e9f, 1e14f);
- glm::mat4 view_proj = proj * view;
-
- m_engine.draw_grid(view_proj);
-
RenderCommand::set_viewport(0, 0, m_engine.get_width(), m_engine.get_height());
+
m_engine.dispatch_compute(m_engine.get_camera());
m_engine.draw_full_screen_quad();
}
void SimulationState::on_event(Event& event)
{
- if (!m_initialized) return;
-
if (event.get_event_type() == EventType::MouseButtonPressed)
{
MouseButtonPressedEvent& e = (MouseButtonPressedEvent&)event;
int button = e.get_mouse_button();
- m_engine.get_camera().process_orbital_mouse_button(button, GLFW_PRESS, 0);
+ GLFWwindow* window = static_cast<GLFWwindow*>(Application::get().get_window().get_native_window());
+ Camera& camera = m_engine.get_camera();
+ double last_x = camera.get_last_x();
+ double last_y = camera.get_last_y();
+ glfwGetCursorPos(window, &last_x, &last_y);
+
+ camera.process_orbital_mouse_button(button, GLFW_PRESS, 0);
}
else if (event.get_event_type() == EventType::MouseButtonReleased)
{
@@ -84,7 +78,7 @@ namespace Donut
KeyPressedEvent& e = (KeyPressedEvent&)event;
if (e.get_key_code() == GLFW_KEY_G)
{
- m_engine.set_gravity(!m_engine.get_gravity());
+ m_engine.get_gravity() = !m_engine.get_gravity();
DONUT_INFO("Gravity turned {}", m_engine.get_gravity() ? "ON" : "OFF");
}
}
@@ -109,6 +103,27 @@ namespace Donut
ImGui::Separator();
+ ImGui::Text("Performance:");
+ ImGui::Text("Engine FPS: %.1f", m_engine.get_current_fps());
+ ImGui::Text("Target FPS: %d", m_engine.get_target_fps());
+
+ int target_fps = m_engine.get_target_fps();
+ if (ImGui::SliderInt("Target FPS", &target_fps, 30, 120))
+ {
+ m_engine.set_target_fps(target_fps);
+ }
+
+ int compute_height = m_engine.get_compute_height();
+ if (ImGui::SliderInt("Compute Height", &compute_height, 64, 2048))
+ {
+ m_engine.set_compute_height(compute_height);
+ m_engine.update_compute_dimensions();
+ }
+
+ ImGui::Text("Compute Width: %d (auto-calculated)", m_engine.get_compute_width());
+
+ ImGui::Separator();
+
ImGui::Text("Controls:");
ImGui::Text("Left Mouse: Orbit camera");
ImGui::Text("Scroll: Zoom in/out");
@@ -118,16 +133,15 @@ namespace Donut
ImGui::Separator();
ImGui::Text("Physics:");
- bool gravity = m_engine.get_gravity();
- if (ImGui::Checkbox("Gravity Enabled", &gravity))
- m_engine.set_gravity(gravity);
+ bool& gravity = m_engine.get_gravity();
+ ImGui::Checkbox("Gravity Enabled", &gravity);
ImGui::Text("Camera:");
ImGui::Text("Position: (%.2e, %.2e, %.2e)",
m_engine.get_camera().get_orbital_position().x,
m_engine.get_camera().get_orbital_position().y,
m_engine.get_camera().get_orbital_position().z);
- ImGui::Text("Radius: %.2e", m_engine.get_camera().get_radius());
+ ImGui::Text("Radius: %.2e", m_engine.get_camera().get_orbital_radius());
ImGui::Text("Azimuth: %.2f", m_engine.get_camera().get_azimuth());
ImGui::Text("Elevation: %.2f", m_engine.get_camera().get_elevation());
diff --git a/src/states/simulation_state.h b/src/states/simulation_state.h
index 68788e8..cc55901 100644
--- a/src/states/simulation_state.h
+++ b/src/states/simulation_state.h
@@ -23,6 +23,6 @@ namespace Donut
private:
Engine m_engine;
- bool m_initialized = false;
+ bool m_initialized = false;
};
};