diff --git a/Editor/Editor/EditorScene.cpp b/Editor/Editor/EditorScene.cpp index 8addfd2..f450010 100644 --- a/Editor/Editor/EditorScene.cpp +++ b/Editor/Editor/EditorScene.cpp @@ -1,5 +1,6 @@ #include "EditorScene.hpp" #include "Core/GraphicDrivers/VertexBuffer.hpp" +#include "Math/Math.hpp" #include #include #include @@ -7,6 +8,7 @@ #include #include #include +#include namespace engine3d{ EditorScene::EditorScene(){ @@ -17,7 +19,10 @@ namespace engine3d{ // auto cube_mesh = CreateCubeMesh({.0f, .0f, .0f}); //! @note Instead of loading in primitive cubes by hand, we load in .obj's instead. - auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/smooth_vase.obj"); + // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/smooth_vase.obj"); + // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/FinalBaseMesh.obj"); + // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/Castelia City.obj"); + auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/bugatti.obj"); // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/colored_cube.obj"); // auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/sphere.obj"); //! @note Make this scene object as part of our current scene. @@ -29,6 +34,7 @@ namespace engine3d{ m_CameraObject->AddComponent(); auto& camera_transform = m_CameraObject->SceneGetComponent(); camera_transform.m_Position = {-1.f, -2.f, -20.f}; + // camera_transform.m_AxisRotation = {glm::radians(180.0f), 0.f, 0.f}; auto camera = m_CameraObject->SceneGetComponent(); m_CameraObjects.push_back(m_CameraObject); @@ -39,7 +45,9 @@ namespace engine3d{ SceneObject* cube1 = new SceneObject(m_Scene); auto& cube1_transform = cube1->SceneGetComponent(); cube1_transform.m_Position = {.0f, .0f, 2.5}; - cube1_transform.m_Scale = {10.5f, 10.5f, 10.5}; + cube1_transform.m_Scale = {.5f, .5f, .5f}; + // cube1_transform.m_AxisRotation = ToQuat(glm::vec3(glm::radians(180.0f), 0.f, 0.f)); + cube1_transform.m_AxisRotation = {glm::radians(180.0f), 0.0f, 0.0f}; cube1->SetMesh(cube_mesh); // ----------------------------- @@ -63,7 +71,7 @@ namespace engine3d{ //! @note Then we add them to our vector. m_SceneObjects.push_back(cube1); - m_SceneObjects.push_back(cube2); + // m_SceneObjects.push_back(cube2); m_PointLightObjects.push_back(sphere_point_light); m_AllSceneObjecs.insert({"SceneObjects", m_SceneObjects}); @@ -82,7 +90,7 @@ namespace engine3d{ // float tempDt_Y; glm::vec2 temp_position = {0.f, 0.f}; constexpr float sensitivity = 2.0f; - constexpr float pos_sensitivity = 2.f; + float pos_sensitivity = 2.f; constexpr glm::vec2 invert_pos = {1, -1}; glm::vec3 rotate{0}; @@ -116,8 +124,12 @@ namespace engine3d{ if(InputPoll::IsKeyPressed(ENGINE_KEY_S)) move_dir -= forward_dir; // BACKWARD if(InputPoll::IsKeyPressed(ENGINE_KEY_D)) move_dir += right_dir; // RIGHT if(InputPoll::IsKeyPressed(ENGINE_KEY_A)) move_dir -= right_dir; // LEFT - if(InputPoll::IsKeyPressed(ENGINE_KEY_E)) move_dir += up_dir; // UP - if(InputPoll::IsKeyPressed(ENGINE_KEY_Q)) move_dir -= up_dir; // DOWN + if(InputPoll::IsKeyPressed(ENGINE_KEY_SPACE)) move_dir += up_dir; // UP + if(InputPoll::IsKeyPressed(ENGINE_KEY_LEFT_SHIFT)) move_dir -= up_dir; // DOWN + + if(InputPoll::IsMousePressed(ENGINE_MOUSE_BUTTON_MIDDLE)){ + pos_sensitivity += (m_MousePosition.y - InputPoll::GetMouseY()) * invert_pos.x; + } if(glm::dot(move_dir, move_dir) > std::numeric_limits::epsilon()){ transform.m_Position += m_MoveSpeed * (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * glm::normalize(move_dir) * pos_sensitivity; @@ -126,7 +138,7 @@ namespace engine3d{ camera.SetViewXYZ(transform.m_Position, transform.m_AxisRotation); - camera.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 100.f); + camera.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 1000.f); } }; \ No newline at end of file diff --git a/Editor/Editor/EditorScene.hpp b/Editor/Editor/EditorScene.hpp index b7f3fc7..6c15b84 100644 --- a/Editor/Editor/EditorScene.hpp +++ b/Editor/Editor/EditorScene.hpp @@ -34,7 +34,7 @@ namespace engine3d{ Scene* m_Scene; // SceneObject* m_CameraObject; glm::vec2 m_MousePosition; - float m_MoveSpeed = {3.f}; + float m_MoveSpeed = {5.f}; float m_LookSpeed = {1.5f}; }; }; \ No newline at end of file diff --git a/engine3d/Math/Math.hpp b/engine3d/Math/Math.hpp new file mode 100644 index 0000000..91f7996 --- /dev/null +++ b/engine3d/Math/Math.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +#define GLM_ENABLE_EXPERIMENTAL +#include + +namespace engine3d{ + // glm::quat ToQuat() + glm::vec4 ToQuat(glm::vec3 p_EulerAngles); +}; \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c4cdcf..63ed852 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -118,6 +118,7 @@ add_library( ${ENGINE_SRC_DIR}/Core/Renderer/Renderer.cpp ${ENGINE_SRC_DIR}/Math/Interpolation.cpp + ${ENGINE_SRC_DIR}/Math/Math.cpp ${ENGINE_SRC_DIR}/Physics/JoltHandler.cpp ) \ No newline at end of file diff --git a/src/engine3d/Core/ApplicationInstance.cpp b/src/engine3d/Core/ApplicationInstance.cpp index 2cdbd5f..f9d1d62 100644 --- a/src/engine3d/Core/ApplicationInstance.cpp +++ b/src/engine3d/Core/ApplicationInstance.cpp @@ -20,7 +20,7 @@ namespace engine3d{ g_ThisInstance = this; g_DebugName = p_DebugName; SetCurrentAPI(VULKAN); - m_Window = Window::Create(900, 600, p_DebugName); + m_Window = Window::Create(1960, 1080, p_DebugName); // ImGui_ImplVulkanH_Window(); // ImGui_ImplGlfw_InitForVulkan(ApplicationInstance::GetWindow().GetNativeWindow(), true); diff --git a/src/engine3d/Core/Renderer/Renderer.cpp b/src/engine3d/Core/Renderer/Renderer.cpp index 0e87c42..aa38af3 100644 --- a/src/engine3d/Core/Renderer/Renderer.cpp +++ b/src/engine3d/Core/Renderer/Renderer.cpp @@ -243,7 +243,8 @@ namespace engine3d{ SimplePushConstantData push = { .Transform = proj_view * model_matrix, .ModelMatrix = model_matrix, - .LightTransform = position + .LightTransform = position - obj->SceneGetComponent().m_Position + // .LightTransform = position }; vkCmdPushConstants( diff --git a/src/engine3d/Math/Math.cpp b/src/engine3d/Math/Math.cpp new file mode 100644 index 0000000..730b012 --- /dev/null +++ b/src/engine3d/Math/Math.cpp @@ -0,0 +1,16 @@ +#include + +namespace engine3d{ + glm::vec4 ToQuat(glm::vec3 p_EulerAngles){ + glm::vec4 quaternion; + glm::vec3 c = glm::cos(p_EulerAngles * float(0.5)); + glm::vec3 s = glm::sin(p_EulerAngles * float(0.5)); + + quaternion.w = c.x * c.y * c.z + s.x * s.y * s.z; + quaternion.x = s.x * c.y * c.z - c.x * s.y * s.z; + quaternion.y = c.x * s.y * c.z + s.x * c.y * s.z; + quaternion.z = c.x * c.y * s.z - s.x * s.y * c.z; + + return quaternion; + } +}; \ No newline at end of file