diff options
Diffstat (limited to 'src/States')
| -rw-r--r-- | src/States/ConfigState.cpp | 307 | ||||
| -rw-r--r-- | src/States/ConfigState.h | 47 | ||||
| -rw-r--r-- | src/States/SimulationState.cpp | 386 | ||||
| -rw-r--r-- | src/States/SimulationState.h | 27 | ||||
| -rw-r--r-- | src/States/WorldBuilderState.cpp | 1113 | ||||
| -rw-r--r-- | src/States/WorldBuilderState.h | 96 |
6 files changed, 0 insertions, 1976 deletions
diff --git a/src/States/ConfigState.cpp b/src/States/ConfigState.cpp deleted file mode 100644 index c57bced..0000000 --- a/src/States/ConfigState.cpp +++ /dev/null @@ -1,307 +0,0 @@ -#include "ConfigState.h" -#include "Rendering/Renderer.h" -#include "Core/Application.h" -#include "Core/ThemeManager.h" -#include "Core/SettingsManager.h" - -#include <imgui.h> -#include <imgui_internal.h> -#include <glad/glad.h> - -namespace Donut -{ - void ConfigState::OnEnter() - { - DONUT_INFO("Entering Config State"); - - const auto& settings = SettingsManager::GetSettingsConst(); - - m_SelectedAPI = (settings.graphics.renderAPI == "Vulkan") ? RendererAPI::API::Vulkan : RendererAPI::API::OpenGL; - m_SelectedTheme = (settings.graphics.selectedTheme == "Light") ? 1 : - (settings.graphics.selectedTheme == "Blue") ? 2 : 0; - m_TargetFPS = settings.simulation.targetFPS; - m_ComputeHeight = settings.simulation.computeHeight; - m_MaxStepsMoving = settings.simulation.maxStepsMoving; - m_MaxStepsStatic = settings.simulation.maxStepsStatic; - m_EarlyExitDistance = settings.simulation.earlyExitDistance; - m_GravityEnabled = settings.simulation.gravityEnabled; - m_VSyncEnabled = settings.graphics.vSyncEnabled; - m_ShowFPS = settings.graphics.showFPS; - m_ShowPerformanceMetrics = settings.graphics.showPerformanceMetrics; - m_ShowDebugInfo = settings.graphics.showDebugInfo; - m_EnableAntiAliasing = settings.graphics.enableAntiAliasing; - } - - void ConfigState::OnExit() - { - DONUT_INFO("Exiting Config State"); - } - - void ConfigState::OnUpdate(float deltaTime) - { - if (m_ShowRestartMessage) - { - m_RestartMessageTimer += deltaTime; - if (m_RestartMessageTimer > 3.0f) - { - m_ShowRestartMessage = false; - m_RestartMessageTimer = 0.0f; - } - } - } - - void ConfigState::OnRender() - { - Renderer::SetClearColor({ 0.1f, 0.1f, 0.1f, 1.0f }); - Renderer::Clear(); - } - - void ConfigState::OnEvent(Event& event) - { - } - - void ConfigState::OnImUIRender() - { - ImGui::SetNextWindowSize(ImVec2(900, 700), ImGuiCond_FirstUseEver); - ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f), - ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f)); - - ImGui::Begin("Donut Configuration", nullptr, ImGuiWindowFlags_NoCollapse); - - ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]); - ImGui::TextColored(ImVec4(0.8f, 0.8f, 1.0f, 1.0f), "Donut Configuration"); - ImGui::PopFont(); - ImGui::Separator(); - - ImGui::Columns(2, "ConfigColumns", true); - - float availableHeight = ImGui::GetWindowHeight() - 140; - - ImGui::BeginChild("GraphicsSettings", ImVec2(0, availableHeight), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Graphics Settings"); - ImGui::Separator(); - - ImGui::Text("Render API:"); - ImGui::SameLine(); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "(requires restart)"); - - const char* apiNames[] = { "OpenGL", "Vulkan" }; - static int currentAPI = (int)m_SelectedAPI - 1; - - if (ImGui::BeginCombo("##RenderAPI", apiNames[currentAPI])) - { - for (int i = 0; i < IM_ARRAYSIZE(apiNames); i++) - { - const bool isSelected = (currentAPI == i); - if (ImGui::Selectable(apiNames[i], isSelected)) - { - currentAPI = i; - m_SelectedAPI = (RendererAPI::API)(i + 1); - m_ShowRestartMessage = true; - m_RestartMessageTimer = 0.0f; - } - - if (isSelected) - ImGui::SetItemDefaultFocus(); - } - - ImGui::EndCombo(); - } - - ImGui::Text("Current API: "); - ImGui::SameLine(); - const char* currentAPIName = (Renderer::GetAPI() == RendererAPI::API::OpenGL) ? "OpenGL" : "Vulkan"; - ImGui::TextColored(ImVec4(0.3f, 0.8f, 0.3f, 1.0f), currentAPIName); - - ImGui::Spacing(); - - ImGui::Checkbox("Enable VSync", &m_VSyncEnabled); - ImGui::SameLine(); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "(recommended)"); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Display"); - ImGui::Separator(); - - ImGui::Text("Window Size: 1280x720"); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Fullscreen: Not implemented yet"); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "System Info"); - ImGui::Separator(); - - ImGui::Text("OpenGL Version: %s", glGetString(GL_VERSION)); - ImGui::Text("GPU: %s", glGetString(GL_RENDERER)); - ImGui::Text("Vendor: %s", glGetString(GL_VENDOR)); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Performance"); - ImGui::Separator(); - - ImGui::SliderInt("Target FPS", &m_TargetFPS, 30, 120, "%d FPS"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Target frame rate for the simulation"); - - ImGui::Checkbox("Show FPS Counter", &m_ShowFPS); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Display current FPS in the simulation"); - - ImGui::Checkbox("Show Performance Metrics", &m_ShowPerformanceMetrics); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Show detailed performance information"); - - ImGui::Checkbox("Show Debug Info", &m_ShowDebugInfo); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Display debug information and statistics"); - - ImGui::Checkbox("Enable Anti-Aliasing", &m_EnableAntiAliasing); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Enable anti-aliasing for smoother rendering"); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Theme"); - ImGui::Separator(); - - const char* themeNames[] = { "Dark", "Light", "Blue" }; - if (ImGui::Combo("UI Theme", &m_SelectedTheme, themeNames, IM_ARRAYSIZE(themeNames))) - ThemeManager::SetTheme(static_cast<Theme>(m_SelectedTheme)); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Choose the application theme"); - - ImGui::EndChild(); - - ImGui::NextColumn(); - - ImGui::BeginChild("SimulationSettings", ImVec2(0, availableHeight), true, ImGuiWindowFlags_AlwaysVerticalScrollbar); - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Simulation Settings"); - ImGui::Separator(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Quality"); - ImGui::Separator(); - - ImGui::SliderInt("Compute Height", &m_ComputeHeight, 64, 2048, "%d px"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Resolution of the compute shader. Higher values give better quality but lower performance."); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Higher = better quality, lower performance"); - - ImGui::SliderInt("Max Steps (Moving)", &m_MaxStepsMoving, 1000, 60000, "%d"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Maximum ray marching steps when camera is moving"); - - ImGui::SliderInt("Max Steps (Static)", &m_MaxStepsStatic, 1000, 30000, "%d"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Maximum ray marching steps when camera is stationary"); - - ImGui::SliderFloat("Early Exit Distance", &m_EarlyExitDistance, 1e11f, 1e13f, "%.2e"); - if (ImGui::IsItemHovered()) - ImGui::SetTooltip("Distance at which ray marching stops to improve performance"); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Distance at which ray marching stops"); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Physics"); - ImGui::Separator(); - - ImGui::Checkbox("Enable Gravity", &m_GravityEnabled); - - ImGui::EndChild(); - - ImGui::Columns(1); - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::Spacing(); - - float buttonWidth = (ImGui::GetWindowWidth() - 120) / 5.0f; - - if (ImGui::Button("World Builder", ImVec2(buttonWidth, 35))) - { - ApplySettings(); - Application::Get().GetStateManager().SwitchToState("WorldBuilder"); - } - - ImGui::SameLine(); - if (ImGui::Button("Reset to Defaults", ImVec2(buttonWidth, 35))) - ResetToDefaults(); - - ImGui::SameLine(); - if (ImGui::Button("Apply Settings", ImVec2(buttonWidth, 35))) - ApplySettings(); - - ImGui::SameLine(); - if (ImGui::Button("Save Settings", ImVec2(buttonWidth, 35))) - { - ApplySettings(); - DONUT_INFO("Settings saved manually"); - } - - ImGui::SameLine(); - if (ImGui::Button("Exit", ImVec2(buttonWidth, 35))) - Application::Get().Close(); - - if (m_ShowRestartMessage) - { - ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.8f, 0.2f, 1.0f)); - ImGui::TextWrapped("Warning: Render API changed! Please restart the application for changes to take effect."); - ImGui::PopStyleColor(); - } - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Donut Engine v1.0.0 | Black Hole Simulation"); - - ImGui::End(); - } - - void ConfigState::ApplySettings() - { - SimulationSettings simSettings; - simSettings.targetFPS = m_TargetFPS; - simSettings.computeHeight = m_ComputeHeight; - simSettings.maxStepsMoving = m_MaxStepsMoving; - simSettings.maxStepsStatic = m_MaxStepsStatic; - simSettings.earlyExitDistance = m_EarlyExitDistance; - simSettings.gravityEnabled = m_GravityEnabled; - - GraphicsSettings gfxSettings; - gfxSettings.renderAPI = (m_SelectedAPI == RendererAPI::API::Vulkan) ? "Vulkan" : "OpenGL"; - gfxSettings.vSyncEnabled = m_VSyncEnabled; - gfxSettings.showFPS = m_ShowFPS; - gfxSettings.showPerformanceMetrics = m_ShowPerformanceMetrics; - gfxSettings.showDebugInfo = m_ShowDebugInfo; - gfxSettings.enableAntiAliasing = m_EnableAntiAliasing; - gfxSettings.selectedTheme = (m_SelectedTheme == 1) ? "Light" : - (m_SelectedTheme == 2) ? "Blue" : "Dark"; - - SettingsManager::SetSimulationSettings(simSettings); - SettingsManager::SetGraphicsSettings(gfxSettings); - - RendererAPI::SetAPI(m_SelectedAPI); - DONUT_INFO("Settings applied and saved"); - } - - void ConfigState::ResetToDefaults() - { - m_SelectedAPI = RendererAPI::API::OpenGL; - m_TargetFPS = 60; - m_ComputeHeight = 512; - m_MaxStepsMoving = 30000; - m_MaxStepsStatic = 15000; - m_EarlyExitDistance = 5e12f; - m_GravityEnabled = true; - m_VSyncEnabled = true; - m_ShowFPS = true; - m_ShowPerformanceMetrics = true; - m_ShowDebugInfo = false; - m_EnableAntiAliasing = true; - m_SelectedTheme = 0; - - ApplySettings(); - DONUT_INFO("Settings reset to defaults and saved"); - } -}; diff --git a/src/States/ConfigState.h b/src/States/ConfigState.h deleted file mode 100644 index ad7e238..0000000 --- a/src/States/ConfigState.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "Core/State.h" -#include "Core/Event.h" -#include "Core/Log.h" -#include "Rendering/Renderer.h" - -namespace Donut -{ - class ConfigState - : public State - { - public: - ~ConfigState() = default; - - void OnEnter() override; - void OnExit() override; - void OnUpdate(float deltaTime) override; - void OnRender() override; - void OnImUIRender() override; - void OnEvent(Event& event) override; - - private: - void ApplySettings(); - void ResetToDefaults(); - - private: - RendererAPI::API m_SelectedAPI = RendererAPI::API::OpenGL; - bool m_ShowRestartMessage = false; - float m_RestartMessageTimer = 0.0f; - - int m_TargetFPS = 60; - int m_ComputeHeight = 512; - int m_MaxStepsMoving = 30000; - int m_MaxStepsStatic = 15000; - float m_EarlyExitDistance = 5e12f; - bool m_GravityEnabled = true; - - bool m_VSyncEnabled = true; - bool m_ShowFPS = true; - bool m_ShowPerformanceMetrics = true; - bool m_ShowDebugInfo = false; - bool m_EnableAntiAliasing = true; - - int m_SelectedTheme = 0; // 0=Dark, 1=Light, 2=Blue - }; -};
\ No newline at end of file diff --git a/src/States/SimulationState.cpp b/src/States/SimulationState.cpp deleted file mode 100644 index 12c9397..0000000 --- a/src/States/SimulationState.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "SimulationState.h" -#include "Rendering/Renderer.h" -#include "Core/Application.h" -#include "Core/HDRIManager.h" -#include "Core/Window.h" -#include "Core/Event.h" -#include "Core/SettingsManager.h" - -#include <imgui.h> -#include <GLFW/glfw3.h> -#include <chrono> -#include <iomanip> -#include <sstream> -#include <vector> - -namespace Donut -{ - void SimulationState::OnEnter() - { - DONUT_INFO("Entering Simulation State"); - - const auto& settings = SettingsManager::GetSettingsConst(); - auto& engine = Application::Get().GetEngine(); - - engine.SetTargetFPS(settings.simulation.targetFPS); - engine.SetComputeHeight(settings.simulation.computeHeight); - engine.SetMaxStepsMoving(settings.simulation.maxStepsMoving); - engine.SetMaxStepsStatic(settings.simulation.maxStepsStatic); - engine.SetEarlyExitDistance(settings.simulation.earlyExitDistance); - engine.GetGravity() = settings.simulation.gravityEnabled; - - engine.SetDiskThickness(settings.simulation.diskThickness); - engine.SetDiskDensity(settings.simulation.diskDensity); - engine.SetRotationSpeed(settings.simulation.rotationSpeed); - engine.SetBlurStrength(settings.simulation.blurStrength); - engine.SetGlowIntensity(settings.simulation.glowIntensity); - - engine.UpdateComputeDimensions(); - m_Initialized = true; - } - - void SimulationState::OnExit() - { - DONUT_INFO("Exiting Simulation State"); - } - - void SimulationState::OnUpdate(float deltaTime) - { - auto& engine = Application::Get().GetEngine(); - engine.UpdatePerformance(deltaTime); - engine.UpdateWindowDimensions(); - engine.UpdatePhysics(deltaTime); - - if (engine.GetCamera().IsDragging()) - { - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - double xpos, ypos; - glfwGetCursorPos(window, &xpos, &ypos); - engine.GetCamera().ProcessOrbitalMouseMove(xpos, ypos); - } - } - - void SimulationState::OnRender() - { - auto& engine = Application::Get().GetEngine(); - RenderCommand::SetClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - RenderCommand::Clear(); - RenderCommand::SetViewport(0, 0, static_cast<uint32_t>(engine.GetWidth()), static_cast<uint32_t>(engine.GetHeight())); - - engine.DispatchCompute(engine.GetCamera()); - engine.DrawBlurPass(); - } - - void SimulationState::OnEvent(Event& event) - { - auto& engine = Application::Get().GetEngine(); - - if (event.GetEventType() == EventType::MouseButtonPressed) - { - MouseButtonPressedEvent& e = (MouseButtonPressedEvent&)event; - int button = e.GetMouseButton(); - - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - Camera& camera = engine.GetCamera(); - double lastX = camera.GetLastX(); - double lastY = camera.GetLastY(); - glfwGetCursorPos(window, &lastX, &lastY); - - camera.ProcessOrbitalMouseButton(button, GLFW_PRESS, 0); - } - else if (event.GetEventType() == EventType::MouseButtonReleased) - { - MouseButtonReleasedEvent& e = (MouseButtonReleasedEvent&)event; - int button = e.GetMouseButton(); - engine.GetCamera().ProcessOrbitalMouseButton(button, GLFW_RELEASE, 0); - } - - if (event.GetEventType() == EventType::MouseScrolled) - { - MouseScrolledEvent& e = (MouseScrolledEvent&)event; - engine.GetCamera().ProcessOrbitalScroll(e.GetXOffset(), e.GetYOffset()); - } - - if (event.GetEventType() == EventType::KeyPressed) - { - KeyPressedEvent& e = (KeyPressedEvent&)event; - if (e.GetKeyCode() == GLFW_KEY_G) - { - engine.GetGravity() = !engine.GetGravity(); - DONUT_INFO("Gravity turned {}", engine.GetGravity() ? "ON" : "OFF"); - } - } - } - - void SimulationState::OnImUIRender() - { - auto& engine = Application::Get().GetEngine(); - - ImGui::SetNextWindowSize(ImVec2(400, 600), ImGuiCond_FirstUseEver); - ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - 420, 20), ImGuiCond_FirstUseEver); - - ImGui::Begin("Simulation Controls", nullptr, ImGuiWindowFlags_NoCollapse); - - ImGui::TextColored(ImVec4(0.8f, 0.8f, 1.0f, 1.0f), "Black Hole Simulation"); - ImGui::SameLine(); - if (ImGui::Button("Back to Config")) - Application::Get().GetStateManager().SwitchToState("Config"); - ImGui::SameLine(); - if (ImGui::Button("Save Settings")) - { - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.targetFPS = engine.GetTargetFPS(); - settings.computeHeight = engine.GetComputeHeight(); - settings.maxStepsMoving = engine.GetMaxStepsMoving(); - settings.maxStepsStatic = engine.GetMaxStepsStatic(); - settings.earlyExitDistance = engine.GetEarlyExitDistance(); - settings.gravityEnabled = engine.GetGravity(); - SettingsManager::SetSimulationSettings(settings); - DONUT_INFO("Simulation settings saved manually"); - } - - ImGui::Separator(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Performance"); - ImGui::Separator(); - - ImGui::Text("FPS: %.1f", ImGui::GetIO().Framerate); - ImGui::Text("Frame Time: %.3f ms", 1000.0f / ImGui::GetIO().Framerate); - ImGui::Text("Engine FPS: %.1f", engine.GetCurrentFPS()); - - int targetFPS = engine.GetTargetFPS(); - if (ImGui::SliderInt("Target FPS", &targetFPS, 30, 120)) - { - engine.SetTargetFPS(targetFPS); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.targetFPS = targetFPS; - SettingsManager::SetSimulationSettings(settings); - } - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Simulation Info"); - ImGui::Separator(); - - ImGui::Text("Resolution: %dx%d", engine.GetWidth(), engine.GetHeight()); - ImGui::Text("Compute Resolution: %dx%d", engine.GetComputeWidth(), engine.GetComputeHeight()); - ImGui::Text("Objects: %zu", engine.GetObjects().size()); - - if (ImGui::Button("Print Object Info")) - engine.PrintObjectInfo(); - - int computeHeight = engine.GetComputeHeight(); - if (ImGui::SliderInt("Compute Height", &computeHeight, 64, 2048)) - { - engine.SetComputeHeight(computeHeight); - engine.UpdateComputeDimensions(); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.computeHeight = computeHeight; - SettingsManager::SetSimulationSettings(settings); - } - - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Compute Width: %d (auto-calculated)", engine.GetComputeWidth()); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Quality Settings"); - ImGui::Separator(); - - int maxStepsMoving = engine.GetMaxStepsMoving(); - if (ImGui::SliderInt("Max Steps (Moving)", &maxStepsMoving, 1000, 60000)) - { - engine.SetMaxStepsMoving(maxStepsMoving); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.maxStepsMoving = maxStepsMoving; - SettingsManager::SetSimulationSettings(settings); - } - int maxStepsStatic = engine.GetMaxStepsStatic(); - if (ImGui::SliderInt("Max Steps (Static)", &maxStepsStatic, 1000, 30000)) - { - engine.SetMaxStepsStatic(maxStepsStatic); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.maxStepsStatic = maxStepsStatic; - SettingsManager::SetSimulationSettings(settings); - } - float earlyExitDistance = engine.GetEarlyExitDistance(); - if (ImGui::SliderFloat("Early Exit Distance", &earlyExitDistance, 1e11f, 1e13f, "%.2e")) - { - engine.SetEarlyExitDistance(earlyExitDistance); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.earlyExitDistance = earlyExitDistance; - SettingsManager::SetSimulationSettings(settings); - } - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Physics"); - ImGui::Separator(); - - bool& gravity = engine.GetGravity(); - if (ImGui::Checkbox("Gravity Enabled", &gravity)) - { - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.gravityEnabled = gravity; - SettingsManager::SetSimulationSettings(settings); - } - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Accretion Disk"); - ImGui::Separator(); - - float diskThickness = engine.GetDiskThickness(); - if (ImGui::SliderFloat("Cloud Thickness", &diskThickness, 0.1f, 2.0f, "%.2f")) - { - engine.SetDiskThickness(diskThickness); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.diskThickness = diskThickness; - SettingsManager::SetSimulationSettings(settings); - } - ImGui::TextDisabled("Thickness relative to Schwarzschild radius"); - - float diskDensity = engine.GetDiskDensity(); - if (ImGui::SliderFloat("Cloud Density", &diskDensity, 0.1f, 3.0f, "%.2f")) - { - engine.SetDiskDensity(diskDensity); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.diskDensity = diskDensity; - SettingsManager::SetSimulationSettings(settings); - } - ImGui::TextDisabled("Overall density multiplier"); - - float rotationSpeed = engine.GetRotationSpeed(); - if (ImGui::SliderFloat("Rotation Speed", &rotationSpeed, 0.0f, 3.0f, "%.2f")) - { - engine.SetRotationSpeed(rotationSpeed); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.rotationSpeed = rotationSpeed; - SettingsManager::SetSimulationSettings(settings); - } - ImGui::TextDisabled("Rotation speed multiplier (0 = no rotation)"); - - float blurStrength = engine.GetBlurStrength(); - if (ImGui::SliderFloat("Blur Strength", &blurStrength, 0.5f, 5.0f, "%.2f")) - { - engine.SetBlurStrength(blurStrength); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.blurStrength = blurStrength; - SettingsManager::SetSimulationSettings(settings); - } - ImGui::TextDisabled("Blur radius for glow effect"); - - float glowIntensity = engine.GetGlowIntensity(); - if (ImGui::SliderFloat("Glow Intensity", &glowIntensity, 0.1f, 3.0f, "%.2f")) - { - engine.SetGlowIntensity(glowIntensity); - SimulationSettings settings = SettingsManager::GetSettingsConst().simulation; - settings.glowIntensity = glowIntensity; - SettingsManager::SetSimulationSettings(settings); - } - ImGui::TextDisabled("Intensity of the glow effect"); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "HDRI Environment"); - ImGui::Separator(); - - static int selectedHDRI = 0; - ImGui::PushID("SimulationHDRI"); - auto& hdriManager = HDRIManager::Get(); - const auto& availableHDRI = hdriManager.GetAvailableHDRI(); - - static std::vector<std::string> hdriOptionNames; - static std::vector<const char*> hdriOptions; - - if (hdriOptionNames.size() != availableHDRI.size()) - { - hdriOptionNames.clear(); - hdriOptions.clear(); - - for (const auto& path : availableHDRI) - { - hdriOptionNames.push_back(hdriManager.GetHDRIName(path)); - hdriOptions.push_back(hdriOptionNames.back().c_str()); - } - } - - if (ImGui::Combo("HDRI Environment", &selectedHDRI, hdriOptions.data(), static_cast<int>(hdriOptions.size()))) - { - auto& hdriManager = HDRIManager::Get(); - hdriManager.SetCurrentHDRI(availableHDRI[selectedHDRI]); - engine.SetHDRIEnvironment(hdriManager.GetCurrentHDRI()); - } - ImGui::TextDisabled("HDRI provides background and lighting for the simulation"); - ImGui::PopID(); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Camera"); - ImGui::Separator(); - - ImGui::Text("Position: (%.2e, %.2e, %.2e)", - engine.GetCamera().GetOrbitalPosition().x, - engine.GetCamera().GetOrbitalPosition().y, - engine.GetCamera().GetOrbitalPosition().z); - ImGui::Text("Radius: %.2e", engine.GetCamera().GetOrbitalRadius()); - ImGui::Text("Azimuth: %.2f", engine.GetCamera().GetAzimuth()); - ImGui::Text("Elevation: %.2f", engine.GetCamera().GetElevation()); - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Export"); - ImGui::Separator(); - - if (ImGui::Button("Export Frame (1080p)", ImVec2(-1, 30))) - { - auto& engine = Application::Get().GetEngine(); - auto now = std::chrono::system_clock::now(); - auto time_t = std::chrono::system_clock::to_time_t(now); - std::stringstream ss; - ss << "frame_1080p_" << std::put_time(std::localtime(&time_t), "%Y-%m-%d_%H-%M-%S") << ".png"; - engine.ExportHighResFrame(ss.str(), 1920, 1080); - } - - if (ImGui::Button("Export High-Res Frame (4K)", ImVec2(-1, 30))) - { - auto& engine = Application::Get().GetEngine(); - auto now = std::chrono::system_clock::now(); - auto time_t = std::chrono::system_clock::to_time_t(now); - std::stringstream ss; - ss << "high_res_frame_4k_" << std::put_time(std::localtime(&time_t), "%Y-%m-%d_%H-%M-%S") << ".png"; - engine.ExportHighResFrame(ss.str(), 4096, 3072); - } - - if (ImGui::Button("Export High-Res Frame (8K)", ImVec2(-1, 30))) - { - auto& engine = Application::Get().GetEngine(); - auto now = std::chrono::system_clock::now(); - auto time_t = std::chrono::system_clock::to_time_t(now); - std::stringstream ss; - ss << "high_res_frame_8k_" << std::put_time(std::localtime(&time_t), "%Y-%m-%d_%H-%M-%S") << ".png"; - engine.ExportHighResFrame(ss.str(), 8192, 6144); - } - - if (ImGui::Button("Export Ultra High-Res Frame (16K)", ImVec2(-1, 30))) - { - auto& engine = Application::Get().GetEngine(); - auto now = std::chrono::system_clock::now(); - auto time_t = std::chrono::system_clock::to_time_t(now); - std::stringstream ss; - ss << "high_res_frame_16k_" << std::put_time(std::localtime(&time_t), "%Y%m%d_%H%M%S") << ".png"; - engine.ExportHighResFrame(ss.str(), 16384, 12288); - } - - ImGui::Spacing(); - - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Controls"); - ImGui::Separator(); - - ImGui::Text("Left Mouse: Orbit camera"); - ImGui::Text("Scroll: Zoom in/out"); - ImGui::Text("G: Toggle gravity"); - ImGui::Text("Right Mouse: Enable gravity (hold)"); - - ImGui::End(); - } -}; diff --git a/src/States/SimulationState.h b/src/States/SimulationState.h deleted file mode 100644 index 2589804..0000000 --- a/src/States/SimulationState.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "Core/State.h" -#include "Core/Event.h" -#include "Core/Log.h" -#include "Engine/Engine.h" -#include <vector> - -namespace Donut -{ - class SimulationState - : public State - { - public: - ~SimulationState() = default; - - void OnEnter() override; - void OnExit() override; - void OnUpdate(float deltaTime) override; - void OnRender() override; - void OnImUIRender() override; - void OnEvent(Event& event) override; - - private: - bool m_Initialized = false; - }; -}; diff --git a/src/States/WorldBuilderState.cpp b/src/States/WorldBuilderState.cpp deleted file mode 100644 index 3c49f62..0000000 --- a/src/States/WorldBuilderState.cpp +++ /dev/null @@ -1,1113 +0,0 @@ -#include "WorldBuilderState.h" - -#include "Core/Application.h" -#include "Core/Window.h" -#include "Core/HDRIManager.h" - -#include "Rendering/Renderer.h" -#include "Rendering/Shader.h" -#include "Rendering/VertexArray.h" -#include "Rendering/VertexBuffer.h" -#include "Rendering/IndexBuffer.h" -#include "Rendering/Texture.h" - -#include <imgui.h> -#include <ImGuizmo.h> -#include <GLFW/glfw3.h> - -#include <glm/gtc/matrix_transform.hpp> -#include <glm/gtc/type_ptr.hpp> - -#include <nlohmann/json.hpp> - -#include <numbers> -#include <fstream> -#include <sstream> -#include <limits> -#include <vector> - -namespace Donut -{ - void WorldBuilderState::OnEnter() - { - DONUT_INFO("Entering World Builder State"); - - ImGuizmo::Enable(true); - - m_Camera.SetCameraMode(CameraMode::Orbital); - m_Camera.SetOrbitalTarget(glm::vec3(0.0f, 0.0f, 0.0f)); - m_Camera.SetOrbitalRadius(15.0f); - m_Camera.SetOrbitalLimits(2.0f, 200.0f); - m_Camera.SetOrbitalSpeed(0.01f); - m_Camera.SetZoomSpeed(2.0f); - m_Camera.SetAzimuth(0.0f); - m_Camera.SetElevation(static_cast<float>(std::numbers::pi) / 3.0f); - m_Camera.UpdateOrbital(); - - m_SphereShader = Ref<Shader>(Shader::Create("Assets/Shaders/Sphere.glsl")); - m_SkyboxShader = Ref<Shader>(Shader::Create("Assets/Shaders/Skybox.glsl")); - m_GridShader = Ref<Shader>(Shader::Create("Assets/Shaders/Grid.glsl")); - - if (!m_SphereShader) - DONUT_ERROR("Failed to create sphere shader"); - if (!m_SkyboxShader) - DONUT_ERROR("Failed to create skybox shader"); - if (!m_GridShader) - DONUT_ERROR("Failed to create grid shader"); - - InitializeSphereGeometry(); - InitializeSkyboxGeometry(); - InitializeGridGeometry(); - - auto& hdriManager = HDRIManager::Get(); - m_HDRIEnvironment = hdriManager.GetCurrentHDRI(); - if (!m_HDRIEnvironment) - { - hdriManager.SetCurrentHDRI("Assets/HDRI/HDR_blue_nebulae-1.hdr"); - m_HDRIEnvironment = hdriManager.GetCurrentHDRI(); - if (!m_HDRIEnvironment) - DONUT_WARN("Failed to load default HDRI for WorldBuilder, using fallback"); - } - - Material blackHoleMaterial(glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.0f); - m_BlackHole = Object(glm::vec3(0.0f, 0.0f, 0.0f), 2.0f, blackHoleMaterial); - m_BlackHoleInitialized = true; - - // Set default grid size - m_GridSize = 10.0f; - - m_Initialized = true; - } - - void WorldBuilderState::OnExit() - { - DONUT_INFO("Exiting World Builder State"); - } - - void WorldBuilderState::OnUpdate(float deltaTime) - { - if (m_CameraDragging && - !ImGuizmo::IsUsing()) - { - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - double xpos, ypos; - glfwGetCursorPos(window, &xpos, &ypos); - - glm::vec2 currentMousePos(xpos, ypos); - glm::vec2 delta = currentMousePos - m_LastMousePos; - - float sensitivity = 0.005f; - float azimuthDelta = delta.x * sensitivity; - float elevationDelta = -delta.y * sensitivity; - - float newAzimuth = m_Camera.GetAzimuth() + azimuthDelta; - float newElevation = m_Camera.GetElevation() + elevationDelta; - - newElevation = glm::clamp(newElevation, 0.01f, static_cast<float>(std::numbers::pi) - 0.01f); - - m_Camera.SetAzimuth(newAzimuth); - m_Camera.SetElevation(newElevation); - m_Camera.UpdateOrbital(); - - m_LastMousePos = currentMousePos; - } - } - - void WorldBuilderState::OnRender() - { - auto& hdriManager = HDRIManager::Get(); - m_HDRIEnvironment = hdriManager.GetCurrentHDRI(); - - RenderCommand::SetClearColor(glm::vec4(0.1f, 0.1f, 0.1f, 1.0f)); - RenderCommand::Clear(); - - if (m_HDRIEnvironment) - RenderSkybox(); - - if (m_ShowGrid) - RenderGrid(); - - RenderScene(); - } - - void WorldBuilderState::OnEvent(Event& event) - { - EventDispatcher dispatcher(event); - - dispatcher.Dispatch<MouseButtonPressedEvent>([this](MouseButtonPressedEvent& e) - { - if (e.GetMouseButton() == GLFW_MOUSE_BUTTON_LEFT) - { - if (ImGuizmo::IsUsing() || - ImGuizmo::IsOver()) - return false; - - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - double xpos, ypos; - glfwGetCursorPos(window, &xpos, &ypos); - - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - float ndcX = (2.0f * static_cast<float>(xpos)) / static_cast<float>(width) - 1.0f; - float ndcY = 1.0f - (2.0f * static_cast<float>(ypos)) / static_cast<float>(height); - - glm::vec4 rayStart_NDC(ndcX, ndcY, -1.0f, 1.0f); - glm::vec4 rayEnd_NDC(ndcX, ndcY, 0.0f, 1.0f); - - glm::mat4 invVP = glm::inverse(m_Camera.GetProjectionMatrix() * m_Camera.GetViewMatrix()); - glm::vec4 rayStart_World = invVP * rayStart_NDC; - glm::vec4 rayEnd_World = invVP * rayEnd_NDC; - - rayStart_World /= rayStart_World.w; - rayEnd_World /= rayEnd_World.w; - - glm::vec3 rayDir = glm::normalize(glm::vec3(rayEnd_World - rayStart_World)); - glm::vec3 rayOrigin = glm::vec3(rayStart_World); - - float closestDistance = std::numeric_limits<float>::max(); - int closestObjectIndex = -1; - - if (m_BlackHoleInitialized) - { - glm::vec3 oc = rayOrigin - m_BlackHole.m_Centre; - float a = glm::dot(rayDir, rayDir); - float b = 2.0f * glm::dot(oc, rayDir); - float c = glm::dot(oc, oc) - m_BlackHole.m_Radius * m_BlackHole.m_Radius; - float discriminant = b * b - 4 * a * c; - - if (discriminant > 0) - { - float t1 = (-b - sqrt(discriminant)) / (2.0f * a); - float t2 = (-b + sqrt(discriminant)) / (2.0f * a); - - if (t1 > 0 && t1 < closestDistance) - { - closestDistance = t1; - closestObjectIndex = -2; - } - else if (t2 > 0 && t2 < closestDistance) - { - closestDistance = t2; - closestObjectIndex = -2; - } - } - } - - for (size_t i = 0; i < m_Scene.objs.size(); ++i) - { - const Object& obj = m_Scene.objs[i]; - - glm::vec3 oc = rayOrigin - obj.m_Centre; - float a = glm::dot(rayDir, rayDir); - float b = 2.0f * glm::dot(oc, rayDir); - float c = glm::dot(oc, oc) - obj.m_Radius * obj.m_Radius; - float discriminant = b * b - 4 * a * c; - - if (discriminant > 0) - { - float t1 = (-b - sqrt(discriminant)) / (2.0f * a); - float t2 = (-b + sqrt(discriminant)) / (2.0f * a); - - if (t1 > 0 && t1 < closestDistance) - { - closestDistance = t1; - closestObjectIndex = static_cast<int>(i); - } - else if (t2 > 0 && t2 < closestDistance) - { - closestDistance = t2; - closestObjectIndex = static_cast<int>(i); - } - } - } - - if (closestObjectIndex >= 0) - { - m_SelectedObjectIndex = closestObjectIndex; - DONUT_INFO("Selected object {}", closestObjectIndex); - return true; - } - else if (closestObjectIndex == -2) - { - m_SelectedObjectIndex = -1; - DONUT_INFO("Black hole clicked (not selectable)"); - return true; - } - else - { - m_SelectedObjectIndex = -1; - m_CameraDragging = true; - m_LastMousePos = glm::vec2(xpos, ypos); - } - - return true; - } - return false; - }); - - dispatcher.Dispatch<MouseButtonReleasedEvent>([this](MouseButtonReleasedEvent& e) - { - if (e.GetMouseButton() == GLFW_MOUSE_BUTTON_LEFT) - { - if (!ImGuizmo::IsUsing()) - m_CameraDragging = false; - return true; - } - - return false; - }); - - dispatcher.Dispatch<WindowResizeEvent>([this](WindowResizeEvent& e) - { - int newWidth = e.GetWidth(); - int newHeight = e.GetHeight(); - if (newWidth > 0 && newHeight > 0) - { - float aspect = static_cast<float>(newWidth) / static_cast<float>(newHeight); - m_Camera.SetProjection(45.0f, aspect, 0.1f, 1000.0f); - } - return false; - }); - - dispatcher.Dispatch<MouseScrolledEvent>([this](MouseScrolledEvent& e) - { - float zoomSpeed = 0.1f; - float zoomDelta = e.GetYOffset() * zoomSpeed; - - double currentRadius = m_Camera.GetOrbitalRadius(); - double newRadius = currentRadius - zoomDelta * currentRadius * 0.1f; - - double minRadius = 2.0f; - double maxRadius = 200.0f; - newRadius = glm::clamp(newRadius, minRadius, maxRadius); - - m_Camera.SetOrbitalRadius(newRadius); - m_Camera.UpdateOrbital(); - - return true; - }); - - dispatcher.Dispatch<KeyPressedEvent>([this](KeyPressedEvent& e) - { - if (m_SelectedObjectIndex >= 0 && - m_SelectedObjectIndex < static_cast<int>(m_Scene.objs.size())) - { - switch (e.GetKeyCode()) - { - case GLFW_KEY_M: - m_GizmoOperation = ImGuizmo::TRANSLATE; - return true; - case GLFW_KEY_R: - m_GizmoOperation = ImGuizmo::ROTATE; - return true; - case GLFW_KEY_S: - m_GizmoOperation = ImGuizmo::SCALE; - return true; - } - } - return false; - }); - } - - void WorldBuilderState::OnImUIRender() - { - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - ImGuiViewport* vp = ImGui::GetMainViewport(); - ImGuizmo::SetRect(vp->Pos.x, vp->Pos.y, vp->Size.x, vp->Size.y); - - ImGui::SetNextWindowSize(ImVec2(400, 600), ImGuiCond_FirstUseEver); - ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_FirstUseEver); - - ImGui::Begin("World Builder", nullptr, ImGuiWindowFlags_NoCollapse); - - ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]); - ImGui::TextColored(ImVec4(0.8f, 0.8f, 1.0f, 1.0f), "World Builder"); - ImGui::PopFont(); - ImGui::Separator(); - - if (ImGui::CollapsingHeader("Scene Info")) - { - ImGui::Text("Objects in scene: %zu/16 (+ 1 black hole)", m_Scene.objs.size()); - - ImGui::Separator(); - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Camera Info:"); - - glm::vec3 cameraPos = m_Camera.GetOrbitalPosition(); - glm::vec3 target = m_Camera.GetOrbitalTarget(); - - ImGui::Text("Position: (%.2f, %.2f, %.2f)", cameraPos.x, cameraPos.y, cameraPos.z); - ImGui::Text("Target: (%.2f, %.2f, %.2f)", target.x, target.y, target.z); - ImGui::Text("Distance: %.2f", m_Camera.GetOrbitalRadius()); - ImGui::Text("Azimuth: %.1f°", glm::degrees(m_Camera.GetAzimuth())); - ImGui::Text("Elevation: %.1f°", glm::degrees(m_Camera.GetElevation())); - - ImGui::Separator(); - - if (ImGui::Button("Reset Camera")) - { - m_Camera.SetOrbitalRadius(15.0f); - m_Camera.SetAzimuth(0.0f); - m_Camera.SetElevation(static_cast<float>(std::numbers::pi) / 3.0f); - m_Camera.SetOrbitalTarget(glm::vec3(0.0f, 0.0f, 0.0f)); - m_Camera.UpdateOrbital(); - } - - ImGui::SameLine(); - if (ImGui::Button("Clear Scene")) - ClearScene(); - - ImGui::SameLine(); - if (ImGui::Button("Focus on Objects")) - { - if (!m_Scene.objs.empty()) - { - glm::vec3 center(0.0f); - for (const auto& obj : m_Scene.objs) - center += obj.m_Centre; - center /= static_cast<float>(m_Scene.objs.size()); - m_Camera.SetOrbitalTarget(center); - m_Camera.UpdateOrbital(); - } - } - } - - ImGui::Spacing(); - - if (ImGui::CollapsingHeader("Create Object")) - { - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "New Sphere"); - ImGui::Separator(); - - ImGui::TextColored(ImVec4(0.8f, 0.8f, 0.8f, 1.0f), "Objects: %zu/16", m_Scene.objs.size()); - - ImGui::Text("Position:"); - ImGui::DragFloat3("##Position", &m_NewObjectPosition.x, 0.1f); - - ImGui::Text("Radius:"); - ImGui::DragFloat("##Radius", &m_NewObjectRadius, 0.1f, 0.1f, 10.0f); - - ImGui::Text("Color:"); - ImGui::ColorEdit3("##Color", &m_NewObjectColor.x); - - ImGui::Text("Specular:"); - ImGui::SliderFloat("##Specular", &m_NewObjectSpecular, 0.0f, 1.0f); - - ImGui::Text("Emission:"); - ImGui::SliderFloat("##Emission", &m_NewObjectEmission, 0.0f, 1.0f); - - ImGui::Spacing(); - - if (m_Scene.objs.size() >= 16) - { - ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f); - ImGui::Button("Add Sphere (Limit Reached)", ImVec2(ImGui::GetWindowWidth() - 20, 30)); - ImGui::PopStyleVar(); - } - else - { - if (ImGui::Button("Add Sphere", ImVec2(ImGui::GetWindowWidth() - 20, 30))) - AddSphere(); - } - } - - ImGui::Spacing(); - - if (ImGui::CollapsingHeader("Scene Objects")) - { - if (m_BlackHoleInitialized) - { - ImGui::PushID(-1); - - ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 1.0f), "Black Hole (Center)"); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Position: (0.00, 0.00, 0.00)"); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Radius: %.2f", m_BlackHole.m_Radius); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Color: Black (with white outline)"); - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Cannot be removed or modified"); - - ImGui::PopID(); - ImGui::Separator(); - } - - if (m_Scene.objs.empty()) - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "No additional objects in scene"); - else - { - for (size_t i = 0; i < m_Scene.objs.size(); ++i) - { - Object& obj = m_Scene.objs[i]; - - ImGui::PushID(static_cast<int>(i)); - - bool isSelected = (m_SelectedObjectIndex == static_cast<int>(i)); - if (ImGui::Selectable(("Sphere " + std::to_string(i)).c_str(), isSelected)) - m_SelectedObjectIndex = static_cast<int>(i); - - if (isSelected) - { - ImGui::SameLine(); - if (ImGui::Button("Remove")) - { - RemoveSelectedObject(); - } - - ImGui::Text("Position: (%.2f, %.2f, %.2f)", - obj.m_Centre.x, obj.m_Centre.y, obj.m_Centre.z); - ImGui::Text("Radius: %.2f", obj.m_Radius); - ImGui::Text("Color: (%.2f, %.2f, %.2f)", - obj.m_Material.m_Color.x, obj.m_Material.m_Color.y, obj.m_Material.m_Color.z); - } - - ImGui::PopID(); - } - } - } - - ImGui::Spacing(); - - if (ImGui::CollapsingHeader("Gizmo Controls")) - { - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Gizmo Operation:"); - - if (ImGui::RadioButton("Translate", m_GizmoOperation == ImGuizmo::TRANSLATE)) - m_GizmoOperation = ImGuizmo::TRANSLATE; - ImGui::SameLine(); - if (ImGui::RadioButton("Rotate", m_GizmoOperation == ImGuizmo::ROTATE)) - m_GizmoOperation = ImGuizmo::ROTATE; - ImGui::SameLine(); - if (ImGui::RadioButton("Scale", m_GizmoOperation == ImGuizmo::SCALE)) - m_GizmoOperation = ImGuizmo::SCALE; - - ImGui::Spacing(); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Hotkeys:"); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "M = Move, R = Rotate, S = Scale"); - } - - ImGui::Spacing(); - - if (ImGui::CollapsingHeader("Selection Outline")) - { - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Outline Settings:"); - - ImGui::Text("Outline Color:"); - ImGui::ColorEdit3("##OutlineColor", &m_OutlineColor.x); - - ImGui::Text("Outline Width:"); - ImGui::SliderFloat("##OutlineWidth", &m_OutlineWidth, 0.01f, 0.9f, "%.2f"); - - ImGui::Spacing(); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "White rim around sphere silhouette"); - } - - ImGui::Spacing(); - - if (ImGui::CollapsingHeader("Grid Settings")) - { - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "Grid Settings:"); - - ImGui::Text("Show Grid:"); - ImGui::SameLine(); - ImGui::Checkbox("##ShowGrid", &m_ShowGrid); - - ImGui::Text("Grid Color:"); - ImGui::ColorEdit3("##GridColor", &m_GridColor.x); - - ImGui::Text("Grid Alpha:"); - ImGui::SliderFloat("##GridAlpha", &m_GridAlpha, 0.0f, 1.0f, "%.2f"); - - ImGui::Text("Grid Size:"); - ImGui::SliderFloat("##GridSize", &m_GridSize, 1.0f, 500.0f, "%.1f"); - - ImGui::Spacing(); - if (ImGui::Button("Regenerate Grid", ImVec2(ImGui::GetWindowWidth() - 20, 25))) - InitializeGridGeometry(); - - ImGui::Spacing(); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Reference grid for spatial orientation"); - } - - ImGui::Spacing(); - - if (ImGui::CollapsingHeader("HDRI Environment", nullptr)) - { - ImGui::TextColored(ImVec4(0.9f, 0.9f, 1.0f, 1.0f), "HDRI Settings:"); - - static int selectedHDRI = 0; - ImGui::PushID("WorldBuilderHDRI"); - auto& hdriManager = HDRIManager::Get(); - const auto& availableHDRI = hdriManager.GetAvailableHDRI(); - - static std::vector<std::string> hdriOptionNames; - static std::vector<const char*> hdriOptions; - - if (hdriOptionNames.size() != availableHDRI.size()) - { - hdriOptionNames.clear(); - hdriOptions.clear(); - - for (const auto& path : availableHDRI) - { - hdriOptionNames.push_back(hdriManager.GetHDRIName(path)); - hdriOptions.push_back(hdriOptionNames.back().c_str()); - } - } - - if (ImGui::Combo("HDRI Environment", &selectedHDRI, hdriOptions.data(), static_cast<int>(hdriOptions.size()))) - { - auto& hdriManager = HDRIManager::Get(); - hdriManager.SetCurrentHDRI(availableHDRI[selectedHDRI]); - m_HDRIEnvironment = hdriManager.GetCurrentHDRI(); - } - - ImGui::Spacing(); - ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "HDRI provides background skybox and lighting for the scene"); - ImGui::PopID(); - } - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::Spacing(); - - float buttonWidth = (ImGui::GetWindowWidth() - 30) / 2.0f; - - if (ImGui::Button("Save Scene", ImVec2(buttonWidth, 30))) - SaveScene(); - - ImGui::SameLine(); - if (ImGui::Button("Load Scene", ImVec2(buttonWidth, 30))) - LoadScene(); - - ImGui::Spacing(); - - if (ImGui::Button("Start Simulation", ImVec2(ImGui::GetWindowWidth() - 20, 30))) - { - auto& engine = Application::Get().GetEngine(); - engine.LoadObjectsFromScene(m_Scene.objs); - Application::Get().GetStateManager().SwitchToState("Simulation"); - } - - ImGui::Spacing(); - - if (ImGui::Button("Back to Config", ImVec2(ImGui::GetWindowWidth() - 20, 30))) - Application::Get().GetStateManager().SwitchToState("Config"); - - ImGui::Spacing(); - ImGui::Separator(); - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Camera: Left mouse = rotate, Scroll = zoom"); - ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Gizmo: M=Move, R=Rotate, S=Scale"); - - ImGui::End(); - - if (m_SelectedObjectIndex >= 0 && - m_SelectedObjectIndex < static_cast<int>(m_Scene.objs.size()) && - m_SelectedObjectIndex != -2) - { - glm::mat4 view = m_Camera.GetViewMatrix(); - glm::mat4 projection = m_Camera.GetProjectionMatrix(); - - Object& selectedObj = m_Scene.objs[m_SelectedObjectIndex]; - - glm::mat4 objectTransform = glm::mat4(1.0f); - objectTransform = glm::translate(objectTransform, selectedObj.m_Centre); - objectTransform = glm::scale(objectTransform, glm::vec3(selectedObj.m_Radius)); - - DONUT_INFO("Object position: ({}, {}, {})", selectedObj.m_Centre.x, selectedObj.m_Centre.y, selectedObj.m_Centre.z); - glm::vec3 cameraPos = m_Camera.GetOrbitalPosition(); - DONUT_INFO("Camera position: ({}, {}, {})", cameraPos.x, cameraPos.y, cameraPos.z); - - glm::vec3 viewTranslation = glm::vec3(view[3][0], view[3][1], view[3][2]); - DONUT_INFO("View translation: ({}, {}, {})", viewTranslation.x, viewTranslation.y, viewTranslation.z); - - ImGuizmo::SetDrawlist(ImGui::GetForegroundDrawList()); - if (ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection), - m_GizmoOperation, m_GizmoMode, - glm::value_ptr(objectTransform), - nullptr, nullptr)) - { - glm::vec3 newPosition = glm::vec3(objectTransform[3][0], objectTransform[3][1], objectTransform[3][2]); - selectedObj.m_Centre = newPosition; - - glm::vec3 scale = glm::vec3 - ( - glm::length(glm::vec3(objectTransform[0])), - glm::length(glm::vec3(objectTransform[1])), - glm::length(glm::vec3(objectTransform[2])) - ); - selectedObj.m_Radius = (scale.x + scale.y + scale.z) / 3.0f; - - DONUT_INFO("Matrix [3]: ({}, {}, {}, {})", objectTransform[3][0], objectTransform[3][1], objectTransform[3][2], objectTransform[3][3]); - DONUT_INFO("New position: ({}, {}, {})", newPosition.x, newPosition.y, newPosition.z); - } - } - } - - void WorldBuilderState::AddSphere() - { - if (m_Scene.objs.size() >= 16) - { - DONUT_WARN("Cannot add more objects. Maximum of 16 objects reached."); - return; - } - - Material material(m_NewObjectColor, m_NewObjectSpecular, m_NewObjectEmission); - Object sphere(m_NewObjectPosition, m_NewObjectRadius, material); - m_Scene.objs.push_back(sphere); - - m_SelectedObjectIndex = static_cast<int>(m_Scene.objs.size() - 1); - - m_NewObjectPosition = glm::vec3(0.0f, 0.0f, 0.0f); - m_NewObjectRadius = 1.0f; - m_NewObjectColor = glm::vec3(1.0f, 1.0f, 1.0f); - m_NewObjectSpecular = 0.5f; - m_NewObjectEmission = 0.0f; - - DONUT_INFO("Added sphere to scene and selected it"); - } - - void WorldBuilderState::RemoveSelectedObject() - { - if (m_SelectedObjectIndex >= 0 && m_SelectedObjectIndex < static_cast<int>(m_Scene.objs.size())) - { - m_Scene.objs.erase(m_Scene.objs.begin() + m_SelectedObjectIndex); - m_SelectedObjectIndex = -1; - DONUT_INFO("Removed object from scene"); - } - } - - void WorldBuilderState::ClearScene() - { - m_Scene.objs.clear(); - m_SelectedObjectIndex = -1; - DONUT_INFO("Cleared scene (black hole remains at center)"); - } - - void WorldBuilderState::SaveScene() - { - nlohmann::json sceneData; - sceneData["objects"] = nlohmann::json::array(); - - for (const auto& obj : m_Scene.objs) - { - nlohmann::json sphereData; - sphereData["position"] = - { - obj.m_Centre.x, - obj.m_Centre.y, - obj.m_Centre.z - }; - - sphereData["color"] = - { - obj.m_Material.m_Color.x, - obj.m_Material.m_Color.y, - obj.m_Material.m_Color.z - }; - - sphereData["radius"] = obj.m_Radius; - sphereData["specular"] = obj.m_Material.m_Specular; - sphereData["emission"] = obj.m_Material.m_Emission; - sceneData["objects"].push_back(sphereData); - } - - std::ofstream file("Scene.json"); - if (file.is_open()) - { - file << sceneData.dump(4); - file.close(); - DONUT_INFO("Scene saved to Scene.json (black hole always present at center)"); - } - else - DONUT_ERROR("Failed to save scene"); - } - - void WorldBuilderState::LoadScene() - { - std::ifstream file("Scene.json"); - if (file.is_open()) - { - m_Scene.objs.clear(); - m_SelectedObjectIndex = -1; - - nlohmann::json sceneData; - file >> sceneData; - - if (sceneData.contains("objects")) - { - for (const auto& sphereData : sceneData["objects"]) - { - glm::vec3 position; - glm::vec3 color; - float radius; - float specular; - float emission; - - auto posArray = sphereData["position"]; - position.x = posArray[0].get<float>(); - position.y = posArray[1].get<float>(); - position.z = posArray[2].get<float>(); - - auto colorArray = sphereData["color"]; - color.x = colorArray[0].get<float>(); - color.y = colorArray[1].get<float>(); - color.z = colorArray[2].get<float>(); - - radius = sphereData["radius"].get<float>(); - specular = sphereData["specular"].get<float>(); - emission = sphereData["emission"].get<float>(); - - Material material(color, specular, emission); - Object sphere(position, radius, material); - m_Scene.objs.push_back(sphere); - } - } - - file.close(); - DONUT_INFO("Scene loaded from Scene.json (black hole remains at center)"); - } - else - DONUT_ERROR("Failed to load scene"); - } - - void WorldBuilderState::InitializeSphereGeometry() - { - std::vector<float> vertices; - std::vector<uint32_t> indices; - - const int segments = 32; - const int rings = 16; - - for (int ring = 0; ring <= rings; ++ring) - { - float phi = static_cast<float>(std::numbers::pi) * ring / rings; - float sinPhi = sin(phi); - float cosPhi = cos(phi); - - for (int segment = 0; segment <= segments; ++segment) - { - float theta = 2.0f * static_cast<float>(std::numbers::pi) * segment / segments; - float sinTheta = sin(theta); - float cosTheta = cos(theta); - - float x = cosTheta * sinPhi; - float y = cosPhi; - float z = sinTheta * sinPhi; - - float nx = x; - float ny = y; - float nz = z; - - vertices.push_back(x); - vertices.push_back(y); - vertices.push_back(z); - vertices.push_back(nx); - vertices.push_back(ny); - vertices.push_back(nz); - } - } - - for (int ring = 0; ring < rings; ++ring) - { - for (int segment = 0; segment < segments; ++segment) - { - uint32_t first = ring * (segments + 1) + segment; - uint32_t second = first + segments + 1; - - indices.push_back(first); - indices.push_back(second); - indices.push_back(first + 1); - - indices.push_back(second); - indices.push_back(second + 1); - indices.push_back(first + 1); - } - } - - auto vertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(vertices.data(), static_cast<uint32_t>(vertices.size() * sizeof(float)))); - VertexBufferLayout layout; - layout.Push<float>(3); - layout.Push<float>(3); - vertexBuffer->SetLayout(layout); - - auto indexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(indices.data(), static_cast<uint32_t>(indices.size()))); - - m_SphereVAO = Ref<VertexArray>(VertexArray::Create()); - m_SphereVAO->AddVertexBuffer(vertexBuffer); - m_SphereVAO->SetIndexBuffer(indexBuffer); - } - - void WorldBuilderState::RenderScene() - { - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - RenderCommand::SetViewport(0, 0, width, height); - RenderCommand::EnableDepthTest(); - - glm::mat4 view = m_Camera.GetViewMatrix(); - glm::mat4 projection = m_Camera.GetProjectionMatrix(); - glm::mat4 viewProjection = projection * view; - - glm::vec3 lightPos = m_Scene.m_LightPos; - glm::vec3 cameraPos = m_Camera.GetOrbitalPosition(); - - m_SphereShader->Bind(); - m_SphereShader->SetMat4("u_ViewProjection", viewProjection); - m_SphereShader->SetFloat3("u_LightPos", lightPos); - m_SphereShader->SetFloat3("u_CameraPos", cameraPos); - - m_SphereShader->SetFloat3("u_OutlineColor", m_OutlineColor); - m_SphereShader->SetFloat("u_OutlineWidth", m_OutlineWidth); - - if (m_HDRIEnvironment) - { - m_HDRIEnvironment->Bind(1); - m_SphereShader->SetInt("u_HDRIEnvironment", 1); - } - - if (m_BlackHoleInitialized) - { - glm::mat4 blackHoleTransform = glm::translate(glm::mat4(1.0f), m_BlackHole.m_Centre); - blackHoleTransform = glm::scale(blackHoleTransform, glm::vec3(m_BlackHole.m_Radius)); - - m_SphereShader->SetMat4("u_Transform", blackHoleTransform); - m_SphereShader->SetInt("u_IsSelected", 1); - m_SphereShader->SetFloat3("u_Color", m_BlackHole.m_Material.m_Color); - m_SphereShader->SetFloat("u_Emission", m_BlackHole.m_Material.m_Emission); - m_SphereShader->SetFloat("u_Specular", m_BlackHole.m_Material.m_Specular); - m_SphereShader->SetFloat("u_OutlineWidth", 0.3f); - - m_SphereVAO->Bind(); - RenderCommand::DrawIndexed(m_SphereVAO); - - m_SphereShader->SetFloat("u_OutlineWidth", m_OutlineWidth); - } - - for (size_t i = 0; i < m_Scene.objs.size(); ++i) - { - const auto& obj = m_Scene.objs[i]; - - glm::mat4 transform = glm::translate(glm::mat4(1.0f), obj.m_Centre); - transform = glm::scale(transform, glm::vec3(obj.m_Radius)); - - m_SphereShader->SetMat4("u_Transform", transform); - - bool isSelected = (m_SelectedObjectIndex == static_cast<int>(i)); - m_SphereShader->SetInt("u_IsSelected", isSelected ? 1 : 0); - if (isSelected) - { - glm::vec3 highlightColor = obj.m_Material.m_Color * 1.5f; - highlightColor = glm::clamp(highlightColor, 0.0f, 1.0f); - m_SphereShader->SetFloat3("u_Color", highlightColor); - m_SphereShader->SetFloat("u_Emission", 0.2f); - } - else - { - m_SphereShader->SetFloat3("u_Color", obj.m_Material.m_Color); - m_SphereShader->SetFloat("u_Emission", obj.m_Material.m_Emission); - } - - m_SphereShader->SetFloat("u_Specular", obj.m_Material.m_Specular); - - m_SphereVAO->Bind(); - RenderCommand::DrawIndexed(m_SphereVAO); - } - - RenderCommand::DisableDepthTest(); - } - - - - void WorldBuilderState::InitializeSkyboxGeometry() - { - float skyboxVertices[] = - { - -1.0f, 1.0f, -1.0f, - -1.0f, -1.0f, -1.0f, - 1.0f, -1.0f, -1.0f, - 1.0f, -1.0f, -1.0f, - 1.0f, 1.0f, -1.0f, - -1.0f, 1.0f, -1.0f, - - -1.0f, -1.0f, 1.0f, - -1.0f, -1.0f, -1.0f, - -1.0f, 1.0f, -1.0f, - -1.0f, 1.0f, -1.0f, - -1.0f, 1.0f, 1.0f, - -1.0f, -1.0f, 1.0f, - - 1.0f, -1.0f, -1.0f, - 1.0f, -1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, -1.0f, - 1.0f, -1.0f, -1.0f, - - -1.0f, -1.0f, 1.0f, - -1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f, -1.0f, 1.0f, - -1.0f, -1.0f, 1.0f, - - -1.0f, 1.0f, -1.0f, - 1.0f, 1.0f, -1.0f, - 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, - -1.0f, 1.0f, 1.0f, - -1.0f, 1.0f, -1.0f, - - -1.0f, -1.0f, -1.0f, - -1.0f, -1.0f, 1.0f, - 1.0f, -1.0f, -1.0f, - 1.0f, -1.0f, -1.0f, - -1.0f, -1.0f, 1.0f, - 1.0f, -1.0f, 1.0f - }; - - auto vertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(skyboxVertices, sizeof(skyboxVertices))); - VertexBufferLayout layout; - layout.Push<float>(3); - vertexBuffer->SetLayout(layout); - - m_SkyboxVAO = Ref<VertexArray>(VertexArray::Create()); - m_SkyboxVAO->AddVertexBuffer(vertexBuffer); - } - - void WorldBuilderState::RenderSkybox() - { - if (!m_SkyboxShader || !m_SkyboxVAO || !m_HDRIEnvironment) - return; - - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - RenderCommand::SetViewport(0, 0, width, height); - RenderCommand::DisableDepthTest(); - - glm::mat4 view = m_Camera.GetViewMatrix(); - glm::mat4 projection = m_Camera.GetProjectionMatrix(); - - view = glm::mat4(glm::mat3(view)); - - m_SkyboxShader->Bind(); - m_SkyboxShader->SetMat4("u_View", view); - m_SkyboxShader->SetMat4("u_Projection", projection); - - m_HDRIEnvironment->Bind(0); - m_SkyboxShader->SetInt("u_Skybox", 0); - - m_SkyboxVAO->Bind(); - RenderCommand::DrawArrays(36); - - RenderCommand::EnableDepthTest(); - } - - void WorldBuilderState::InitializeGridGeometry() - { - if (m_GridVAO) - { - m_GridVAO->Unbind(); - m_GridVAO.reset(); - } - - const float gridSize = 50.0f; - const int gridLines = 101; - const float halfSize = gridSize * 0.5f; - const float step = gridSize / (gridLines - 1); - - std::vector<float> vertices; - std::vector<uint32_t> indices; - - for (int i = 0; i < gridLines; ++i) - { - float z = -halfSize + i * step; - - vertices.push_back(-halfSize); - vertices.push_back(0.0f); - vertices.push_back(z); - - vertices.push_back(halfSize); - vertices.push_back(0.0f); - vertices.push_back(z); - - uint32_t baseIndex = static_cast<uint32_t>(vertices.size() / 3) - 2; - indices.push_back(baseIndex); - indices.push_back(baseIndex + 1); - } - - for (int i = 0; i < gridLines; ++i) - { - float x = -halfSize + i * step; - - vertices.push_back(x); - vertices.push_back(0.0f); - vertices.push_back(-halfSize); - - vertices.push_back(x); - vertices.push_back(0.0f); - vertices.push_back(halfSize); - - uint32_t baseIndex = static_cast<uint32_t>(vertices.size() / 3) - 2; - indices.push_back(baseIndex); - indices.push_back(baseIndex + 1); - } - - auto vertexBuffer = Ref<VertexBuffer>(VertexBuffer::Create(vertices.data(), static_cast<uint32_t>(vertices.size() * sizeof(float)))); - VertexBufferLayout layout; - layout.Push<float>(3); - vertexBuffer->SetLayout(layout); - - auto indexBuffer = Ref<IndexBuffer>(IndexBuffer::Create(indices.data(), static_cast<uint32_t>(indices.size()))); - - m_GridVAO = Ref<VertexArray>(VertexArray::Create()); - m_GridVAO->AddVertexBuffer(vertexBuffer); - m_GridVAO->SetIndexBuffer(indexBuffer); - - m_GridVAO->Unbind(); - } - - void WorldBuilderState::RenderGrid() - { - if (!m_GridShader || !m_GridVAO) - return; - - GLFWwindow* window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow()); - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - RenderCommand::SetViewport(0, 0, width, height); - RenderCommand::EnableDepthTest(); - RenderCommand::EnableBlending(); - - glm::mat4 view = m_Camera.GetViewMatrix(); - glm::mat4 projection = m_Camera.GetProjectionMatrix(); - glm::mat4 viewProjection = projection * view; - glm::mat4 transform = glm::mat4(1.0f); - - glm::vec3 cameraPos = m_Camera.GetOrbitalPosition(); - - m_GridShader->Bind(); - m_GridShader->SetMat4("u_ViewProjection", viewProjection); - m_GridShader->SetMat4("u_Transform", transform); - m_GridShader->SetFloat3("u_GridColor", m_GridColor); - m_GridShader->SetFloat("u_GridAlpha", m_GridAlpha); - m_GridShader->SetFloat("u_GridSize", m_GridSize); - m_GridShader->SetFloat3("u_CameraPos", cameraPos); - - m_GridVAO->Bind(); - RenderCommand::DrawLines(m_GridVAO); - - // Clean up state to prevent conflicts with scene rendering - m_GridVAO->Unbind(); - m_GridShader->Unbind(); - RenderCommand::DisableBlending(); - - // Ensure depth test is still enabled for scene rendering - RenderCommand::EnableDepthTest(); - } -}; diff --git a/src/States/WorldBuilderState.h b/src/States/WorldBuilderState.h deleted file mode 100644 index 2d65060..0000000 --- a/src/States/WorldBuilderState.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include "Core/Camera.h" -#include "Core/State.h" -#include "Core/Event.h" -#include "Core/Log.h" - -#include "Engine/Scene.h" -#include "Engine/Object.h" - -#include "Rendering/Renderer.h" -#include "Rendering/Shader.h" -#include "Rendering/VertexArray.h" - -#include <imgui.h> -#include <ImGuizmo.h> - -#include <vector> -#include <memory> - -namespace Donut -{ - class WorldBuilderState - : public State - { - public: - ~WorldBuilderState() = default; - - void OnEnter() override; - void OnExit() override; - void OnUpdate(float deltaTime) override; - void OnRender() override; - void OnImUIRender() override; - void OnEvent(Event& event) override; - private: - void AddSphere(); - void RemoveSelectedObject(); - void ClearScene(); - void SaveScene(); - void LoadScene(); - void RenderScene(); - void InitializeSphereGeometry(); - void InitializeGridGeometry(); - void RenderGrid(); - private: - Scene m_Scene; - Camera m_Camera; - bool m_Initialized = false; - - Ref<Shader> m_SphereShader; - Ref<VertexArray> m_SphereVAO; - Ref<CubemapTexture> m_HDRIEnvironment; - - Ref<Shader> m_SkyboxShader; - Ref<VertexArray> m_SkyboxVAO; - - Ref<Shader> m_GridShader; - Ref<VertexArray> m_GridVAO; - - glm::vec3 m_NewObjectPosition = glm::vec3(0.0f, 0.0f, 0.0f); - float m_NewObjectRadius = 1.0f; - glm::vec3 m_NewObjectColor = glm::vec3(1.0f, 1.0f, 1.0f); - float m_NewObjectSpecular = 0.5f; - float m_NewObjectEmission = 0.0f; - - int m_SelectedObjectIndex = -1; - bool m_CameraDragging = false; - glm::vec2 m_LastMousePos = glm::vec2(0.0f, 0.0f); - - ImGuizmo::OPERATION m_GizmoOperation = ImGuizmo::TRANSLATE; - ImGuizmo::MODE m_GizmoMode = ImGuizmo::LOCAL; - - bool m_ShowObjectList = true; - bool m_ShowObjectCreator = true; - bool m_ShowSceneInfo = true; - bool m_ShowGizmoControls = true; - bool m_ShowOutlineControls = true; - bool m_ShowGrid = true; - - glm::vec3 m_OutlineColor = glm::vec3(1.0f, 1.0f, 1.0f); - float m_OutlineWidth = 0.25f; - - glm::vec3 m_GridColor = glm::vec3(0.5f, 0.5f, 0.5f); - float m_GridAlpha = 0.5f; - float m_GridSize = 50.0f; - - Object m_BlackHole; - bool m_BlackHoleInitialized = false; - - void SetHDRIEnvironment(Ref<CubemapTexture> hdri) { m_HDRIEnvironment = hdri; } - Ref<CubemapTexture> GetHDRIEnvironment() const { return m_HDRIEnvironment; } - - void InitializeSkyboxGeometry(); - void RenderSkybox(); - }; -}; |
