hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/engine/engine.h
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/engine/engine.h
parent3d8d3259e1cf5a7d88e5d1e530cc8c9bf9140734 (diff)
feat: complete first geodesic 3D raytracing
Diffstat (limited to 'src/engine/engine.h')
-rw-r--r--src/engine/engine.h87
1 files changed, 46 insertions, 41 deletions
diff --git a/src/engine/engine.h b/src/engine/engine.h
index 6f90efb..39791c1 100644
--- a/src/engine/engine.h
+++ b/src/engine/engine.h
@@ -2,10 +2,6 @@
#include <vector>
#include <iostream>
-#include <GLFW/glfw3.h>
-#include <glm/glm.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/gtc/type_ptr.hpp>
#include <fstream>
#include <sstream>
#include <chrono>
@@ -15,16 +11,27 @@
#include "core/camera.h"
#include "rendering/renderer.h"
#include "rendering/shader.h"
-#include "rendering/texture.h"
#include "rendering/vertex_array.h"
+#include "rendering/texture.h"
#include "rendering/uniform_buffer.h"
+#include "rendering/texture_manager.h"
+
+#include <GLFW/glfw3.h>
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/type_ptr.hpp>
+
+#define _USE_MATH_DEFINES
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
namespace Donut
{
const double c = 299792458.0;
const double G = 6.67430e-11;
- struct BlackHole
+ struct BlackHole
{
glm::vec3 m_position;
double m_mass;
@@ -32,13 +39,12 @@ namespace Donut
double m_rs;
BlackHole(glm::vec3 pos, float mass)
- : m_position(pos),
- m_mass(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
+ 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);
@@ -48,11 +54,11 @@ namespace Donut
}
};
- struct ObjectData
+ struct ObjectData
{
glm::vec4 m_pos_radius;
glm::vec4 m_color;
- float m_mass;
+ float m_mass;
glm::vec3 m_velocity = glm::vec3(0.0f, 0.0f, 0.0f);
};
@@ -62,8 +68,6 @@ namespace Donut
Engine();
~Engine() = default;
- void generate_grid(const std::vector<ObjectData>& objects);
- void draw_grid(const glm::mat4& view_proj);
void draw_full_screen_quad();
void dispatch_compute(const Camera& cam);
void upload_camera_ubo(const Camera& cam);
@@ -73,46 +77,47 @@ namespace Donut
void update_physics(float delta_time);
void update_window_dimensions();
- Camera& get_camera() { return m_camera; }
- const Camera& get_camera() const { return m_camera; }
-
- const std::vector<ObjectData>& get_objects() const { return m_objects; }
- std::vector<ObjectData>& get_objects() { return m_objects; }
-
- bool get_gravity() const { return m_gravity; }
- void set_gravity(bool gravity) { m_gravity = gravity; }
-
- int get_width() const { return m_width; }
- int get_height() const { return m_height; }
- int get_compute_width() const { return m_compute_width; }
- int get_compute_height() const { return m_compute_height; }
+ int get_width() const { return m_width; }
+ int get_height() const { return m_height; }
+
+ std::vector<ObjectData>& get_objects() { return m_objects; }
+ BlackHole& get_sag_a() { return m_sag_a; }
+ Camera& get_camera() { return m_camera; }
+ bool& get_gravity() { return m_gravity; }
+ void update_performance(float delta_time);
+ void set_target_fps(int fps) { m_target_fps = fps; }
+ int get_target_fps() const { return m_target_fps; }
+ float get_current_fps() const { return m_current_fps; }
+ void set_compute_height(int height) { m_compute_height = height; }
+ int get_compute_height() const { return m_compute_height; }
+ int get_compute_width() const { return (m_width * m_compute_height) / m_height; }
+ void update_compute_dimensions();
private:
- std::string create_basic_vertex_shader();
- std::string create_basic_fragment_shader();
- std::string load_compute_shader(const std::string& path);
+ Ref<Shader> create_compute_program(const char* path);
+ std::pair<Ref<VertexArray>, Ref<Texture2D>> quad_vao();
private:
- Ref<Shader> m_grid_shader;
- Ref<Shader> m_quad_shader;
- Ref<Shader> m_compute_shader;
- Ref<Texture2D> m_texture;
Ref<VertexArray> m_quad_vao;
- Ref<VertexArray> m_grid_vao;
+ Ref<Texture2D> m_texture;
+ Ref<Shader> m_shader_program;
+ Ref<Shader> m_compute_program;
Ref<UniformBuffer> m_camera_ubo;
Ref<UniformBuffer> m_disk_ubo;
Ref<UniformBuffer> m_objects_ubo;
-
- int m_grid_index_count = 0;
+
int m_width;
int m_height;
- int m_compute_width;
- int m_compute_height;
- float m_width_scale = 100000000000.0f;
- float m_height_scale = 75000000000.0f;
+ float m_width_f = 100*10e10f;
+ float m_height_f = 75*10e10f;
+
+ int m_target_fps = 60;
+ float m_current_fps = 60.0f;
+ float m_last_frame_time = 0.0f;
+ int m_compute_height = 320;
std::vector<ObjectData> m_objects;
BlackHole m_sag_a;
Camera m_camera;
bool m_gravity = false;
};
-}
+};