diff --git a/Editor/Editor/Editor.cpp b/Editor/Editor/Editor.cpp index 3b6af77..b6e5e9c 100644 --- a/Editor/Editor/Editor.cpp +++ b/Editor/Editor/Editor.cpp @@ -7,126 +7,9 @@ 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); - } - */ - - EditorApplication::EditorApplication(const std::string& p_DebugName) : ApplicationInstance(p_DebugName) { GlobalUpdateManager::GetInstance()->SubscribeApplicationUpdate(this, &EditorApplication::OnApplicationUpdate); - // Ref m_CubeMesh = CreateCubeMesh({.0f, .0f, .0f}); - - - // 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); - - // ConsoleLogError("m_SceneGameObjects.size() === {}", m_SceneGameObjects.size()); m_EditorScene = new EditorScene(); - - - // m_GravitySystem = GravityPhysicsSystem(0.81f); - // m_SquareMesh = CreateSquareMesh({0.5f, 0.5f}); - - // //! @note Create Physics Circle Mesh - // m_CircleMesh = CreateCircleMesh(64); - - // // Creating a red circle. - // auto red = SceneObject::Create(); - // red.GetTransform().scale = glm::vec2{.05f}; - // red.GetTransform().Translation = {.5f, .5f}; - // red.SetColor({1.f, 0.f, 0.f}); - // red.RigidBodyComponent.velocity = {-.5f, .0f}; - // red.SetModel(m_CircleMesh); - - // m_SceneGameObjects.push_back(red); - - // //! @note Creating a blue circle. - // auto blue = SceneObject::Create(); - // blue.GetTransform().scale = glm::vec2{.05f}; - // blue.GetTransform().Translation = {-.45f, -.25f}; - // blue.SetColor({0.f, 0.f, 1.f}); - // blue.RigidBodyComponent.velocity = {-.5f, .0f}; - // blue.SetModel(m_CircleMesh); - - // m_SceneGameObjects.push_back(blue); - - - // // create vector field - // // std::vector vectorField{}; - // int gridCount = 40; - // for (int i = 0; i < gridCount; i++) { - // for (int j = 0; j < gridCount; j++) { - // auto vf = SceneObject::Create(); - // vf.GetTransform().scale = glm::vec2(0.005f); - // vf.GetTransform().Translation = { - // -1.0f + (i + 0.5f) * 2.0f / gridCount, - // -1.0f + (j + 0.5f) * 2.0f / gridCount}; - // vf.SetColor(glm::vec3(1.0f)); - // // vf.model = m_SquareMesh; - // vf.SetModel(m_SquareMesh); - // m_VectorFields.push_back(vf); - // } - // } } EditorApplication::~EditorApplication() { @@ -134,17 +17,8 @@ namespace engine3d{ void EditorApplication::OnApplicationUpdate(){ //! @note Handle Events. - // m_GravitySystem.update(m_SceneGameObjects, 5); - // m_VectorFieldSystem.update(m_GravitySystem, m_SceneGameObjects, m_VectorFields); auto& objects = m_EditorScene->GetSceneObjects(); Renderer::RecordSceneGameObjects(objects); - // Renderer::RecordGameObjects(m_SceneGameObjects); - // Renderer::RecordGameObjects(m_VectorFields); - - - // if(InputPoll::IsKeyPressed(ENGINE_KEY_ESCAPE)){ - // exit(0); - // } } ApplicationInstance* InitializeApplication(){ diff --git a/Editor/Editor/EditorScene.cpp b/Editor/Editor/EditorScene.cpp index 8c9bc1c..e81cfe4 100644 --- a/Editor/Editor/EditorScene.cpp +++ b/Editor/Editor/EditorScene.cpp @@ -78,10 +78,6 @@ namespace engine3d{ //! @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); diff --git a/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp b/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp index 99e21b6..91e7e6b 100644 --- a/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp +++ b/engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp @@ -89,6 +89,11 @@ namespace engine3d m_ParentScene == other.m_ParentScene; } + glm::vec3 GetRotation(); + void SetRotation(const glm::vec3& p_Rotation); + + void SetPosition(const glm::vec3& p_Position); + bool operator!=(const SceneObject &other) const { return !(*this == other); } UUID GetUUID() { return objectID; } diff --git a/src/engine3d/Core/Renderer/Renderer.cpp b/src/engine3d/Core/Renderer/Renderer.cpp index 02e0de6..8686a4b 100644 --- a/src/engine3d/Core/Renderer/Renderer.cpp +++ b/src/engine3d/Core/Renderer/Renderer.cpp @@ -26,11 +26,10 @@ namespace engine3d{ static VkPipelineLayout g_PipelineLayout; static VkPipeline g_Pipeline; - // static std::vector g_GameObjects; - + //! @note Push Constants to apply data to the shaders. + //! @note vk::VulkanModal is how shaders are going to be struct SimplePushConstantData{ glm::mat4 Transform{1.f}; - // glm::vec2 Offsets; glm::vec2 iResolution; alignas(16) glm::vec3 Color; }; @@ -57,8 +56,6 @@ namespace engine3d{ .flags = 0, .setLayoutCount = 0, .pSetLayouts = nullptr, - // .pushConstantRangeCount = 0, - // .pPushConstantRanges = nullptr, .pushConstantRangeCount = 1, .pPushConstantRanges = &push_const_range }; @@ -77,9 +74,6 @@ namespace engine3d{ ConsoleLogError("NOT AN ERROR: Shader Loaded Successfully!"); - - - //! @note Initializing Command buffers. g_CommandBuffers.resize(ApplicationInstance::GetWindow().GetCurrentSwapchain()->GetImagesSize()); @@ -105,41 +99,6 @@ namespace engine3d{ vk::vk_check(vkAllocateCommandBuffers(vk::VulkanContext::GetDriver(), &cmd_buffer_alloc_info, g_CommandBuffers.data()), "vkAllocateCommandBuffers", __FILE__, __LINE__, __FUNCTION__); ConsoleLogInfo("CommandBuffers Size === {}", g_CommandBuffers.size()); - - //-------------------------------------------- - //! @note Loading Game Objectts Here - //-------------------------------------------- - // std::vector triangle_vertices = { - // {.Position={0.0f, -0.5f}, .Color = {1.0f, 0.0f, 0.0f}}, - // {.Position ={0.5f, 0.5f}, .Color = {0.0f, 1.0f, 0.0f}}, - // {.Position ={-0.5f, 0.5f}, .Color = {0.0f, 0.0f, 1.0f}} - // }; - // // vk::VulkanModel model = vk::VulkanModel(triangle_vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - // auto model = CreateRef(triangle_vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - // auto triangle = SceneObject::Create(); - // triangle.SetModel(model); - - // //! @note Push Constants is pretty much how we can modify data without needing to record command buffers again. - - // // g_GameObjects.push_back(std::move(triangle)); - // std::vector colors{ - // {1.f, .7f, .73f}, - // {1.f, .87f, .73f}, - // {1.f, 1.f, .73f}, - // {.73f, 1.f, .8f}, - // {.73, .88f, 1.f} // - // }; - - //! @note Loading 40 triangles. - // for(int i = 0; i < 40; i++){ - // auto triangle = SceneObject::Create(); - // triangle.SetModel(model); - // triangle.m_Transform2D.scale = glm::vec2(.5f) + i * 0.0025f; - // triangle.m_Transform2D.rotation = glm::pi() * .00002f; - // triangle.SetColor(colors[i % colors.size()]); - // g_GameObjects.push_back(triangle); - // } - } void Renderer::SetBackgroundColor(const std::array& p_Rgba){ @@ -178,47 +137,6 @@ namespace engine3d{ return cmd_buffer; } - void Renderer::RecordCommandBuffers(VkCommandBuffer p_CommandBuffer){ - //! @note We can probably add this into Shader::Bind() - //! @note Usage: m_Shader.Bind(m_CommandBuffers[i]); - /* - int i = 0; - for(auto& obj : g_GameObjects){ - i += 1; - obj.m_Transform2D.rotation = glm::mod(obj.m_Transform2D.rotation + 0.001f * i, 2.f * glm::pi()); - } - - - //! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i]) - //! @note Starts when to start rendering!! - vkCmdBindPipeline(p_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Shader->GetGraphicsPipeline()); - - //! @note Only for testing purposes for mesh data. - for(auto& obj : g_GameObjects){ - obj.m_Transform2D.rotation = glm::mod(obj.GetTransform().rotation + 0.001f, glm::two_pi()); - - SimplePushConstantData push = { - .Transform = obj.GetTransform().mat2(), - // .Transform = glm::mod(obj.GetTransform().rotation * 0.1f, glm::two_pi()), - .Offsets = obj.GetTransform().Translation, - .Color = obj.GetColor(), - }; - vkCmdPushConstants( - p_CommandBuffer, - g_PipelineLayout, - VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, - 0, - sizeof(SimplePushConstantData), - &push - ); - - obj.GetModel()->Bind(p_CommandBuffer); - obj.GetModel()->Draw(p_CommandBuffer); - } - - */ - } - void Renderer::RecordGameObjects(std::vector& p_Objects){ auto current_cmd_buffer = GetCurrentCommandBuffer(); //! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i]) @@ -257,6 +175,10 @@ namespace engine3d{ //! @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()); + float x = obj->GetRotation().x; + float y = glm::mod(obj->GetRotation().y + 0.001f, glm::two_pi()); + float z = obj->GetRotation().z; + obj->SetRotation({x, y, z}); SimplePushConstantData push = { // .Transform = obj.GetTransform().mat4(), diff --git a/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp b/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp index e2afe6f..f3e0e2a 100644 --- a/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp +++ b/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp @@ -1,29 +1,35 @@ #include #include -#include "EngineLogger.hpp" namespace engine3d { SceneObject::SceneObject(entt::entity handle, Scene *scene) : 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) { m_ParentScene = scene; SceneObjectHandler = scene->m_SceneRegistry.create(); - ConsoleLogInfo("Entity Registered"); AddComponent(); } + void SceneObject::SetPosition(const glm::vec3& p_Position){ + SceneGetComponent().m_Position = p_Position; + } + + void SceneObject::SetRotation(const glm::vec3& p_Rotation){ + SceneGetComponent().m_AxisRotation = p_Rotation; + } + + glm::vec3 SceneObject::GetRotation(){ + return SceneGetComponent().m_AxisRotation; + } + 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});