editor camera!

This commit is contained in:
Erris
2026-02-21 01:11:24 +01:00
parent 02430073ec
commit cb064bdb46
10 changed files with 299 additions and 50 deletions

View File

@@ -3,12 +3,6 @@
#include <open_engine.hpp>
#include "open_engine/core.hpp"
#include "open_engine/events/event.hpp"
#include "open_engine/events/key_event.hpp"
#include "open_engine/logging.hpp"
#include "open_engine/math/math.hpp"
#include "open_engine/scene/components.hpp"
#include "panels/scene_hierarchy.hpp"
//#include <imfilebrowser.h>
@@ -75,6 +69,8 @@ namespace OpenEngine {
scene = CreateRef<Scene>();
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
scene_hierarchy.SetContext(scene);
}
@@ -86,23 +82,23 @@ namespace OpenEngine {
{
FramebufferSpecification spec = framebuffer->GetSpecification();
if (viewport_size.x > 0.0f && viewport_size.y > 0.0f &&
(spec.width != viewport_size.x || spec.height != viewport_size.y))
{
framebuffer->Resize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
}
{
(spec.width != viewport_size.x || spec.height != viewport_size.y)) {
OE_PROFILE_SCOPE("Setting up Rendering");
framebuffer->Bind();
framebuffer->Resize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
editor_camera.SetViewportSize(viewport_size.x, viewport_size.y);
scene->OnViewportResize((uint32_t)viewport_size.x, (uint32_t)viewport_size.y);
}
framebuffer->Bind();
Renderer2D::ResetStats();
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
RenderCommand::Clear();
scene->OnUpdate();
editor_camera.OnUpdate();
scene->OnUpdateEditor(editor_camera);
framebuffer->Unbind();
}
@@ -142,6 +138,8 @@ namespace OpenEngine {
{
OE_PROFILE_FUNCTION();
editor_camera.OnEvent(event);
EventDispatcher dispatcher(event);
dispatcher.Dispatch<KeyPressedEvent>(BIND_EVENT_FN(EditorLayer::EditorKeyBinds));
};
@@ -209,20 +207,6 @@ namespace OpenEngine {
int max_x = viewport_size.x + imgui_cursor_position.x;
int max_y = viewport_size.y + imgui_cursor_position.y;
if (focused || hovered) {
float x = mouse_position.x - imgui_cursor_position.x;
float y = mouse_position.y - imgui_cursor_position.y;
/*
auto& cam = camera.GetCamera();
world_pos_cursor = ScreenToWorld(x, y, 0.0f,
cam.GetViewMatrix(),
cam.GetProjectionMatrix(),
viewport_size.x,
viewport_size.y);
*/
}
uint32_t texture_id = framebuffer->GetColorAttachmentRendererID();
ImGui::Image((void*)(uint64_t)texture_id, ImVec2{ viewport_size.x, viewport_size.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 });
@@ -248,8 +232,8 @@ namespace OpenEngine {
ImGui::Text("Renderer2D:");
ImGui::Text("\t\tDraw calls: %d", stats.draw_calls);
ImGui::Text("\t\tQuad count: %d", stats.quad_count);
ImGui::Text("\t\tVertices count: %d", stats.GetToralVertexCount());
ImGui::Text("\t\tIndices count: %d", stats.GetToralIndexCount());
ImGui::Text("\t\tVertices count: %d", stats.GetTotalVertexCount());
ImGui::Text("\t\tIndices count: %d", stats.GetTotalIndexCount());
/*
for (auto& result : profiling_results)
@@ -287,10 +271,12 @@ namespace OpenEngine {
auto window_size = ImGui::GetWindowSize();
ImGuizmo::SetRect(window_position.x, window_position.y, window_size.x, window_size.y);
auto camera_entity = scene->GetPrimaryCamera();
auto camera = camera_entity.GetComponents<CameraComponent>().camera;
const glm::mat4& projection = camera.GetProjection();
glm::mat4 camera_view = glm::inverse(camera_entity.GetComponents<TransformComponent>().GetTransform());
//auto camera_entity = scene->GetPrimaryCamera();
//auto camera = camera_entity.GetComponents<CameraComponent>().camera;
//const glm::mat4& projection = camera.GetProjection();
//glm::mat4 camera_view = glm::inverse(camera_entity.GetComponents<TransformComponent>().GetTransform());
const glm::mat4& camera_projection = editor_camera.GetProjection();
glm::mat4 camera_view = editor_camera.GetViewMatrix();
auto& transform_comp = selected_entity.GetComponents<TransformComponent>();
glm::mat4 transform = transform_comp.GetTransform();
@@ -302,7 +288,7 @@ namespace OpenEngine {
float snap_values[] = { snap_value, snap_value, snap_value };
ImGuizmo::Manipulate(glm::value_ptr(camera_view), glm::value_ptr(projection),
ImGuizmo::Manipulate(glm::value_ptr(camera_view), glm::value_ptr(camera_projection),
(ImGuizmo::OPERATION)guizmo_operation, ImGuizmo::LOCAL,
glm::value_ptr(transform), nullptr,
snap ? snap_values : nullptr);
@@ -390,7 +376,7 @@ namespace OpenEngine {
SceneHierarchy scene_hierarchy;
Entity camera_bis;
EditorCamera editor_camera;
int guizmo_operation = -1;