From bc2d88c799cb3913a5defe4ea9ddea9c56814349 Mon Sep 17 00:00:00 2001 From: hachem Date: Thu, 14 Aug 2025 18:21:00 +0200 Subject: [help]: I am going to throw my computer out a window --- src/Engine/Engine.h | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/Engine/Engine.h (limited to 'src/Engine/Engine.h') diff --git a/src/Engine/Engine.h b/src/Engine/Engine.h new file mode 100644 index 0000000..2368bb8 --- /dev/null +++ b/src/Engine/Engine.h @@ -0,0 +1,118 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Core/Application.h" +#include "Core/Camera.h" +#include "Rendering/Renderer.h" +#include "Rendering/Shader.h" +#include "Rendering/Texture.h" +#include "Rendering/VertexArray.h" +#include "Rendering/UniformBuffer.h" + +namespace Donut +{ + const double c = 299792458.0; + const double G = 6.67430e-11; + + struct BlackHole + { + glm::vec3 m_Position; + double m_Mass; + double m_Radius; + double m_Rs; + + BlackHole(glm::vec3 pos, float mass) + : m_Position(pos), + m_Mass(mass) + { + m_Rs = 2.0 * G * m_Mass / (c * c); + } + + bool Intercept(float px, float py, float pz) const + { + double dx = double(px) - double(m_Position.x); + double dy = double(py) - double(m_Position.y); + double dz = double(pz) - double(m_Position.z); + double dist2 = dx * dx + dy * dy + dz * dz; + return dist2 < m_Rs * m_Rs; + } + }; + + struct ObjectData + { + glm::vec4 m_PosRadius; + glm::vec4 m_Color; + float m_Mass; + glm::vec3 m_Velocity = glm::vec3(0.0f, 0.0f, 0.0f); + }; + + class Engine + { + public: + Engine(); + ~Engine() = default; + + void GenerateGrid(const std::vector& objects); + void DrawGrid(const glm::mat4& viewProj); + void DrawFullScreenQuad(); + void DispatchCompute(const Camera& cam); + void UploadCameraUBO(const Camera& cam); + void UploadObjectsUBO(const std::vector& objs); + void UploadDiskUBO(); + void RenderScene(); + void UpdatePhysics(float deltaTime); + void UpdateWindowDimensions(); + + Camera& GetCamera() { return m_Camera; } + const Camera& GetCamera() const { return m_Camera; } + + const std::vector& GetObjects() const { return m_Objects; } + std::vector& GetObjects() { return m_Objects; } + + bool GetGravity() const { return m_Gravity; } + void SetGravity(bool gravity) { m_Gravity = gravity; } + + int GetWidth() const { return m_Width; } + int GetHeight() const { return m_Height; } + int GetComputeWidth() const { return m_ComputeWidth; } + int GetComputeHeight() const { return m_ComputeHeight; } + + private: + std::string CreateBasicVertexShader(); + std::string CreateBasicFragmentShader(); + std::string LoadComputeShader(const std::string& path); + private: + Ref m_GridShader; + Ref m_QuadShader; + Ref m_ComputeShader; + Ref m_Texture; + Ref m_QuadVAO; + Ref m_GridVAO; + Ref m_CameraUBO; + Ref m_DiskUBO; + Ref m_ObjectsUBO; + + int m_GridIndexCount = 0; + int m_Width; + int m_Height; + int m_ComputeWidth; + int m_ComputeHeight; + float m_WidthScale = 100000000000.0f; + float m_HeightScale = 75000000000.0f; + + std::vector m_Objects; + BlackHole m_SagA; + Camera m_Camera; + bool m_Gravity = false; + }; +} -- cgit v1.3