From 64171da71a8042a3e9364edfa9a9194753cdd5e1 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Fri, 17 Nov 2023 15:26:10 +0530 Subject: [PATCH] store maincamera entity and rework base level setup --- include/NazaraEditor/Core/Application/BaseApplication.hpp | 3 +++ src/NazaraEditor/Core/Application/BaseApplication.cpp | 6 +++--- src/NazaraEditor/Editor/Application.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp index 23bd9f6..334e01a 100644 --- a/include/NazaraEditor/Core/Application/BaseApplication.hpp +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -76,6 +76,8 @@ namespace Nz OnActionRegistered(properties); } + inline entt::handle GetMainCamera() { return m_mainCamera; } + private: static EditorBaseApplication* s_instance; @@ -88,5 +90,6 @@ namespace Nz Nz::EditorLogger* m_logger; Nz::Level m_level; + entt::handle m_mainCamera; }; } \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp index 00a885d..27af225 100644 --- a/src/NazaraEditor/Core/Application/BaseApplication.cpp +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -84,9 +84,9 @@ namespace Nz if (bRes) { // configure camera - auto camera = CreateEntity("Camera"); - auto& cmp = camera.get(); - //cmp.SetFlags(EditorEntityFlags_Hidden); + m_mainCamera = CreateEntity("MainCamera"); + auto& cmp = m_mainCamera.get(); + cmp.SetFlags(EditorEntityFlags_Hidden); auto& cameraComponent = camera.emplace(m_windowSwapchain.get(), Nz::ProjectionType::Perspective); cameraComponent.UpdateFOV(70.f); diff --git a/src/NazaraEditor/Editor/Application.cpp b/src/NazaraEditor/Editor/Application.cpp index 24ce8cf..4b982f7 100644 --- a/src/NazaraEditor/Editor/Application.cpp +++ b/src/NazaraEditor/Editor/Application.cpp @@ -41,10 +41,12 @@ namespace NzEditor auto directional = CreateEntity("SunLight"); Nz::LightComponent& lightComponent = directional.emplace(); Nz::DirectionalLight& light = lightComponent.AddLight(); - light.UpdateRotation(Nz::EulerAnglesf(-45.f, 0.f, 0.f)); + light.UpdateRotation(Nz::Quaternionf::LookAt(Nz::Vector3f(-1, 0, -1), Nz::Vector3f::Up())); + light.EnableShadowCasting(true); } { auto cube = CreateEntity("Cube"); + cube.get().SetPosition(Nz::Vector3f(0, 0, 0)); Nz::GraphicsComponent& graphicsComponent = cube.emplace(); std::shared_ptr boxMesh = Nz::GraphicalMesh::Build(Nz::Primitive::Box(Nz::Vector3f(1.f), Nz::Vector3ui::Zero(), Nz::Matrix4f::Scale(Nz::Vector3f(1.f)), Nz::Rectf(0.f, 0.f, 2.f, 2.f))); @@ -55,6 +57,10 @@ namespace NzEditor boxModel->SetMaterial(0, std::move(boxMat)); graphicsComponent.AttachRenderable(boxModel); } + + GetMainCamera().get().SetPosition(-5, 0, 0); + GetMainCamera().get().SetRotation(Nz::Quaternionf::LookAt(Nz::Vector3f(1, 0, 0), Nz::Vector3f::Up())); + return true; } } \ No newline at end of file