setting up 3d

This commit is contained in:
Erris
2026-03-02 00:49:08 +01:00
parent 90a6ea00c0
commit 03bca252d3
6 changed files with 132 additions and 11 deletions

View File

@@ -31,6 +31,7 @@ namespace OpenEngine {
glm::vec3 GetForwardDirection() const;
const glm::vec3& GetPosition() const { return position; }
glm::quat GetOrientation() const;
void ResetMousePosition();
float GetPitch() const { return pitch; }
float GetYaw() const { return yaw; }
@@ -61,6 +62,7 @@ namespace OpenEngine {
glm::vec3 focal_point = { 0.0f, 0.0f, 0.0f };
glm::vec2 initial_mouse_position = { 0.0f, 0.0f };
bool mouse_button_was_pressed = false;
float distance = 10.0f;
float pitch = 0.0f, yaw = 0.0f;

View File

@@ -1,4 +1,3 @@
#include "logging.hpp"
#include <pch.hpp>
#include <renderer/editor_camera.hpp>
@@ -63,10 +62,11 @@ namespace OpenEngine {
void EditorCamera::OnUpdate()
{
if (Input::IsKeyPressed(Key::LeftAlt)) {
const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() };
glm::vec2 delta = (mouse - initial_mouse_position) * 0.003f;
initial_mouse_position = mouse;
const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() };
glm::vec2 delta = (mouse - initial_mouse_position) * 0.003f;
initial_mouse_position = mouse;
if (Input::IsMouseButtonPressed(Mouse::ButtonMiddle)) {
MousePan(delta);
@@ -151,4 +151,10 @@ namespace OpenEngine {
return glm::quat(glm::vec3(-pitch, -yaw, 0.0f));
}
void EditorCamera::ResetMousePosition()
{
initial_mouse_position = { Input::GetMouseX(), Input::GetMouseY() };
mouse_button_was_pressed = false;
}
}

View File

@@ -93,12 +93,19 @@ namespace OpenEngine {
};
std::vector<uint32_t> indices = {
0, 1, 2, 0, 2, 3, // back
4, 6, 5, 4, 7, 6, // front
8, 9, 10, 8, 10, 11, // left
12, 14, 13, 12, 15, 14, // right
16, 17, 18, 16, 18, 19, // top
20, 23, 22, 20, 22, 21, // bottom
// Back face (z=-0.5)
0, 1, 2, 0, 2, 3,
// Front face (z=0.5)
4, 6, 5, 4, 7, 6,
// Right face
12, 13, 14, 12, 14, 15,
// Left face
8, 10, 9, 8, 11, 10,
// Top face
18, 16, 17, 18, 19, 16,
// Bottom face
20, 22, 21, 20, 23, 22
// TODO: Missing backface
};
return CreateMesh(vertices, indices);
@@ -112,6 +119,7 @@ namespace OpenEngine {
struct CameraData
{
glm::mat4 view_projection;
glm::vec3 view_position;
};
CameraData camera_buffer;
Ref<UniformBuffer> camera_uniform_buffer;
@@ -130,6 +138,9 @@ namespace OpenEngine {
{
OE_PROFILE_FUNCTION();
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
renderer_data.color_shader_3d = Shader::Create("assets/shaders/color3d.glsl");
renderer_data.camera_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::CameraData), 0);
renderer_data.transform_uniform_buffer = UniformBuffer::Create(sizeof(Renderer3DData::TransformData), 1);
@@ -153,6 +164,8 @@ namespace OpenEngine {
OE_PROFILE_FUNCTION();
renderer_data.camera_buffer.view_projection = camera.GetProjection() * glm::inverse(transform);
renderer_data.camera_buffer.view_position = transform[3];
renderer_data.camera_uniform_buffer->SetData(&renderer_data.camera_buffer, sizeof(Renderer3DData::CameraData));
}
@@ -161,6 +174,8 @@ namespace OpenEngine {
OE_PROFILE_FUNCTION();
renderer_data.camera_buffer.view_projection = camera.GetViewProjection();
renderer_data.camera_buffer.view_position = camera.GetPosition();
renderer_data.camera_uniform_buffer->SetData(&renderer_data.camera_buffer, sizeof(Renderer3DData::CameraData));
}