aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Engine/Engine.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/Engine/Engine.cpp b/src/Engine/Engine.cpp
index 9c2a4f6..e436f4c 100644
--- a/src/Engine/Engine.cpp
+++ b/src/Engine/Engine.cpp
@@ -21,14 +21,14 @@ namespace Donut
{
m_Width = 1280;
m_Height = 720;
-
+
m_Camera.SetCameraMode(CameraMode::Orbital);
m_Camera.SetOrbitalRadius(1e11);
m_Camera.SetOrbitalLimits(1e9, 1e13);
m_Camera.SetOrbitalSpeed(0.01f);
m_Camera.SetZoomSpeed(1e10f);
-
- m_Objects =
+
+ m_Objects =
{
{ glm::vec4(0.00f, 0.00f, 0.00f, m_SagA.m_Rs), glm::vec4(0, 0, 0, 1), static_cast<float>(m_SagA.m_Mass) }
};
@@ -39,7 +39,7 @@ namespace Donut
m_ComputeProgram = Ref<Shader>(Shader::Create("Assets/Shaders/Geodesic.glsl"));
m_ShaderProgram = Ref<Shader>(Shader::Create("Assets/Shaders/TexturedQuad.glsl"));
m_BlurShader = Ref<Shader>(Shader::Create("Assets/Shaders/Blur.glsl"));
-
+
auto& hdriManager = HDRIManager::Get();
m_HDRIEnvironment = hdriManager.GetCurrentHDRI();
if (!m_HDRIEnvironment)
@@ -49,15 +49,15 @@ namespace Donut
if (!m_HDRIEnvironment)
DONUT_WARN("Failed to load default HDRI, using fallback");
}
-
+
m_CameraUBO = UniformBuffer::Create(128, 1);
m_DiskUBO = UniformBuffer::Create(sizeof(float) * 5, 2);
-
+
uint32_t objUBOSize = sizeof(int) + 3 * sizeof(float)
+ 16 * (sizeof(glm::vec4) + sizeof(glm::vec4))
+ 16 * sizeof(float);
m_ObjectsUBO = UniformBuffer::Create(objUBOSize, 3);
-
+
m_SimulationUBO = UniformBuffer::Create(sizeof(int) * 2 + sizeof(float) * 2, 4);
auto result = QuadVAO();
@@ -89,18 +89,18 @@ namespace Donut
{
UpdateComputeDimensions();
}
-
+
void Engine::SetWindowDimensions(int width, int height)
{
int oldWidth = m_Width;
int oldHeight = m_Height;
int oldComputeHeight = m_ComputeHeight;
-
+
m_Width = width;
m_Height = height;
-
- if (oldWidth != m_Width ||
- oldHeight != m_Height ||
+
+ if (oldWidth != m_Width ||
+ oldHeight != m_Height ||
oldComputeHeight != m_ComputeHeight)
UpdateComputeDimensions();
}
@@ -119,7 +119,7 @@ namespace Donut
void Engine::DrawFullScreenQuad()
{
RenderCommand::SetViewport(0, 0, m_Width, m_Height);
-
+
m_ShaderProgram->Bind();
m_QuadVAO->Bind();
@@ -134,7 +134,7 @@ namespace Donut
void Engine::DrawBlurPass()
{
RenderCommand::SetViewport(0, 0, m_Width, m_Height);
-
+
m_BlurShader->Bind();
m_QuadVAO->Bind();
@@ -333,7 +333,7 @@ namespace Donut
double Gforce = (G * obj.m_Mass * obj2.m_Mass) / (distance * distance);
double acc1 = Gforce / obj.m_Mass;
std::vector<double> acc = {direction[0] * acc1, direction[1] * acc1, direction[2] * acc1};
-
+
if (m_Gravity)
{
obj.m_Velocity.x += static_cast<float>(acc[0]);
@@ -374,7 +374,7 @@ namespace Donut
std::pair<Ref<VertexArray>, Ref<Texture2D>> Engine::QuadVAO()
{
- float quadVertices[] =
+ float quadVertices[] =
{
// Positions // TexCoords
-1.0f, 1.0f, 0.0f, 1.0f,
@@ -394,24 +394,24 @@ namespace Donut
auto vertexArray = Ref<VertexArray>(VertexArray::Create());
vertexArray->AddVertexBuffer(vertexBuffer);
auto texture = Texture2D::Create(GetComputeWidth(), m_ComputeHeight);
-
+
return { vertexArray, texture };
}
-
+
void Engine::LoadObjectsFromScene(const std::vector<Donut::Object>& objects)
{
m_Objects.clear();
m_Objects.push_back(
- {
- glm::vec4(0.00f, 0.00f, 0.00f, m_SagA.m_Rs),
- glm::vec4(0, 0, 0, 1),
- static_cast<float>(m_SagA.m_Mass)
+ {
+ glm::vec4(0.00f, 0.00f, 0.00f, m_SagA.m_Rs),
+ glm::vec4(0, 0, 0, 1),
+ static_cast<float>(m_SagA.m_Mass)
});
-
+
for (const auto& obj : objects)
{
ObjectData engineObj;
-
+
float scaleFactor = 1e10f;
engineObj.m_PosRadius = glm::vec4
(
@@ -420,30 +420,30 @@ namespace Donut
obj.m_Centre.z * scaleFactor,
obj.m_Radius * scaleFactor
);
-
+
engineObj.m_Color = glm::vec4(obj.m_Material.m_Color, 1.0f);
-
+
float volume = (4.0f / 3.0f) * 3.14159f * engineObj.m_PosRadius.w * engineObj.m_PosRadius.w * engineObj.m_PosRadius.w;
float density = 1e12f;
engineObj.m_Mass = volume * density;
engineObj.m_Velocity = glm::vec3(0.0f, 0.0f, 0.0f);
-
+
m_Objects.push_back(engineObj);
}
-
+
DONUT_INFO("Loaded {} objects from WorldBuilder scene (scaled up by {})", objects.size(), 1e10f);
PrintObjectInfo();
}
-
+
void Engine::PrintObjectInfo() const
{
DONUT_INFO("=== Object Information ===");
DONUT_INFO("Total objects: {}", m_Objects.size());
-
+
for (size_t i = 0; i < m_Objects.size(); ++i)
{
const auto& obj = m_Objects[i];
- DONUT_INFO("Object {}: Pos=({}, {}, {}), Radius={}, Mass={}, Color=({}, {}, {})",
+ DONUT_INFO("Object {}: Pos=({}, {}, {}), Radius={}, Mass={}, Color=({}, {}, {})",
i,
obj.m_PosRadius.x, obj.m_PosRadius.y, obj.m_PosRadius.z,
obj.m_PosRadius.w,
@@ -451,7 +451,7 @@ namespace Donut
obj.m_Color.x, obj.m_Color.y, obj.m_Color.z
);
}
- DONUT_INFO("Camera position: ({}, {}, {})",
+ DONUT_INFO("Camera position: ({}, {}, {})",
m_Camera.GetOrbitalPosition().x,
m_Camera.GetOrbitalPosition().y,
m_Camera.GetOrbitalPosition().z
@@ -459,52 +459,52 @@ namespace Donut
DONUT_INFO("Camera radius: {}", m_Camera.GetOrbitalRadius());
DONUT_INFO("========================");
}
-
+
void Engine::ExportHighResFrame(const std::string& filename, int width, int height)
{
DONUT_INFO("Exporting high-resolution frame: {}x{} to {}", width, height, filename);
-
+
if (width <= 0 || height <= 0)
{
DONUT_ERROR("Invalid dimensions for export: {}x{}", width, height);
return;
}
-
+
if (filename.empty())
{
DONUT_ERROR("Invalid filename for export");
return;
}
-
+
int originalWidth = m_Width;
int originalHeight = m_Height;
int originalComputeHeight = m_ComputeHeight;
-
+
m_Width = width;
m_Height = height;
m_ComputeHeight = height;
-
+
int computeHeight = height;
int computeWidth = (width * computeHeight) / height;
-
+
if (computeWidth <= 0 || computeHeight <= 0)
{
DONUT_ERROR("Invalid compute dimensions: {}x{}", computeWidth, computeHeight);
return;
}
-
+
FramebufferSpecification fbSpec;
fbSpec.Width = width;
fbSpec.Height = height;
fbSpec.Attachments = { FramebufferTextureFormat::RGBA8 };
-
+
auto highResFramebuffer = Framebuffer::Create(fbSpec);
if (!highResFramebuffer)
{
DONUT_ERROR("Failed to create high-resolution framebuffer");
return;
}
-
+
auto highResTexture = Texture2D::Create(computeWidth, computeHeight);
if (!highResTexture)
{
@@ -567,18 +567,18 @@ namespace Donut
m_ShaderProgram->Bind();
m_QuadVAO->Bind();
-
+
highResTexture->Bind(0);
m_ShaderProgram->SetInt("u_ScreenTexture", 0);
-
+
RenderCommand::DisableDepthTest();
RenderCommand::DrawArrays(6);
RenderCommand::EnableDepthTest();
-
+
std::vector<unsigned char> pixels(width * height * 4);
DONUT_INFO("Reading {} pixels from framebuffer...", width * height);
RenderCommand::ReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
-
+
DONUT_INFO("Flipping image vertically...");
std::vector<unsigned char> flippedPixels(width * height * 4);
for (int y = 0; y < height; ++y)
@@ -593,22 +593,22 @@ namespace Donut
flippedPixels[dstIndex + 3] = pixels[srcIndex + 3]; // A
}
}
-
+
DONUT_INFO("Saving PNG file: {}...", filename);
int result = stbi_write_png(filename.c_str(), width, height, 4, flippedPixels.data(), width * 4);
-
+
if (result)
DONUT_INFO("Successfully exported high-resolution frame to: {}", filename);
else
DONUT_ERROR("Failed to export high-resolution frame to: {}", filename);
-
+
highResFramebuffer->Unbind();
-
+
m_Width = originalWidth;
m_Height = originalHeight;
m_ComputeHeight = originalComputeHeight;
-
+
RenderCommand::SetViewport(0, 0, originalWidth, originalHeight);
}
-
+
}