From 97573bc91b861f1008633e74eda7942c756f633b Mon Sep 17 00:00:00 2001 From: SpinnerX Date: Thu, 21 Nov 2024 01:35:15 -0800 Subject: [PATCH] Working EditorScene to test the ECS and custom Scene objects intsead of the ones from the tutorials --- Editor/CMakeLists.txt | 3 + Editor/Editor/Editor.cpp | 76 +++-------- Editor/Editor/Editor.hpp | 94 ++----------- .../Editor/EditorComponents/EditorCamera.cpp | 128 ++++++++++++++++++ .../Editor/EditorComponents/EditorCamera.hpp | 74 ++++++++++ Editor/Editor/EditorScene.cpp | 96 +++++++++++++ Editor/Editor/EditorScene.hpp | 19 +++ TestApp/Application.cpp | 2 +- TestApp/CMakeLists.txt | 75 +++------- .../Components/Bodies/BodyContainer.hpp | 0 .../Components/Bodies/Shapes/BoxShaper.hpp | 0 .../Components/Bodies/Shapes/SphereShaper.hpp | 0 .../Components/Physics/PhysicsBody3D.hpp | 0 .../Scenes/Assets/Components/testComp.hpp | 0 .../SceneInstances/ShowCaseSceneInstance.hpp | 8 +- .../Components/Bodies/BodyContainer.cpp | 0 .../Components/Bodies/Shapes/BoxShaper.cpp | 0 .../Components/Bodies/Shapes/SphereShaper.cpp | 0 .../Components/Physics/PhysicsBody3D.cpp | 3 +- .../src/Scenes/Assets/Components/testComp.cpp | 2 +- .../SceneInstances/ShowCaseSceneInstance.cpp | 2 +- engine3d/Core/ApplicationManager/Scene.hpp | 1 + engine3d/Core/Renderer/Renderer.hpp | 6 +- engine3d/Core/Scene/SceneObject.hpp | 11 -- engine3d/Core/Scene/SceneTest.hpp | 120 ++++++++++++++++ .../Components/GameComponent.hpp | 3 +- .../SceneObjects/SceneObject.hpp | 17 +++ .../Vulkan2Showcase/VulkanImGuiLayer.hpp | 10 ++ src/engine3d/Core/Renderer/Renderer.cpp | 32 ++++- .../SceneObjects/SceneObject.cpp | 14 ++ .../Vulkan2Showcase/VulkanImGuiLayer.cpp | 71 ++++++++++ 31 files changed, 647 insertions(+), 220 deletions(-) create mode 100644 Editor/Editor/EditorComponents/EditorCamera.cpp create mode 100644 Editor/Editor/EditorComponents/EditorCamera.hpp create mode 100644 Editor/Editor/EditorScene.cpp create mode 100644 Editor/Editor/EditorScene.hpp rename TestApp/{SceneTest => }/Scenes/Assets/Components/Bodies/BodyContainer.hpp (100%) rename TestApp/{SceneTest => }/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp (100%) rename TestApp/{SceneTest => }/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp (100%) rename TestApp/{SceneTest => }/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp (100%) rename TestApp/{SceneTest => }/Scenes/Assets/Components/testComp.hpp (100%) rename TestApp/{SceneTest => }/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp (74%) rename TestApp/{SceneTest => }/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp (100%) rename TestApp/{SceneTest => }/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp (100%) rename TestApp/{SceneTest => }/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp (100%) rename TestApp/{SceneTest => }/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp (96%) rename TestApp/{SceneTest => }/src/Scenes/Assets/Components/testComp.cpp (94%) rename TestApp/{SceneTest => }/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp (93%) create mode 100644 engine3d/Core/Scene/SceneTest.hpp create mode 100644 engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.hpp create mode 100644 src/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.cpp diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 8f1e0b9..40c9ba7 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -11,5 +11,8 @@ build_demos( SOURCES Editor/Editor.hpp Editor/Editor.cpp + + Editor/EditorScene.hpp + Editor/EditorScene.cpp LINK_LIBRARIES engine3d ) diff --git a/Editor/Editor/Editor.cpp b/Editor/Editor/Editor.cpp index a4182e9..3b6af77 100644 --- a/Editor/Editor/Editor.cpp +++ b/Editor/Editor/Editor.cpp @@ -1,55 +1,14 @@ #include "Editor.hpp" -#include -#include "Core/Renderer/Renderer.hpp" -#include "Core/Scene/SceneObject.hpp" -// #include "internal/VulkanCpp/helper_functions.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "EditorScene.hpp" +#include +#include +#include +#include namespace engine3d{ - /* - Ref CreateSquareMesh(glm::vec2 offset) { - std::vector vertices = { - {{-0.5f, -0.5f}}, - {{0.5f, 0.5f}}, - {{-0.5f, 0.5f}}, - {{-0.5f, -0.5f}}, - {{0.5f, -0.5f}}, - {{0.5f, 0.5f}}, // - }; - for (auto& v : vertices) { - v.Position += offset; - } - return CreateRef(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - } - - Ref CreateCircleMesh(unsigned int numSides) { - std::vector uniqueVertices{}; - for (int i = 0; i < numSides; i++) { - float angle = i * glm::two_pi() / numSides; - uniqueVertices.push_back({{glm::cos(angle), glm::sin(angle)}}); - } - uniqueVertices.push_back({}); // adds center vertex at 0, 0 - - std::vector vertices{}; - for (int i = 0; i < numSides; i++) { - vertices.push_back(uniqueVertices[i]); - vertices.push_back(uniqueVertices[(i + 1) % numSides]); - vertices.push_back(uniqueVertices[numSides]); - } - return CreateRef(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - } - - */ + + /* Ref CreateCubeMesh(glm::vec3 offset){ std::vector vertices{ // left face (white) @@ -106,22 +65,23 @@ namespace engine3d{ } return CreateRef(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); } + */ EditorApplication::EditorApplication(const std::string& p_DebugName) : ApplicationInstance(p_DebugName) { GlobalUpdateManager::GetInstance()->SubscribeApplicationUpdate(this, &EditorApplication::OnApplicationUpdate); - m_CubeMesh = CreateCubeMesh({.0f, .0f, .0f}); + // Ref m_CubeMesh = CreateCubeMesh({.0f, .0f, .0f}); - auto cube = SceneObject::Create(); - cube.SetModel(m_CubeMesh); - cube.GetTransform().Translation = {.0f, .0f, .5f}; - cube.GetTransform().scale = {.5f, .5f, .5f}; + // auto cube = SceneObjectTutorial::Create(); + // cube.SetModel(m_CubeMesh); + // cube.GetTransform().Translation = {.0f, .0f, .5f}; + // cube.GetTransform().scale = {.5f, .5f, .5f}; - m_SceneGameObjects.push_back(cube); + // m_SceneGameObjects.push_back(cube); - ConsoleLogError("m_SceneGameObjects.size() === {}", m_SceneGameObjects.size()); - + // ConsoleLogError("m_SceneGameObjects.size() === {}", m_SceneGameObjects.size()); + m_EditorScene = new EditorScene(); // m_GravitySystem = GravityPhysicsSystem(0.81f); @@ -176,7 +136,9 @@ namespace engine3d{ //! @note Handle Events. // m_GravitySystem.update(m_SceneGameObjects, 5); // m_VectorFieldSystem.update(m_GravitySystem, m_SceneGameObjects, m_VectorFields); - Renderer::RecordGameObjects(m_SceneGameObjects); + auto& objects = m_EditorScene->GetSceneObjects(); + Renderer::RecordSceneGameObjects(objects); + // Renderer::RecordGameObjects(m_SceneGameObjects); // Renderer::RecordGameObjects(m_VectorFields); diff --git a/Editor/Editor/Editor.hpp b/Editor/Editor/Editor.hpp index 807526c..2c3c9ff 100644 --- a/Editor/Editor/Editor.hpp +++ b/Editor/Editor/Editor.hpp @@ -1,85 +1,11 @@ #pragma once -#include "Core/internal/Vulkan2Showcase/VulkanModel.hpp" +// #include #include -#include -#include +// #include +// #include +#include "EditorScene.hpp" namespace engine3d{ - - /* - class GravityPhysicsSystem{ - public: - GravityPhysicsSystem() = default; - GravityPhysicsSystem(float strength) : m_Strength(strength){} - - void update(std::vector& p_Objects, unsigned int substeps = 1){ - const float step_data = SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime / substeps; - - for(int i = 0; i < substeps; i++){ - step_simulation(p_Objects, step_data); - } - } - - glm::vec2 ComputeForce(SceneObject& p_FromObject, SceneObject& p_ToObject) const{ - auto offset = p_FromObject.GetTransform().Translation - p_ToObject.GetTransform().Translation; - float dist_squared = glm::dot(offset, offset); - - if(glm::abs(dist_squared) < 1e-10f){ - return {.0f, .0f}; - } - - float force = m_Strength * p_ToObject.RigidBodyComponent.mass * p_FromObject.RigidBodyComponent.mass / dist_squared; - return force * offset / glm::sqrt(dist_squared); - } - - private: - void step_simulation(std::vector& physicsObjs, float dt){ - - // Loops through all pairs of objects and applies attractive force between them - for (auto iterA = physicsObjs.begin(); iterA != physicsObjs.end(); ++iterA) { - auto& objA = *iterA; - for (auto iterB = iterA; iterB != physicsObjs.end(); ++iterB) { - if (iterA == iterB) continue; - auto& objB = *iterB; - - auto force = ComputeForce(objA, objB); - objA.RigidBodyComponent.velocity += dt * -force / objA.RigidBodyComponent.mass; - objB.RigidBodyComponent.velocity += dt * force / objB.RigidBodyComponent.mass; - } - } - - // update each objects position based on its final velocity - for (auto& obj : physicsObjs) { - obj.GetTransform().Translation += dt * obj.RigidBodyComponent.velocity; - } - } - - private: - float m_Strength; - }; - - class Vec2FieldSystem{ - public: - Vec2FieldSystem() = default; - - void update(const GravityPhysicsSystem& physicsSystem, std::vector& physicsObjs, std::vector& vectorField){ - // For each field line we caluclate the net graviation force for that point in space - for (auto& vf : vectorField) { - glm::vec2 direction{}; - - for (auto& obj : physicsObjs) { - direction += physicsSystem.ComputeForce(obj, vf); - } - - // This scales the length of the field line based on the log of the length - // values were chosen just through trial and error based on what i liked the look - // of and then the field line is rotated to point in the direction of the field - vf.GetTransform().scale.x = 0.005f + 0.045f * glm::clamp(glm::log(glm::length(direction) + 1) / 3.f, 0.f, 1.f); - vf.GetTransform().rotation = atan2(direction.y, direction.x); - } - } - }; - */ //! @note Our actual editor application //! @note TODO -- Having a cenrtal application that will be used across both editor and the game(being developed) @@ -96,15 +22,15 @@ namespace engine3d{ void OnApplicationUpdate(); private: - Ref m_SquareMesh; - Ref m_CircleMesh; - - std::vector m_SceneGameObjects; - std::vector m_VectorFields; + // Ref m_SquareMesh; + // Ref m_CircleMesh; + EditorScene* m_EditorScene; + // std::vector m_SceneGameObjects; + // std::vector m_VectorFields; // GravityPhysicsSystem m_GravitySystem; // Vec2FieldSystem m_VectorFieldSystem; - Ref m_CubeMesh; + // Ref m_CubeMesh; diff --git a/Editor/Editor/EditorComponents/EditorCamera.cpp b/Editor/Editor/EditorComponents/EditorCamera.cpp new file mode 100644 index 0000000..81fce9f --- /dev/null +++ b/Editor/Editor/EditorComponents/EditorCamera.cpp @@ -0,0 +1,128 @@ +#include "EditorCamera.hpp" +#include "Event/InputPoll.hpp" +#include "TimeManagement/UpdateManagers/SyncUpdateManager.hpp" +#include +#include +#include + +#define GLM_ENABLE_EXPERIMENTAL +#include + +#include +#include +#include + +namespace engine3d{ + EditorCamera::EditorCamera(const std::string& p_Tag) : m_Tag(p_Tag) {} + + void EditorCamera::OnIntegrate(float p_Fov, float p_NearClip, float p_FarClip){ + m_Fov = p_Fov; + m_AspectRatio = ((float)ApplicationInstance::GetWindow().GetWidth() / (float)ApplicationInstance::GetWindow().GetHeight()); + m_NearClip = p_NearClip; + m_FarClip = p_FarClip; + + m_ViewportSize.x = (float)ApplicationInstance::GetWindow().GetWidth(); + m_ViewportSize.y = (float)ApplicationInstance::GetWindow().GetHeight(); + + RecalculateView(); + } + + void EditorCamera::OnUpdate(){ + if(InputPoll::IsKeyPressed(ENGINE_KEY_LEFT_ALT)){ + glm::vec2 delta = (InputPoll::GetMousePosition() - m_InitialMousePosition) * 0.003f; + m_InitialMousePosition = InputPoll::GetMousePosition(); + + if(InputPoll::IsMousePressed(Mouse::ButtonMiddle)){ + CameraPan(delta); + } + else if(InputPoll::IsMousePressed(Mouse::ButtonLast)){ + CameraRotate(delta); + } + else if(InputPoll::IsMousePressed(Mouse::ButtonRight)){ + CameraZoom(delta.y); + } + } + + RecalculateView(); + } + + glm::quat EditorCamera::GetOrientation() const { + return glm::quat(glm::vec3(-m_Pitch, -m_Yaw, 1.0f)); + } + + glm::vec3 EditorCamera::GetUpDirection() const{ + return glm::rotate(GetOrientation(), glm::vec3{0.0f, 1.0f, 0.0f}); + } + + glm::vec3 EditorCamera::GetRightDirection() const { + return glm::rotate(GetOrientation(), glm::vec3(1.0f, 0.0f, 0.0f)); + } + + glm::vec3 EditorCamera::GetForwardDirection() const { + return glm::rotate(GetOrientation(), glm::vec3(0.0f, 0.0f, -1.0f)); + } + + + //! @note Getting pans. + void EditorCamera::CameraPan(const glm::vec2& p_Data){} + + void EditorCamera::CameraZoom(float delta) { + // float dt = SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime; + m_Distance -= (delta * ZoomSpeed()); + + if(m_Distance < 1.0f){ + m_FocalPoint += GetForwardDirection(); + m_Distance = 1.0f; + } + } + + void EditorCamera::CameraRotate(const glm::vec2& p_Position) { + float yawSign = GetUpDirection().y < 0 ? -1.0f : 1.0f; + m_Yaw += yawSign * p_Position.x * RotationSpeed(); + m_Pitch += p_Position.y * RotationSpeed(); + } + + float EditorCamera::RotationSpeed() const { + return 0.8f; + } + + glm::vec3 EditorCamera::CalculateNewPosition() const{ + return m_FocalPoint - GetForwardDirection() * m_Distance; + } + + float EditorCamera::ZoomSpeed() const{ + float distance = m_Distance * 0.2f; + distance = std::max(distance, 0.0f); + + float speed = distance * distance; + speed = std::min(speed, 100.0f); + return speed; + } + + void EditorCamera::RecalculateProjection() { + m_ProjectionMatrix = glm::perspective(glm::radians(m_Fov), m_AspectRatio, m_NearClip, m_FarClip); + RecalculateView(); + } + + void EditorCamera::RecalculateView() { + m_Position = CalculateNewPosition(); + glm::quat orientation = GetOrientation(); + m_ViewMatrix = glm::translate(glm::mat4(1.0f), m_Position) * glm::toMat4(orientation); + m_ViewMatrix = glm::inverse(m_ViewMatrix); + } + + glm::vec3 EditorCamera::RecalculatePosition() const { + return m_FocalPoint * GetForwardDirection() * m_Distance; + + } + + glm::vec2 EditorCamera::PanSpeed() const{ + float x = std::min(m_ViewportSize.x / 1000.0f, 2.4f); // max = 2.4.f + float xFactor = 0.0366f * (x * x) - 0.1778f * x + 0.3021f; + + float y = std::min(m_ViewportSize.y / 1000.0f, 2.4f); // max = 2.4f + float yFactor = 0.0366f * (y * y) - 0.1778f * y + 0.3021f; + + return {xFactor, yFactor}; + } +}; \ No newline at end of file diff --git a/Editor/Editor/EditorComponents/EditorCamera.hpp b/Editor/Editor/EditorComponents/EditorCamera.hpp new file mode 100644 index 0000000..4934b9f --- /dev/null +++ b/Editor/Editor/EditorComponents/EditorCamera.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include + +namespace engine3d{ + class EditorCamera : public GameComponent{ + public: + struct CameraData{ + float PerspectiveFOV = glm::radians(45.0f); + float PerspectiveNear = 0.01; + float PerspectiveFar = 1000.0f; + float OrthographicSize = 10.0f; + float OrthographicNear = 1.0f; + float OrthographicFar = 1.0f; + }; + + enum CameraProjectionType{ + UNDEFINED = -1, + ORTHOGRAPHIC = 0, + PERSPECTIVE = 1 + }; + + + EditorCamera() = default; + EditorCamera(const std::string& p_Tag); + + void OnUpdate(); + + //! @note Eventually we will refer to OnIntegrate as OnCreate or OnPlay or something. + //! @note Come up with a better name for this for accurate API. + void OnIntegrate(float p_Fov, float p_NearClip, float p_FarClip); + + glm::quat GetOrientation() const; + glm::vec3 GetUpDirection() const; + glm::vec3 GetRightDirection() const; + glm::vec3 GetForwardDirection() const; + + + //! @note Getting pans. + void CameraPan(const glm::vec2& p_Data); + void CameraZoom(float delta); + void CameraRotate(const glm::vec2& p_Data); + + private: + glm::vec3 CalculateNewPosition() const; + void RecalculateView(); + + void RecalculateProjection(); + + glm::vec3 RecalculatePosition() const; + + glm::vec2 PanSpeed() const; + float ZoomSpeed() const; + + float RotationSpeed() const; + + private: + std::string m_Tag; + glm::vec2 m_InitialMousePosition = {0.0f, 0.0f}; + float m_Fov = 45.0f, m_AspectRatio = 1.778f, m_NearClip=0.1f, m_FarClip = 1000.0f; + + glm::mat4 m_ViewMatrix; + glm::mat4 m_ProjectionMatrix; + glm::vec3 m_Position; + glm::vec3 m_FocalPoint; + //! @note Moving this out of Editor Camera. + // glm::vec2 m_InitialMousePosition + float m_Distance = 10.0f; + float m_Pitch = 0.f, m_Yaw = 0.f; + glm::vec2 m_ViewportSize; + + }; +}; \ No newline at end of file diff --git a/Editor/Editor/EditorScene.cpp b/Editor/Editor/EditorScene.cpp new file mode 100644 index 0000000..8c9bc1c --- /dev/null +++ b/Editor/Editor/EditorScene.cpp @@ -0,0 +1,96 @@ +#include "EditorScene.hpp" +#include +#include +#include + +namespace engine3d{ + Ref CreateCubeMesh(glm::vec3 offset){ + std::vector vertices{ + // left face (white) + {{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}}, + {{-.5f, .5f, .5f}, {.9f, .9f, .9f}}, + {{-.5f, -.5f, .5f}, {.9f, .9f, .9f}}, + {{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}}, + {{-.5f, .5f, -.5f}, {.9f, .9f, .9f}}, + {{-.5f, .5f, .5f}, {.9f, .9f, .9f}}, + + // right face (yellow) + {{.5f, -.5f, -.5f}, {.8f, .8f, .1f}}, + {{.5f, .5f, .5f}, {.8f, .8f, .1f}}, + {{.5f, -.5f, .5f}, {.8f, .8f, .1f}}, + {{.5f, -.5f, -.5f}, {.8f, .8f, .1f}}, + {{.5f, .5f, -.5f}, {.8f, .8f, .1f}}, + {{.5f, .5f, .5f}, {.8f, .8f, .1f}}, + + // top face (orange, remember y axis points down) + {{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}}, + {{.5f, -.5f, .5f}, {.9f, .6f, .1f}}, + {{-.5f, -.5f, .5f}, {.9f, .6f, .1f}}, + {{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}}, + {{.5f, -.5f, -.5f}, {.9f, .6f, .1f}}, + {{.5f, -.5f, .5f}, {.9f, .6f, .1f}}, + + // bottom face (red) + {{-.5f, .5f, -.5f}, {.8f, .1f, .1f}}, + {{.5f, .5f, .5f}, {.8f, .1f, .1f}}, + {{-.5f, .5f, .5f}, {.8f, .1f, .1f}}, + {{-.5f, .5f, -.5f}, {.8f, .1f, .1f}}, + {{.5f, .5f, -.5f}, {.8f, .1f, .1f}}, + {{.5f, .5f, .5f}, {.8f, .1f, .1f}}, + + // nose face (blue) + {{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}}, + {{.5f, .5f, 0.5f}, {.1f, .1f, .8f}}, + {{-.5f, .5f, 0.5f}, {.1f, .1f, .8f}}, + {{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}}, + {{.5f, -.5f, 0.5f}, {.1f, .1f, .8f}}, + {{.5f, .5f, 0.5f}, {.1f, .1f, .8f}}, + + // tail face (green) + {{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}}, + {{.5f, .5f, -0.5f}, {.1f, .8f, .1f}}, + {{-.5f, .5f, -0.5f}, {.1f, .8f, .1f}}, + {{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}}, + {{.5f, -.5f, -0.5f}, {.1f, .8f, .1f}}, + {{.5f, .5f, -0.5f}, {.1f, .8f, .1f}}, + }; + + for (auto& v : vertices) { + v.Position += offset; + } + return CreateRef(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + } + + + EditorScene::EditorScene(){ + m_Scene = new Scene(); + + auto cube_mesh = CreateCubeMesh({.0f, .0f, .0f}); + + //! @note Make this scene object as part of our current scene. + // SceneObject* cube = new SceneObject(m_Scene); + SceneObject* cube = new SceneObject(m_Scene); + // auto cube = SceneObject::Create(); + // cube.SetModel(m_CubeMesh); + // cube.GetTransform().Translation = {.0f, .0f, .5f}; + // cube.GetTransform().scale = {.5f, .5f, .5f}; + + //! @note Setting our properties + auto& transform = cube->SceneGetComponent(); + + if(cube->HasComponent()){ + ConsoleLogInfo("Transform Component found!"); + } + + transform.m_Position = {.0f, .0f, .5f}; + transform.m_Scale = {.5f, .5f, .5f}; + // cube->SetModel(cube_mesh); + cube->SetModal(cube_mesh); + + //! @note Then we add them to our vector. + m_SceneObjects.push_back(cube); + } + + void EditorScene::OnCreate(){ + } +}; \ No newline at end of file diff --git a/Editor/Editor/EditorScene.hpp b/Editor/Editor/EditorScene.hpp new file mode 100644 index 0000000..3adb2c0 --- /dev/null +++ b/Editor/Editor/EditorScene.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include + +namespace engine3d{ + class EditorScene{ + public: + EditorScene(); + + void OnCreate(); + + std::vector& GetSceneObjects() { return m_SceneObjects; } + + private: + std::vector m_SceneObjects; + Scene* m_Scene; + }; +}; \ No newline at end of file diff --git a/TestApp/Application.cpp b/TestApp/Application.cpp index d04d8eb..b1cf406 100644 --- a/TestApp/Application.cpp +++ b/TestApp/Application.cpp @@ -1,6 +1,6 @@ #include "Core/EngineLogger.hpp" #include -#include "SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp" +#include "Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp" #include namespace engine3d{ diff --git a/TestApp/CMakeLists.txt b/TestApp/CMakeLists.txt index dd1246f..d1505bb 100644 --- a/TestApp/CMakeLists.txt +++ b/TestApp/CMakeLists.txt @@ -1,80 +1,37 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.25) project(TestApp CXX) -# find_package(Vulkan REQUIRED) +set(SCENE_TEST_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/SceneTest) -# find_package(engine3d CONFIG REQUIRED) build_demos( SOURCES Application.cpp #To Test - SceneTest/Scenes/Assets/Components/testComp.hpp - SceneTest/src/Scenes/Assets/Components/testComp.cpp + Scenes/Assets/Components/testComp.hpp + src/Scenes/Assets/Components/testComp.cpp #Physics - SceneTest/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp - SceneTest/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp + Scenes/Assets/Components/Physics/PhysicsBody3D.hpp + src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp - SceneTest/Scenes/Assets/Components/Bodies/BodyContainer.hpp - SceneTest/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp + Scenes/Assets/Components/Bodies/BodyContainer.hpp + src/Scenes/Assets/Components/Bodies/BodyContainer.cpp #Body Shapes - SceneTest/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp - SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp + Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp + src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp - SceneTest/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp - SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp + Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp + src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp #Scenes - SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp - SceneTest/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp + Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp + src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp LINK_LIBRARIES engine3d ) -target_include_directories(${PROJECT_NAME} PUBLIC SceneTest) -target_include_directories(${PROJECT_NAME} PRIVATE ../) - -# target_compile_definitions(${PROJECT_NAME} PRIVATE ${dev_definitions}) - -# find_package(OpenGL REQUIRED) -# find_package(glfw3 REQUIRED) - -# find_package(Vulkan REQUIRED) -# find_package(VulkanHeaders REQUIRED) - -# if(LINUX) -# find_package(VulkanLoader REQUIRED) -# endif(LINUX) - -# # target_include_directories(${PROJECT_NAME} PUBLIC ${ENGINE_INCLUDE_DIR}) -# target_include_directories(${PROJECT_NAME} PRIVATE ../) -# find_package(glm REQUIRED) -# find_package(fmt REQUIRED) -# find_package(spdlog REQUIRED) -# find_package(yaml-cpp REQUIRED) -# find_package(imguidocking REQUIRED) -# find_package(box2d REQUIRED) -# find_package(joltphysics REQUIRED) -# find_package(EnTT REQUIRED) - - -# target_link_libraries( -# ${PROJECT_NAME} -# PRIVATE -# glfw -# ${OPENGL_LIBRARIES} -# Vulkan::Vulkan -# vulkan-headers::vulkan-headers -# glm::glm -# fmt::fmt -# spdlog::spdlog -# yaml-cpp::yaml-cpp -# imguidocking::imguidocking -# box2d::box2d -# Jolt::Jolt -# EnTT::EnTT -# engine3d -# ) \ No newline at end of file +# target_include_directories(${PROJECT_NAME} PUBLIC ${SCENE_TEST_INCLUDE_DIR}) +target_include_directories(${PROJECT_NAME} PUBLIC ./ ../) \ No newline at end of file diff --git a/TestApp/SceneTest/Scenes/Assets/Components/Bodies/BodyContainer.hpp b/TestApp/Scenes/Assets/Components/Bodies/BodyContainer.hpp similarity index 100% rename from TestApp/SceneTest/Scenes/Assets/Components/Bodies/BodyContainer.hpp rename to TestApp/Scenes/Assets/Components/Bodies/BodyContainer.hpp diff --git a/TestApp/SceneTest/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp b/TestApp/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp similarity index 100% rename from TestApp/SceneTest/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp rename to TestApp/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp diff --git a/TestApp/SceneTest/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp b/TestApp/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp similarity index 100% rename from TestApp/SceneTest/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp rename to TestApp/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp diff --git a/TestApp/SceneTest/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp b/TestApp/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp similarity index 100% rename from TestApp/SceneTest/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp rename to TestApp/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp diff --git a/TestApp/SceneTest/Scenes/Assets/Components/testComp.hpp b/TestApp/Scenes/Assets/Components/testComp.hpp similarity index 100% rename from TestApp/SceneTest/Scenes/Assets/Components/testComp.hpp rename to TestApp/Scenes/Assets/Components/testComp.hpp diff --git a/TestApp/SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp b/TestApp/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp similarity index 74% rename from TestApp/SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp rename to TestApp/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp index 2195ca0..5572927 100644 --- a/TestApp/SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp +++ b/TestApp/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp @@ -1,5 +1,11 @@ #include "Core/ApplicationManager/Scene.hpp" -#include "Core/SceneManagment/SceneObjects/SceneObject.hpp" +// #include "Core/SceneManagment/SceneObjects/SceneObject.hpp" + + +namespace engine3d{ + class SceneObject; +}; + class ShowCaseSceneInstance { public: diff --git a/TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp b/TestApp/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp similarity index 100% rename from TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp rename to TestApp/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp diff --git a/TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp b/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp similarity index 100% rename from TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp rename to TestApp/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp diff --git a/TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp b/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp similarity index 100% rename from TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp rename to TestApp/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp diff --git a/TestApp/SceneTest/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp b/TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp similarity index 96% rename from TestApp/SceneTest/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp rename to TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp index 3701bd8..e5bfc6b 100644 --- a/TestApp/SceneTest/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp +++ b/TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp @@ -30,7 +30,8 @@ void PhysicsBody3D::OnIntegrate() void PhysicsBody3D::Begin() { m_interface = engine3d::JoltHandler::GetInstance()->getInterface(); - m_Transform = &m_GameObjectRef->SceneGetComponent(); + // m_Transform = &m_GameObjectRef->SceneGetComponent(); + // m_Transform = m_GameObjectRef } void PhysicsBody3D::Update() diff --git a/TestApp/SceneTest/src/Scenes/Assets/Components/testComp.cpp b/TestApp/src/Scenes/Assets/Components/testComp.cpp similarity index 94% rename from TestApp/SceneTest/src/Scenes/Assets/Components/testComp.cpp rename to TestApp/src/Scenes/Assets/Components/testComp.cpp index 91a6bc4..1afa5bd 100644 --- a/TestApp/SceneTest/src/Scenes/Assets/Components/testComp.cpp +++ b/TestApp/src/Scenes/Assets/Components/testComp.cpp @@ -21,7 +21,7 @@ using namespace engine3d; (this, &testComp::PhysicsUpdate); // Need an activation and start funciton - m_rb = m_GameObjectRef->SceneGetComponent().GetBody(); + // m_rb = m_GameObjectRef->SceneGetComponent().GetBody(); } diff --git a/TestApp/SceneTest/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp b/TestApp/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp similarity index 93% rename from TestApp/SceneTest/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp rename to TestApp/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp index 1e2706e..603a92b 100644 --- a/TestApp/SceneTest/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp +++ b/TestApp/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp @@ -4,7 +4,7 @@ #include "Scenes/Assets/Components/testComp.hpp" #include #include -#include +#include ShowCaseSceneInstance::ShowCaseSceneInstance() { diff --git a/engine3d/Core/ApplicationManager/Scene.hpp b/engine3d/Core/ApplicationManager/Scene.hpp index 5515d32..7034996 100644 --- a/engine3d/Core/ApplicationManager/Scene.hpp +++ b/engine3d/Core/ApplicationManager/Scene.hpp @@ -2,6 +2,7 @@ #include namespace engine3d { + //! @note TODO: Move this into Core/Scene/ directory. Not in Application Manager. class Scene { public: entt::registry m_SceneRegistry; diff --git a/engine3d/Core/Renderer/Renderer.hpp b/engine3d/Core/Renderer/Renderer.hpp index 0defaf7..7a51c4d 100644 --- a/engine3d/Core/Renderer/Renderer.hpp +++ b/engine3d/Core/Renderer/Renderer.hpp @@ -1,10 +1,11 @@ #pragma once +#include +#include #include #include #include #include #include -#include namespace engine3d{ class Renderer{ @@ -16,7 +17,8 @@ namespace engine3d{ //! @note Currently the record command buffers just does what "simple_render_system.hpp/.cpp" does already //! @note In the future I'll add API's for submitting draw calls. static void RecordCommandBuffers(VkCommandBuffer p_CommandBuffer); - static void RecordGameObjects(std::vector& p_Objects); + static void RecordGameObjects(std::vector& p_Objects); + static void RecordSceneGameObjects(std::vector& p_SceneObjects); static void EndFrame(); template diff --git a/engine3d/Core/Scene/SceneObject.hpp b/engine3d/Core/Scene/SceneObject.hpp index 96c8969..ddc20b9 100644 --- a/engine3d/Core/Scene/SceneObject.hpp +++ b/engine3d/Core/Scene/SceneObject.hpp @@ -16,17 +16,6 @@ namespace engine3d{ glm::vec3 scale = {1.f, 1.f, 1.f}; glm::vec3 rotation; - // glm::mat2 mat2() { - // const float s = glm::sin(rotation); - // const float c = glm::cos(rotation); - // glm::mat2 rotation_mat = {{c, s}, {-s, c}}; - - // glm::mat2 scale_mat{{scale.x, .0f}, {.0f, scale.y}}; - // // return glm::mat2{1.f}; - // // return scale_mat; - // return rotation_mat * scale_mat; - // } - glm::mat4 mat4(){ auto transform = glm::translate(glm::mat4{1.f}, Translation); transform = glm::rotate(transform, rotation.y, {0.f, 1.f, 0.f}); diff --git a/engine3d/Core/Scene/SceneTest.hpp b/engine3d/Core/Scene/SceneTest.hpp new file mode 100644 index 0000000..3d4f7d3 --- /dev/null +++ b/engine3d/Core/Scene/SceneTest.hpp @@ -0,0 +1,120 @@ +#pragma once +#include +#include +#include + +#define GLM_FORCE_RADIANS +#define GLM_FORCE_DEPTH_ZERO_TO_ONE +#include +#include +#include + +// #include + +namespace engine3d{ + + //! @note Defines what our scene objects'll be. + class SceneObjectTutorial{ + using id_t = unsigned int; + public: + //! @note Creating a transform component for our scene object + struct Transform2DComponent{ + glm::vec3 Position{}; + glm::vec3 scale = {1.f, 1.f, 1.f}; + glm::vec3 rotation; + + glm::mat4 mat4(){ + auto transform = glm::translate(glm::mat4{1.f}, Position); + transform = glm::rotate(transform, rotation.y, {0.f, 1.f, 0.f}); + transform = glm::rotate(transform, rotation.x, {1.f, 0.f, 0.f}); + transform = glm::rotate(transform, rotation.z, {0.f, 0.f, 1.f}); + + transform = glm::scale(transform, scale); + return transform; + } + }; + + struct RigidBody2dComponent { + glm::vec2 velocity; + float mass{1.0f}; + }; + static SceneObjectTutorial Create(); + + id_t GetID() const { return m_Id; } + + void SetModel(Ref& p_Model){ + m_Model = p_Model; + } + + void SetRotation(glm::vec3& p_Rotation){ + m_Transform2D.rotation = p_Rotation; + } + + void SetColor(glm::vec3 p_Color){ + m_Color = p_Color; + } + + void SetTranslation(Transform2DComponent p_Transformation){ + m_Transform2D = p_Transformation; + } + + Ref& GetModel() { return m_Model; } + glm::vec3 GetColor() { return m_Color; } + Transform2DComponent& GetTransform() { return m_Transform2D; } + + Transform2DComponent m_Transform2D; + RigidBody2dComponent RigidBodyComponent; + + private: + SceneObjectTutorial(id_t p_Id); + + private: + Ref m_Model; + glm::vec3 m_Color; + + id_t m_Id; + }; + + // class SceneObjectTutorial2{ + // using id_t = unsigned int; + // public: + // static SceneObjectTutorial2 Create(Scene* p_Scene); + + // id_t GetID() const { return m_Id; } + + // void SetModel(Ref& p_Model){ + // m_Model = p_Model; + // } + + // void SetRotation(glm::vec3& p_Rotation){ + // m_Transform2D.rotation = p_Rotation; + // } + + // void SetColor(glm::vec3 p_Color){ + // m_Color = p_Color; + // } + + // void SetTranslation(Transform2DComponent p_Transformation){ + // m_Transform2D = p_Transformation; + // } + + // Ref& GetModel() { return m_Model; } + // glm::vec3 GetColor() { return m_Color; } + // Transform2DComponent& GetTransform() { return m_Transform2D; } + + // Transform2DComponent m_Transform2D; + // RigidBody2dComponent RigidBodyComponent; + + + + + // private: + // SceneObjectTutorial2(id_t p_Id, Scene* p_Scene); + + // private: + // Ref m_Model; + // glm::vec3 m_Color; + // Scene* m_Scene; + // id_t m_Id; + // }; +}; \ No newline at end of file diff --git a/engine3d/Core/SceneManagment/Components/GameComponent.hpp b/engine3d/Core/SceneManagment/Components/GameComponent.hpp index f846f05..3fe4dcb 100644 --- a/engine3d/Core/SceneManagment/Components/GameComponent.hpp +++ b/engine3d/Core/SceneManagment/Components/GameComponent.hpp @@ -1,10 +1,11 @@ #pragma once -#include +// #include #include namespace engine3d { + class SceneObject; class GameComponent { public: diff --git a/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp b/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp index 9a179c8..99e21b6 100644 --- a/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp +++ b/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp @@ -5,11 +5,19 @@ * @param id - the ID of the SceneObject itself * @note actual wrapper for SceneObject for ECS * */ +#include #include #include + #include #include +#define GLM_FORCE_RADIANS +#define GLM_FORCE_DEPTH_ZERO_TO_ONE +#include +#include +#include + namespace engine3d { class SceneObject @@ -61,6 +69,14 @@ namespace engine3d m_ParentScene->m_SceneRegistry.remove(SceneObjectHandler); } + void SetModal(Ref& p_Model){ + m_Model = p_Model; + } + + glm::mat4 toMat4(); + + Ref& GetModel() { return m_Model; } + operator bool() const { return SceneObjectHandler != entt::null; } operator entt::entity() const { return SceneObjectHandler; } @@ -81,5 +97,6 @@ namespace engine3d entt::entity SceneObjectHandler{entt::null}; UUID objectID; Scene *m_ParentScene = nullptr; // 12 bytes + Ref m_Model; }; }; // namespace Engine3D diff --git a/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.hpp b/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.hpp new file mode 100644 index 0000000..417a202 --- /dev/null +++ b/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace engine3d::vk{ + class VulkanImGuiLayer{ + public: + static void Initialize(); + static void BeginFrame(); + static void EndFrame(); + }; +}; \ No newline at end of file diff --git a/src/engine3d/Core/Renderer/Renderer.cpp b/src/engine3d/Core/Renderer/Renderer.cpp index 5268400..02e0de6 100644 --- a/src/engine3d/Core/Renderer/Renderer.cpp +++ b/src/engine3d/Core/Renderer/Renderer.cpp @@ -219,7 +219,7 @@ namespace engine3d{ */ } - void Renderer::RecordGameObjects(std::vector& p_Objects){ + void Renderer::RecordGameObjects(std::vector& p_Objects){ auto current_cmd_buffer = GetCurrentCommandBuffer(); //! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i]) //! @note Starts when to start rendering!! @@ -248,6 +248,36 @@ namespace engine3d{ } } + void Renderer::RecordSceneGameObjects(std::vector& p_Objects){ + auto current_cmd_buffer = GetCurrentCommandBuffer(); + //! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i]) + //! @note Starts when to start rendering!! + vkCmdBindPipeline(current_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Shader->GetGraphicsPipeline()); + + //! @note Only for testing purposes for mesh data. + for(auto& obj : p_Objects){ + // obj.m_Transform2D.rotation.y = glm::mod(obj.GetTransform().rotation.y + 0.001f, glm::two_pi()); + + SimplePushConstantData push = { + // .Transform = obj.GetTransform().mat4(), + .Transform = obj->toMat4(), + .iResolution = {ApplicationInstance::GetWindow().GetWidth(), ApplicationInstance::GetWindow().GetHeight()}, + // .Color = obj.GetColor(), + }; + vkCmdPushConstants( + current_cmd_buffer, + g_PipelineLayout, + VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, + 0, + sizeof(SimplePushConstantData), + &push + ); + + obj->GetModel()->Bind(current_cmd_buffer); + obj->GetModel()->Draw(current_cmd_buffer); + } + } + void Renderer::EndFrame(){ auto cmd_buffer = GetCurrentCommandBuffer(); vkCmdEndRenderPass(cmd_buffer); diff --git a/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp b/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp index 415077a..e2afe6f 100644 --- a/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp +++ b/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp @@ -7,6 +7,8 @@ namespace engine3d { : SceneObjectHandler(handle), m_ParentScene(scene) { AddComponent(); + auto transform_component = SceneGetComponent(); + ConsoleLogInfo("(Init) transform_component.m_Position = ({}, {}, {})", transform_component.m_Position.x, transform_component.m_Position.y, transform_component.m_Position.z); } SceneObject::SceneObject(Scene *scene) @@ -16,4 +18,16 @@ namespace engine3d { ConsoleLogInfo("Entity Registered"); AddComponent(); } + + glm::mat4 SceneObject::toMat4(){ + auto transform_component = SceneGetComponent(); + + ConsoleLogInfo("(toMat4) transform_component.m_Position = ({}, {}, {})", transform_component.m_Position.x, transform_component.m_Position.y, transform_component.m_Position.z); + + auto transform = glm::translate(glm::mat4{1.f}, transform_component.m_Position); + transform = glm::rotate(transform, transform_component.m_AxisRotation.y, {0.f, 1.f, 0.f}); + transform = glm::rotate(transform, transform_component.m_AxisRotation.x, {1.f, 0.f, 0.f}); + transform = glm::rotate(transform, transform_component.m_AxisRotation.z, {0.f, 0.f, 1.f}); + return transform; + } }; // namespace Engine3D diff --git a/src/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.cpp b/src/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.cpp new file mode 100644 index 0000000..e3cefea --- /dev/null +++ b/src/engine3d/Core/internal/Vulkan2Showcase/VulkanImGuiLayer.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace engine3d::vk{ + void VulkanImGuiLayer::Initialize() { + ConsoleLogInfo("Vulkan2Showcase: Begin Initializing VulkanImGuiLayer!!!"); + //! @note Setting up imgui stuff. + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows + //io.ConfigViewportsNoAutoMerge = true; + //io.ConfigViewportsNoTaskBarIcon = true; + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); + + ImGuiStyle& style = ImGui::GetStyle(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + style.WindowRounding = 0.0f; + style.Colors[ImGuiCol_WindowBg].w = 1.0f; + } + + // Setup Platform/Renderer backends + // ImGui_ImplGlfw_InitForVulkan(ApplicationInstance::GetWindow().GetNativeWindow(), true); + ImGui_ImplGlfw_InitForVulkan(ApplicationInstance::GetWindow().GetNativeWindow(), true); + ImGui_ImplVulkan_InitInfo init_info = {}; + init_info.Instance = VulkanContext::GetVkInstance(); + init_info.PhysicalDevice = VulkanContext::GetPhysicalDriver(); + init_info.Device = VulkanContext::GetDriver(); + init_info.QueueFamily = VulkanContext::GetPhysicalDriver().GetQueueIndices().Graphics; + init_info.Queue = VK_NULL_HANDLE; + init_info.PipelineCache = VK_NULL_HANDLE; + init_info.DescriptorPool = VK_NULL_HANDLE; + init_info.Subpass = 0; + init_info.MinImageCount = 2; + init_info.ImageCount = ApplicationInstance::GetWindow().GetCurrentSwapchain()->GetImagesSize(); + init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT; + init_info.Allocator = nullptr; + // init_info.CheckVkResultFn = check_vk_result; + // ImGui_ImplVulkan_Init(&init_info); + ImGui_ImplGlfw_InitForVulkan(ApplicationInstance::GetWindow().GetNativeWindow(), false); + + // Load default font + ImFontConfig fontConfig; + fontConfig.FontDataOwnedByAtlas = false; + // ImFont* robotoFont = io.Fonts->AddFontFromMemoryTTF((void*)g_RobotoRegular, sizeof(g_RobotoRegular), 20.0f, &fontConfig); + // io.FontDefault = robotoFont; + + ConsoleLogWarn("Vulkan2Showcase: Finished Initializing VulkanImGuiLayer!!!!"); + } + + void VulkanImGuiLayer::BeginFrame() { + + } + + void VulkanImGuiLayer::EndFrame() { + + } +}; \ No newline at end of file