From b5de81e1979854abeac8efa75b630306b700b16a Mon Sep 17 00:00:00 2001 From: Jennife Chukwu Date: Mon, 1 Sep 2025 22:07:38 +0100 Subject: [PATCH 1/2] another one --- .gitignore | 1 - .gitmodules | 3 - CMakeLists.txt | 1 - README.md | 1 - Scripts/BuildEngine.ps1 | 4 +- .../Components/HierarchyViewUIComponent.cpp | 10 +- .../Components/InspectorViewUIComponent.cpp | 101 +++++++------- .../Controllers/EditorCameraController.cpp | 4 +- Tetragrama/EditorScene.cpp | 9 +- .../Helpers/UIComponentDrawerHelper.cpp | 18 +-- Tetragrama/Helpers/UIComponentDrawerHelper.h | 14 +- .../ZEngine/Controllers/ICameraController.h | 12 +- .../PerspectiveCameraController.cpp | 10 +- .../Controllers/PerspectiveCameraController.h | 48 +++---- ZEngine/ZEngine/Core/Maths/MathUtils.h | 40 ++++++ ZEngine/ZEngine/Core/Maths/Matrix.h | 131 +++++++++++++++++- ZEngine/ZEngine/Core/Maths/Quaternion.h | 39 +++++- ZEngine/ZEngine/Core/Maths/Vec.h | 25 ++++ ZEngine/ZEngine/Helpers/Helper.cpp | 10 +- ZEngine/ZEngine/Helpers/MathHelper.h | 8 -- ZEngine/ZEngine/Importers/AssetTypes.h | 6 +- ZEngine/ZEngine/Importers/AssimpImporter.cpp | 25 ++-- ZEngine/ZEngine/Importers/AssimpImporter.h | 12 +- ZEngine/ZEngine/Importers/IAssetImporter.cpp | 5 +- ZEngine/ZEngine/Managers/AssetManager.cpp | 4 +- ZEngine/ZEngine/Maths/Math.cpp | 66 --------- ZEngine/ZEngine/Maths/Math.h | 30 ---- ZEngine/ZEngine/Rendering/Buffers/Bitmap.h | 88 ++++++------ ZEngine/ZEngine/Rendering/Cameras/Camera.h | 40 +++--- .../Rendering/Cameras/PerspectiveCamera.cpp | 58 ++++---- .../Rendering/Cameras/PerspectiveCamera.h | 55 ++++---- .../Rendering/Components/TransformComponent.h | 34 ++--- ZEngine/ZEngine/Rendering/GPUTypes.h | 16 +-- .../ZEngine/Rendering/Geometries/IGeometry.h | 8 +- .../Rendering/Materials/StandardMaterial.cpp | 11 +- .../Rendering/Materials/StandardMaterial.h | 40 +++--- ZEngine/ZEngine/Rendering/Meshes/MeshLight.h | 1 - .../Contracts/RendererDataContract.h | 10 +- .../Rendering/Renderers/GraphicRenderer.cpp | 3 +- .../Renderers/Storages/GraphicVertex.cpp | 20 +-- .../Renderers/Storages/GraphicVertex.h | 17 ++- .../Rendering/Renderers/Storages/IVertex.h | 8 +- .../ZEngine/Rendering/Scenes/GraphicScene.cpp | 12 +- .../ZEngine/Rendering/Scenes/GraphicScene.h | 17 +-- .../Serializers/GraphicScene3DSerializer.cpp | 12 +- .../Serializers/GraphicScene3DSerializer.h | 8 +- ZEngine/tests/Maths/Matrix_test.cpp | 72 ++++++++++ ZEngine/tests/Maths/Quaternion_test.cpp | 76 ++++++++++ ZEngine/tests/Memory/bitmap_test.cpp | 5 +- __externals/externals.cmake | 2 - __externals/glm | 1 - 51 files changed, 758 insertions(+), 493 deletions(-) delete mode 100644 ZEngine/ZEngine/Helpers/MathHelper.h delete mode 100644 ZEngine/ZEngine/Maths/Math.cpp delete mode 100644 ZEngine/ZEngine/Maths/Math.h delete mode 160000 __externals/glm diff --git a/.gitignore b/.gitignore index d8f12cb9..cc998b75 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,6 @@ bld/ # Submodules folder __externals/fmt -__externals/glm __externals/imgui/src __externals/imgui/src/examples/example_glfw_vulkan/out/ __externals/SDL2 diff --git a/.gitmodules b/.gitmodules index 2eaffaf6..1ab3bb18 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,9 +52,6 @@ [submodule "__externals/Vulkan-Loader"] path = __externals/Vulkan-Loader url = https://github.com/KhronosGroup/Vulkan-Loader -[submodule "__externals/glm"] - path = __externals/glm - url = https://github.com/g-truc/glm [submodule "__externals/Vulkan-Headers"] path = __externals/Vulkan-Headers url = https://github.com/KhronosGroup/Vulkan-Headers diff --git a/CMakeLists.txt b/CMakeLists.txt index 799b0d9e..575240c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ if (NOT LAUNCHER_ONLY) add_subdirectory (${EXTERNAL_DIR}/imgui) add_subdirectory (${EXTERNAL_DIR}/glfw) add_subdirectory (${EXTERNAL_DIR}/spdlog) - add_subdirectory (${EXTERNAL_DIR}/glm) add_subdirectory (${EXTERNAL_DIR}/entt) add_subdirectory (${EXTERNAL_DIR}/assimp) add_subdirectory (${EXTERNAL_DIR}/stduuid) diff --git a/README.md b/README.md index 0b326e35..3e243415 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,6 @@ See our roadmap here [Roadmap](Roadmap.md) The project uses the following dependencies as submodules : - [GLFW](https://github.com/glfw/glfw) for window creation and user input management for Windows, Linux, and MacOS, - - [GLM](https://glm.g-truc.net/0.9.9/index.html) for functions and mathematical calculations, - [STB](https://github.com/nothings/stb) for loading and manipulating image files for textures. - [ImGUI](https://github.com/ocornut/imgui) for GUI components and interaction. - [SPDLOG](https://github.com/gabime/spdlog) for logging diff --git a/Scripts/BuildEngine.ps1 b/Scripts/BuildEngine.ps1 index 557da5d9..3868c394 100644 --- a/Scripts/BuildEngine.ps1 +++ b/Scripts/BuildEngine.ps1 @@ -137,7 +137,7 @@ function Build([string]$configuration, [int]$VsVersion , [bool]$runBuild) { } # Define CMake Generator arguments - $cMakeOptions = " -DCMAKE_SYSTEM_NAME=$systemName", " -DCMAKE_BUILD_TYPE=$configuration" + $cMakeOptions = " -DCMAKE_SYSTEM_NAME=$systemName", " -DCMAKE_BUILD_TYPE=$configuration", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" $submoduleCMakeOptions = @{ 'ENTT' = @("-DENTT_INCLUDE_HEADERS=ON") 'SPDLOG' = @("-DSPDLOG_BUILD_SHARED=OFF", "-DBUILD_STATIC_LIBS=ON", "-DSPDLOG_FMT_EXTERNAL=ON", "-DSPDLOG_FMT_EXTERNAL_HO=OFF"); @@ -150,7 +150,6 @@ function Build([string]$configuration, [int]$VsVersion , [bool]$runBuild) { 'SPIRV_TOOLS' = @("-DSPIRV_SKIP_EXECUTABLES=ON", "-DSPIRV_SKIP_TESTS=ON") 'SPIRV_CROSS' = @("-DSPIRV_CROSS_ENABLE_TESTS=OFF") 'LAUNCHER_ONLY' = @("-DLAUNCHER_ONLY=ON") - 'GLM' = @("-DCMAKE_POLICY_VERSION_MINIMUM=3.5") } $cMakeCacheVariableOverride = $cMakeOptions -join ' ' @@ -192,7 +191,6 @@ function Build([string]$configuration, [int]$VsVersion , [bool]$runBuild) { $cMakeCacheVariableOverride += ' ' + $submoduleCMakeOptions.SPIRV_CROSS -join ' ' $cMakeCacheVariableOverride += ' ' + $submoduleCMakeOptions.SPIRV_TOOLS -join ' ' $cMakeCacheVariableOverride += ' ' + $submoduleCMakeOptions.GLFW -join ' ' - $cMakeCacheVariableOverride += ' ' + $submoduleCMakeOptions.GLM -join ' ' } $cMakeArguments = " -S $repositoryRootPath -B $buildDirectoryPath $cMakeGenerator $cMakeCacheVariableOverride" diff --git a/Tetragrama/Components/HierarchyViewUIComponent.cpp b/Tetragrama/Components/HierarchyViewUIComponent.cpp index 46ee9d1a..404c3a66 100644 --- a/Tetragrama/Components/HierarchyViewUIComponent.cpp +++ b/Tetragrama/Components/HierarchyViewUIComponent.cpp @@ -2,18 +2,18 @@ #include #include #include +#include #include #include #include #include #include -#include -#include using namespace ZEngine; using namespace ZEngine::Helpers; using namespace ZEngine::Windows::Inputs; using namespace ZEngine::Rendering::Scenes; +using namespace ZEngine::Core::Maths; namespace Tetragrama::Components { @@ -233,7 +233,7 @@ namespace Tetragrama::Components if (camera && IDevice::As()->IsKeyPressed(ZENGINE_KEY_F, app->CurrentWindow)) { auto active_editor_camera = reinterpret_cast(app->CameraController); - active_editor_camera->SetTarget(glm::vec3(global_transform[0][3], global_transform[1][3], global_transform[2][3])); + active_editor_camera->SetTarget(Vec3f(global_transform[0][3], global_transform[1][3], global_transform[2][3])); } // snapping @@ -247,10 +247,10 @@ namespace Tetragrama::Components if (m_gizmo_operation > 0) { - ImGuizmo::Manipulate(glm::value_ptr(camera_view_matrix), glm::value_ptr(camera_projection), (ImGuizmo::OPERATION) m_gizmo_operation, ImGuizmo::MODE::WORLD, glm::value_ptr(global_transform), nullptr, is_snap_operation ? snap_array : nullptr); + ImGuizmo::Manipulate(value_ptr(camera_view_matrix), value_ptr(camera_projection), (ImGuizmo::OPERATION) m_gizmo_operation, ImGuizmo::MODE::WORLD, value_ptr(global_transform), nullptr, is_snap_operation ? snap_array : nullptr); } - auto delta_transform = glm::inverse(initial_transform) * global_transform; + auto delta_transform = initial_transform.Inverse() * global_transform; local_transform = local_transform * delta_transform; // current_scene->MarkSceneNodeAsChanged(m_selected_node_identifier); diff --git a/Tetragrama/Components/InspectorViewUIComponent.cpp b/Tetragrama/Components/InspectorViewUIComponent.cpp index 98f8c431..7bdb815a 100644 --- a/Tetragrama/Components/InspectorViewUIComponent.cpp +++ b/Tetragrama/Components/InspectorViewUIComponent.cpp @@ -2,14 +2,13 @@ #include #include #include +#include #include #include -#define GLM_ENABLE_EXPERIMENTAL -#include - using namespace ZEngine::Rendering::Textures; using namespace ZEngine::Helpers; +using namespace ZEngine::Core::Maths; namespace Tetragrama::Components { @@ -56,20 +55,20 @@ namespace Tetragrama::Components // Helpers::DrawEntityControl("Transform", m_scene_entity, m_node_flag, [this] { // auto transform = m_scene_entity.GetTransform(); - // glm::vec3 translation, scale, skew; - // glm::qua rot_quat; - // glm::vec4 perspective; - // glm::decompose(transform, scale, rot_quat, translation, skew, perspective); + // Vec3f translation, scale, skew; + // Quaternion rot_quat; + // Vec4f perspective; + // decompose(transform, scale, rot_quat, translation, skew, perspective); // ImGui::Dummy(ImVec2(0, 3)); - // Helpers::DrawVec3Control("Position", translation, [&translation](glm::vec3& value) { translation = value; }); + // Helpers::DrawVec3Control("Position", translation, [&translation](Vec3f& value) { translation = value; }); - // glm::vec3 rotation = glm::eulerAngles(rot_quat); + // Vec3f rotation = eulerAngles(rot_quat); // ImGui::Dummy(ImVec2(0, 0.5)); - // Helpers::DrawVec3Control("Rotation", rotation, [&rotation](glm::vec3& value) { rotation = value; }); + // Helpers::DrawVec3Control("Rotation", rotation, [&rotation](Vec3f& value) { rotation = value; }); // ImGui::Dummy(ImVec2(0, 0.5)); - // Helpers::DrawVec3Control("Scale", scale, [&scale](glm::vec3& value) { scale = value; }, 1.0f); + // Helpers::DrawVec3Control("Scale", scale, [&scale](Vec3f& value) { scale = value; }, 1.0f); //}); // Mesh Renderer @@ -143,24 +142,24 @@ namespace Tetragrama::Components if (light_type == LightType::DIRECTIONAL) { auto light_ptr = reinterpret_cast(light.get()); - auto direction = light_ptr->Direction.As(); - auto ambient = light_ptr->Ambient.As(); - auto diffuse = light_ptr->Diffuse.As(); - auto specular = light_ptr->Specular.As(); + auto direction = light_ptr->Direction.As(); + auto ambient = light_ptr->Ambient.As(); + auto diffuse = light_ptr->Diffuse.As(); + auto specular = light_ptr->Specular.As(); ImGui::Dummy(ImVec2(0, 0.5f)); { - Helpers::DrawVec3Control("Direction", direction, [light_ptr](glm::vec3& value) { - light_ptr->Direction = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawVec3Control("Direction", direction, [light_ptr](Vec3f& value) { + light_ptr->Direction = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Ambient", ambient, [light_ptr](glm::vec3& value) { - light_ptr->Ambient = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Ambient", ambient, [light_ptr](Vec3f& value) { + light_ptr->Ambient = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Diffuse", diffuse, [light_ptr](glm::vec3& value) { - light_ptr->Diffuse = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Diffuse", diffuse, [light_ptr](Vec3f& value) { + light_ptr->Diffuse = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Specular", specular, [light_ptr](glm::vec3& value) { - light_ptr->Specular = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Specular", specular, [light_ptr](Vec3f& value) { + light_ptr->Specular = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); } } @@ -169,24 +168,24 @@ namespace Tetragrama::Components auto transform = m_scene_entity.GetTransform(); auto light_ptr = reinterpret_cast(light.get()); - auto position = glm::vec3(transform[3]); - auto ambient = light_ptr->Ambient.As(); - auto diffuse = light_ptr->Diffuse.As(); - auto specular = light_ptr->Specular.As(); + auto position = Vec3f(transform[3]); + auto ambient = light_ptr->Ambient.As(); + auto diffuse = light_ptr->Diffuse.As(); + auto specular = light_ptr->Specular.As(); ImGui::Dummy(ImVec2(0, 0.5f)); { - Helpers::DrawVec3Control("Position", position, [light_ptr](glm::vec3& value) { light_ptr->Position = - glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawVec3Control("Position", position, [light_ptr](Vec3f& value) { light_ptr->Position = + Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Ambient", ambient, [light_ptr](glm::vec3& value) { - light_ptr->Ambient = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Ambient", ambient, [light_ptr](Vec3f& value) { + light_ptr->Ambient = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Diffuse", diffuse, [light_ptr](glm::vec3& value) { - light_ptr->Diffuse = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Diffuse", diffuse, [light_ptr](Vec3f& value) { + light_ptr->Diffuse = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Specular", specular, [light_ptr](glm::vec3& value) { - light_ptr->Specular = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Specular", specular, [light_ptr](Vec3f& value) { + light_ptr->Specular = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); Helpers::DrawDragFloatControl("Constant", light_ptr->Constant, 0.2f, 0.0f, 0.0f, "%.2f", [light_ptr](float value) { light_ptr->Constant = value; }); ImGui::Dummy(ImVec2(0, 0.5f)); @@ -204,32 +203,32 @@ namespace Tetragrama::Components auto transform = m_scene_entity.GetTransform(); auto light_ptr = reinterpret_cast(light.get()); - auto direction = light_ptr->Direction.As(); - auto position = glm::vec3(transform[3]); - auto ambient = light_ptr->Ambient.As(); - auto diffuse = light_ptr->Diffuse.As(); - auto specular = light_ptr->Specular.As(); + auto direction = light_ptr->Direction.As(); + auto position = Vec3f(transform[3]); + auto ambient = light_ptr->Ambient.As(); + auto diffuse = light_ptr->Diffuse.As(); + auto specular = light_ptr->Specular.As(); static float phi_angle = 12.5f; ImGui::Dummy(ImVec2(0, 0.5f)); { - Helpers::DrawVec3Control("Position", position, [light_ptr](glm::vec3& value) { light_ptr->Position = - glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawVec3Control("Position", position, [light_ptr](Vec3f& value) { light_ptr->Position = + Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawVec3Control("Direction", direction, [light_ptr](glm::vec3& value) { - light_ptr->Direction = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawVec3Control("Direction", direction, [light_ptr](Vec3f& value) { + light_ptr->Direction = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Ambient", ambient, [light_ptr](glm::vec3& value) { - light_ptr->Ambient = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Ambient", ambient, [light_ptr](Vec3f& value) { + light_ptr->Ambient = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Diffuse", diffuse, [light_ptr](glm::vec3& value) { - light_ptr->Diffuse = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Diffuse", diffuse, [light_ptr](Vec3f& value) { + light_ptr->Diffuse = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); - Helpers::DrawColorEdit3Control("Specular", specular, [light_ptr](glm::vec3& value) { - light_ptr->Specular = glm::vec4(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); + Helpers::DrawColorEdit3Control("Specular", specular, [light_ptr](Vec3f& value) { + light_ptr->Specular = Vec4f(value, 1.0f); }); ImGui::Dummy(ImVec2(0, 0.5f)); Helpers::DrawDragFloatControl("CutOff", phi_angle, 0.1f, 0.0f, 360.0f, "%.2f", [light_ptr](float - value) { phi_angle = value; light_ptr->CutOff = glm::cos(glm::radians(value)); + value) { phi_angle = value; light_ptr->CutOff = cos(radians(value)); }); ImGui::Dummy(ImVec2(0, 0.5f)); diff --git a/Tetragrama/Controllers/EditorCameraController.cpp b/Tetragrama/Controllers/EditorCameraController.cpp index 1806f231..b68bfa4f 100644 --- a/Tetragrama/Controllers/EditorCameraController.cpp +++ b/Tetragrama/Controllers/EditorCameraController.cpp @@ -1,7 +1,9 @@ #include +#include using namespace ZEngine::Rendering::Cameras; using namespace ZEngine::Helpers; +using namespace ZEngine::Core::Maths; namespace Tetragrama::Controllers { @@ -13,7 +15,7 @@ namespace Tetragrama::Controllers m_window = window; m_perspective_camera = ZPushStructCtor(arena, PerspectiveCamera); - m_perspective_camera->Initialize(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far, glm::radians(yaw_degree), glm::radians(pitch_degree)); + m_perspective_camera->Initialize(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far, radians(yaw_degree), radians(pitch_degree)); m_perspective_camera->SetDistance(distance); m_window = window; diff --git a/Tetragrama/EditorScene.cpp b/Tetragrama/EditorScene.cpp index 68baff0e..6d89afad 100644 --- a/Tetragrama/EditorScene.cpp +++ b/Tetragrama/EditorScene.cpp @@ -4,6 +4,7 @@ using namespace ZEngine::Rendering::Meshes; using namespace ZEngine::Core::Containers; +using namespace ZEngine::Core::Maths; using namespace ZEngine::Managers; using namespace ZEngine::Helpers; @@ -63,8 +64,8 @@ namespace Tetragrama Hierarchies.push(new_node); HierarchiesNodeRef.push({}); - LocalTransforms.push(glm::mat4(1.0f)); - GlobalTransforms.push(glm::mat4(1.0f)); + LocalTransforms.push(Identity()); + GlobalTransforms.push(Identity()); if (parent >= 0) { @@ -329,8 +330,8 @@ namespace Tetragrama auto& root_name = Names.push_use({}); root_name.init(&LocalArena, Name); - LocalTransforms.push(glm::mat4(1.0f)); - GlobalTransforms.push(glm::mat4(1.0f)); + LocalTransforms.push(Identity()); + GlobalTransforms.push(Identity()); auto& node = Hierarchies.push_use({}); HierarchiesNodeRef.push({}); diff --git a/Tetragrama/Helpers/UIComponentDrawerHelper.cpp b/Tetragrama/Helpers/UIComponentDrawerHelper.cpp index 5250bf85..ce34015c 100644 --- a/Tetragrama/Helpers/UIComponentDrawerHelper.cpp +++ b/Tetragrama/Helpers/UIComponentDrawerHelper.cpp @@ -3,7 +3,7 @@ namespace Tetragrama::Helpers { - void DrawVec4Control(std::string_view label, ZEngine::Maths::Vector4& values, const std::function& callback, float default_value, float column_width) + void DrawVec4Control(std::string_view label, ZEngine::Core::Maths::Vec4f& values, const std::function& callback, float default_value, float column_width) { ImGuiIO& io = ImGui::GetIO(); auto default_bold_font = io.Fonts->Fonts[0]; @@ -130,7 +130,7 @@ namespace Tetragrama::Helpers ImGui::PopID(); } - void DrawVec3Control(std::string_view label, ZEngine::Maths::Vector3& values, const std::function& callback, float default_value, float column_width) + void DrawVec3Control(std::string_view label, ZEngine::Core::Maths::Vec3f& values, const std::function& callback, float default_value, float column_width) { ImGuiIO& io = ImGui::GetIO(); auto default_bold_font = io.Fonts->Fonts[0]; @@ -233,7 +233,7 @@ namespace Tetragrama::Helpers ImGui::PopID(); } - void DrawVec2Control(std::string_view label, ZEngine::Maths::Vector2& values, const std::function& callback, float default_value, float column_width) + void DrawVec2Control(std::string_view label, ZEngine::Core::Maths::Vec2f& values, const std::function& callback, float default_value, float column_width) { ImGuiIO& io = ImGui::GetIO(); auto default_bold_font = io.Fonts->Fonts[0]; @@ -395,7 +395,7 @@ namespace Tetragrama::Helpers ImGui::PopID(); } - void DrawColorEdit4Control(std::string_view label, ZEngine::Maths::Vector4& values, const std::function& callback, float default_value, float column_width) + void DrawColorEdit4Control(std::string_view label, ZEngine::Core::Maths::Vec4f& values, const std::function& callback, float default_value, float column_width) { ImGui::PushID(label.data(), (label.data() + label.size())); @@ -408,7 +408,7 @@ namespace Tetragrama::Helpers ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth() + 60.f); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0.5f, 0}); - if (ImGui::ColorEdit4("##TintColor", ZEngine::Maths::value_ptr(values))) + if (ImGui::ColorEdit4("##TintColor", ZEngine::Core::Maths::value_ptr(values))) { if (callback) { @@ -422,7 +422,7 @@ namespace Tetragrama::Helpers ImGui::PopID(); } - void DrawColorEdit3Control(std::string_view label, ZEngine::Maths::Vector3& values, const std::function& callback, float default_value, float column_width) + void DrawColorEdit3Control(std::string_view label, ZEngine::Core::Maths::Vec3f& values, const std::function& callback, float default_value, float column_width) { ImGui::PushID(label.data(), (label.data() + label.size())); @@ -435,7 +435,7 @@ namespace Tetragrama::Helpers ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth() + 60.f); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0.5f, 0}); - if (ImGui::ColorEdit3("##TintColor", ZEngine::Maths::value_ptr(values))) + if (ImGui::ColorEdit3("##TintColor", ZEngine::Core::Maths::value_ptr(values))) { if (callback) { @@ -449,7 +449,7 @@ namespace Tetragrama::Helpers ImGui::PopID(); } - void DrawTextureColorControl(std::string_view label, ImTextureID texture_id, ZEngine::Maths::Vector4& tint_color, bool enable_zoom, const std::function& image_click_callback, const std::function& tint_color_change_callback, float column_width) + void DrawTextureColorControl(std::string_view label, ImTextureID texture_id, ZEngine::Core::Maths::Vec4f& tint_color, bool enable_zoom, const std::function& image_click_callback, const std::function& tint_color_change_callback, float column_width) { ImGui::PushID(label.data(), (label.data() + label.size())); ImGui::Columns(2); @@ -484,7 +484,7 @@ namespace Tetragrama::Helpers ImGui::SameLine(); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1, 4)); - if (ImGui::ColorEdit4("##TintColor", ZEngine::Maths::value_ptr(tint_color))) + if (ImGui::ColorEdit4("##TintColor", ZEngine::Core::Maths::value_ptr(tint_color))) { if (tint_color_change_callback) { diff --git a/Tetragrama/Helpers/UIComponentDrawerHelper.h b/Tetragrama/Helpers/UIComponentDrawerHelper.h index e324bbe4..b66a5295 100644 --- a/Tetragrama/Helpers/UIComponentDrawerHelper.h +++ b/Tetragrama/Helpers/UIComponentDrawerHelper.h @@ -1,13 +1,13 @@ #pragma once -#include +#include #include #include namespace Tetragrama::Helpers { - void DrawVec4Control(std::string_view label, ZEngine::Maths::Vector4& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); - void DrawVec3Control(std::string_view label, ZEngine::Maths::Vector3& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); - void DrawVec2Control(std::string_view label, ZEngine::Maths::Vector2& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); + void DrawVec4Control(std::string_view label, ZEngine::Core::Maths::Vec4f& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); + void DrawVec3Control(std::string_view label, ZEngine::Core::Maths::Vec3f& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); + void DrawVec2Control(std::string_view label, ZEngine::Core::Maths::Vec2f& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); void DrawInputTextControl(std::string_view label, std::string_view content, const std::function& callback = nullptr, bool read_only_mode = false, float column_width = 50.f); @@ -15,11 +15,11 @@ namespace Tetragrama::Helpers void DrawCenteredButtonControl(std::string_view label, const std::function& callback = nullptr); - void DrawColorEdit4Control(std::string_view label, ZEngine::Maths::Vector4& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); + void DrawColorEdit4Control(std::string_view label, ZEngine::Core::Maths::Vec4f& values, const std::function& callback = nullptr, float default_value = 0.0f, float column_width = 100.0f); - void DrawColorEdit3Control(std::string_view label, ZEngine::Maths::Vector3& values, const std::function& callback, float default_value = 0.0f, float column_width = 100.0f); + void DrawColorEdit3Control(std::string_view label, ZEngine::Core::Maths::Vec3f& values, const std::function& callback, float default_value = 0.0f, float column_width = 100.0f); - void DrawTextureColorControl(std::string_view label, ImTextureID texture_id, ZEngine::Maths::Vector4& texture_tint_color, bool enable_zoom = true, const std::function& image_click_callback = nullptr, const std::function& tint_color_change_callback = nullptr, float column_width = 100.0f); + void DrawTextureColorControl(std::string_view label, ImTextureID texture_id, ZEngine::Core::Maths::Vec4f& texture_tint_color, bool enable_zoom = true, const std::function& image_click_callback = nullptr, const std::function& tint_color_change_callback = nullptr, float column_width = 100.0f); void DrawColoredTextLine(const char* start, const char* end, const ImVec4& color); diff --git a/ZEngine/ZEngine/Controllers/ICameraController.h b/ZEngine/ZEngine/Controllers/ICameraController.h index 5a118c39..12698dea 100644 --- a/ZEngine/ZEngine/Controllers/ICameraController.h +++ b/ZEngine/ZEngine/Controllers/ICameraController.h @@ -10,12 +10,12 @@ namespace ZEngine::Controllers struct ICameraController : public IController { ICameraController() {} - virtual ~ICameraController() = default; + virtual ~ICameraController() = default; - virtual glm::vec3 GetPosition() const = 0; - virtual void SetPosition(const glm::vec3& position) = 0; - virtual ZRawPtr(Rendering::Cameras::Camera) GetCamera() const = 0; - virtual void UpdateProjectionMatrix() = 0; + virtual Core::Maths::Vec3f GetPosition() const = 0; + virtual void SetPosition(const Core::Maths::Vec3f& position) = 0; + virtual ZRawPtr(Rendering::Cameras::Camera) GetCamera() const = 0; + virtual void UpdateProjectionMatrix() = 0; float GetRotationAngle() const { @@ -74,7 +74,7 @@ namespace ZEngine::Controllers } protected: - glm::vec3 m_position{0.0f, 0.0f, 10.0f}; + Core::Maths::Vec3f m_position{0.0f, 0.0f, 10.0f}; float m_rotation_angle{0.0f}; float m_zoom_factor{1.0f}; float m_move_speed{0.05f}; diff --git a/ZEngine/ZEngine/Controllers/PerspectiveCameraController.cpp b/ZEngine/ZEngine/Controllers/PerspectiveCameraController.cpp index bcbf37c2..83335293 100644 --- a/ZEngine/ZEngine/Controllers/PerspectiveCameraController.cpp +++ b/ZEngine/ZEngine/Controllers/PerspectiveCameraController.cpp @@ -23,7 +23,7 @@ namespace ZEngine::Controllers } const auto mouse_position = IDevice::As()->GetMousePosition(window); - const auto mouse = glm::vec2(mouse_position[0], mouse_position[1]); + const auto mouse = Core::Maths::Vec2f(mouse_position[0], mouse_position[1]); bool mouse_pressed = false; if (IDevice::As()->IsKeyPressed(ZENGINE_KEY_LEFT_ALT, window)) { @@ -36,12 +36,12 @@ namespace ZEngine::Controllers } } - glm::vec3 PerspectiveCameraController::GetPosition() const + Core::Maths::Vec3f PerspectiveCameraController::GetPosition() const { return m_perspective_camera->GetPosition(); } - void PerspectiveCameraController::SetPosition(const glm::vec3& position) + void PerspectiveCameraController::SetPosition(const Core::Maths::Vec3f& position) { m_perspective_camera->SetPosition(position); } @@ -80,7 +80,7 @@ namespace ZEngine::Controllers m_perspective_camera->SetViewport(width, height); } - void PerspectiveCameraController::SetTarget(const glm::vec3& target) + void PerspectiveCameraController::SetTarget(const Core::Maths::Vec3f& target) { m_perspective_camera->SetTarget(target); } @@ -101,7 +101,7 @@ namespace ZEngine::Controllers } } - ZRawPtr(ZEngine::Rendering::Cameras::Camera) PerspectiveCameraController::GetCamera() const + ZRawPtr(Rendering::Cameras::Camera) PerspectiveCameraController::GetCamera() const { return m_perspective_camera; } diff --git a/ZEngine/ZEngine/Controllers/PerspectiveCameraController.h b/ZEngine/ZEngine/Controllers/PerspectiveCameraController.h index 189b1daa..b7632b6a 100644 --- a/ZEngine/ZEngine/Controllers/PerspectiveCameraController.h +++ b/ZEngine/ZEngine/Controllers/PerspectiveCameraController.h @@ -19,51 +19,51 @@ namespace ZEngine::Controllers ZRawPtr(Rendering::Cameras::Camera) GetCamera() const override; - void UpdateProjectionMatrix() override; + void UpdateProjectionMatrix() override; - virtual glm::vec3 GetPosition() const override; - virtual void SetPosition(const glm::vec3& position) override; + virtual Core::Maths::Vec3f GetPosition() const override; + virtual void SetPosition(const Core::Maths::Vec3f& position) override; - virtual float GetFieldOfView() const; - virtual void SetFieldOfView(float rad_fov); + virtual float GetFieldOfView() const; + virtual void SetFieldOfView(float rad_fov); - virtual float GetNear() const; - virtual void SetNear(float value); + virtual float GetNear() const; + virtual void SetNear(float value); - virtual float GetFar() const; - virtual void SetFar(float value); + virtual float GetFar() const; + virtual void SetFar(float value); - void SetViewport(float width, float height); - void SetTarget(const glm::vec3& target); + void SetViewport(float width, float height); + void SetTarget(const Core::Maths::Vec3f& target); - virtual void ResumeEventProcessing(); - virtual void PauseEventProcessing(); + virtual void ResumeEventProcessing(); + virtual void PauseEventProcessing(); public: - bool OnMouseButtonPressed(ZEngine::Windows::Events::MouseButtonPressedEvent&) override + bool OnMouseButtonPressed(Windows::Events::MouseButtonPressedEvent&) override { return false; } - bool OnMouseButtonReleased(ZEngine::Windows::Events::MouseButtonReleasedEvent&) override + bool OnMouseButtonReleased(Windows::Events::MouseButtonReleasedEvent&) override { return false; } - bool OnMouseButtonMoved(ZEngine::Windows::Events::MouseButtonMovedEvent&) override + bool OnMouseButtonMoved(Windows::Events::MouseButtonMovedEvent&) override { return false; } - bool OnMouseButtonWheelMoved(ZEngine::Windows::Events::MouseButtonWheelEvent&) override; + bool OnMouseButtonWheelMoved(Windows::Events::MouseButtonWheelEvent&) override; protected: - float m_camera_fov = 90.0f; - float m_camera_near = 1.f; - float m_camera_far = 1000.0f; - bool m_process_event = true; - glm::vec3 m_camera_target = {0.0f, 0.0f, 0.0f}; - std::recursive_mutex m_event_mutex = {}; - ZRawPtr(ZEngine::Rendering::Cameras::PerspectiveCamera) m_perspective_camera = nullptr; + float m_camera_fov = 90.0f; + float m_camera_near = 1.f; + float m_camera_far = 1000.0f; + bool m_process_event = true; + Core::Maths::Vec3f m_camera_target = {0.0f, 0.0f, 0.0f}; + std::recursive_mutex m_event_mutex = {}; + ZRawPtr(Rendering::Cameras::PerspectiveCamera) m_perspective_camera = nullptr; }; } // namespace ZEngine::Controllers diff --git a/ZEngine/ZEngine/Core/Maths/MathUtils.h b/ZEngine/ZEngine/Core/Maths/MathUtils.h index b7f61295..2f42f858 100644 --- a/ZEngine/ZEngine/Core/Maths/MathUtils.h +++ b/ZEngine/ZEngine/Core/Maths/MathUtils.h @@ -174,4 +174,44 @@ namespace ZEngine::Core::Maths return atan2(sqrt_term, x); } + template + constexpr bool epsilonNotEqual(T a, T b, T epsilon = T(1e-6)) + { + return abs(a - b) > epsilon; + } + + template + constexpr bool epsilonEqual(T a, T b, T epsilon = T(1e-6)) + { + return abs(a - b) == epsilon; + } + + template + T asin(T x) + { + if (abs(x) > T(1)) + return T(0); + + if (x == T(1)) + return HALF_PI; + else if (x == T(-1)) + return -HALF_PI; + else if (x == T(0)) + return T(0); + + T sqrt_term = sqrt(T(1) - x * x); + return atan2(x, sqrt_term); + } + + template + T tan(T x) + { + T c = cos(x); + if (c == T(0)) + { + return (x > T(0)) ? T(1e30) : T(-1e30); + } + return sin(x) / c; + } + } // namespace ZEngine::Core::Maths \ No newline at end of file diff --git a/ZEngine/ZEngine/Core/Maths/Matrix.h b/ZEngine/ZEngine/Core/Maths/Matrix.h index 82ce7508..274eadbc 100644 --- a/ZEngine/ZEngine/Core/Maths/Matrix.h +++ b/ZEngine/ZEngine/Core/Maths/Matrix.h @@ -1,3 +1,4 @@ +#pragma once #include #include @@ -363,6 +364,15 @@ namespace ZEngine::Core::Maths return Mat4(r0.x, r1.x, r2.x, r3.x, r0.y, r1.y, r2.y, r3.y, r0.z, r1.z, r2.z, r3.z, -dot(r0, d), -dot(r1, d), -dot(r2, a), -dot(r3, a)); } + Vec4& operator[](int j) + { + return (*reinterpret_cast*>(m_data[j])); + } + + const Vec4& operator[](int j) const + { + return (*reinterpret_cast*>(m_data[j])); + } }; using IMat2 = Mat2; @@ -409,11 +419,17 @@ namespace ZEngine::Core::Maths } template - inline Mat3 operator*(const Mat3& a, const Vec3& v) + inline Vec3 operator*(const Mat3& a, const Vec3& v) { return Vec3(a(0, 0) * v.x + a(0, 1) * v.y + a(0, 2) * v.z, a(1, 0) * v.x + a(1, 1) * v.y + a(1, 2) * v.z, a(2, 0) * v.x + a(2, 1) * v.y + a(2, 2) * v.z); } + template + inline Vec4 operator*(const Mat4& a, const Vec4& vec) + { + return Vec4(a(0, 0) * vec.x + a(0, 1) * vec.y + a(0, 2) * vec.z + a(0, 3) * vec.w, a(1, 0) * vec.x + a(1, 1) * vec.y + a(1, 2) * vec.z + a(1, 3) * vec.w, a(2, 0) * vec.x + a(2, 1) * vec.y + a(2, 2) * vec.z + a(2, 3) * vec.w, a(3, 0) * vec.x + a(3, 1) * vec.y + a(3, 2) * vec.z + a(3, 3) * vec.w); + } + template T Determinant(const Mat2& M) { @@ -461,4 +477,115 @@ namespace ZEngine::Core::Maths a(3, 0) * b(0, 2) + a(3, 1) * b(1, 2) + a(3, 2) * b(2, 2) + a(3, 3) * b(3, 2), a(3, 0) * b(0, 3) + a(3, 1) * b(1, 3) + a(3, 2) * b(2, 3) + a(3, 3) * b(3, 3))); } -} // namespace ZEngine::Core::Maths + + inline bool DecomposeTransformComponent(const Mat4f& transform, Vec3f& translation, Vec3f& rotation, Vec3f& scale) + { + Mat4f LocalMatrix(transform); + if (epsilonEqual(LocalMatrix(3, 3), static_cast(0))) + return false; + + if (epsilonNotEqual(LocalMatrix(0, 3), static_cast(0.0f)) || epsilonNotEqual(LocalMatrix(3, 1), static_cast(0.0f)) || epsilonNotEqual(LocalMatrix(3, 2), static_cast(0.0f))) + { + LocalMatrix(3, 0) = LocalMatrix(3, 1) = LocalMatrix(3, 2) = static_cast(0); + LocalMatrix(3, 3) = static_cast(1); + } + + // Next take care of translation (easy). + translation = Vec3f(LocalMatrix[3].x, LocalMatrix[3].y, LocalMatrix[3].z); + LocalMatrix[3] = Vec4f(0, 0, 0, LocalMatrix[3].w); + + Vec3f Row[3], Pdum3; + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 3; ++j) + Row[i][j] = LocalMatrix(i, j); + + scale.x = Row[0].magnitude(); + Row[0] = Row[0].normalize(); + scale.y = Row[1].magnitude(); + Row[1] = Row[1].normalize(); + scale.z = Row[2].magnitude(); + Row[2] = Row[2].normalize(); + + // At this point, the matrix (in rows[]) is orthonormal. + // Check for a coordinate system flip. If the determinant + // is -1, then negate the matrix and the scaling factors. + + rotation.y = asin(-Row[0][2]); + if (cos(rotation.y) != 0) + { + rotation.x = atan2(Row[1][2], Row[2][2]); + rotation.z = atan2(Row[0][1], Row[0][0]); + } + else + { + rotation.x = atan2(-Row[2][0], Row[1][1]); + rotation.z = 0; + } + + return true; + } + + template + inline Mat4 translate(const Mat4& matrix, const Vec3& translation) + { + Mat4 result = matrix; + + // Set translation column (last column) + result(0, 3) = matrix(0, 0) * translation.x + matrix(0, 1) * translation.y + matrix(0, 2) * translation.z + matrix(0, 3); + result(1, 3) = matrix(1, 0) * translation.x + matrix(1, 1) * translation.y + matrix(1, 2) * translation.z + matrix(1, 3); + result(2, 3) = matrix(2, 0) * translation.x + matrix(2, 1) * translation.y + matrix(2, 2) * translation.z + matrix(2, 3); + result(3, 3) = matrix(3, 0) * translation.x + matrix(3, 1) * translation.y + matrix(3, 2) * translation.z + matrix(3, 3); + + return result; + } + + template + const T* value_ptr(const Matrix& matrix) + { + return &matrix.m_data[0][0]; + } + + template + T* value_ptr(Matrix& matrix) + { + return &matrix.m_data[0][0]; + } + + // value_ptr for vectors + template + const T* value_ptr(const Vec2& vec) + { + return &vec.x; + } + + template + T* value_ptr(Vec2& vec) + { + return &vec.x; + } + + template + const T* value_ptr(const Vec3& vec) + { + return &vec.x; + } + + template + T* value_ptr(Vec3& vec) + { + return &vec.x; + } + + template + const T* value_ptr(const Vec4& vec) + { + return &vec.x; + } + + template + T* value_ptr(Vec4& vec) + { + return &vec.x; + } + +} // namespace ZEngine::Core::Maths \ No newline at end of file diff --git a/ZEngine/ZEngine/Core/Maths/Quaternion.h b/ZEngine/ZEngine/Core/Maths/Quaternion.h index 82cad9dd..9b0fd1a1 100644 --- a/ZEngine/ZEngine/Core/Maths/Quaternion.h +++ b/ZEngine/ZEngine/Core/Maths/Quaternion.h @@ -1,4 +1,5 @@ -#include +#pragma once +#include namespace ZEngine::Core::Maths { @@ -311,4 +312,40 @@ namespace ZEngine::Core::Maths return slerpUnclamped(a, b, t); } + template + inline Vec3 rotate(const Quaternion& quat, const Vec3& vec) + { + Vec3 qvec(quat.x, quat.y, quat.z); + T qw = quat.w; + + Vec3 cross1 = cross3d(qvec, vec); + Vec3 cross2 = cross3d(qvec, cross1 + vec * qw); + + return vec + cross2 * T(2); + } + + template + Mat4 quaternionToMat4(const Quaternion& quat) + { + Quaternion q = quat.normalize(); + + T x = q.x, y = q.y, z = q.z, w = q.w; + + T x2 = x * T(2); + T y2 = y * T(2); + T z2 = z * T(2); + + T xx = x * x2; + T xy = x * y2; + T xz = x * z2; + T yy = y * y2; + T yz = y * z2; + T zz = z * z2; + T wx = w * x2; + T wy = w * y2; + T wz = w * z2; + + return Mat4(T(1) - (yy + zz), xy - wz, xz + wy, T(0), xy + wz, T(1) - (xx + zz), yz - wx, T(0), xz - wy, yz + wx, T(1) - (xx + yy), T(0), T(0), T(0), T(0), T(1)); + } + } // namespace ZEngine::Core::Maths \ No newline at end of file diff --git a/ZEngine/ZEngine/Core/Maths/Vec.h b/ZEngine/ZEngine/Core/Maths/Vec.h index ae9255a5..c558c74e 100644 --- a/ZEngine/ZEngine/Core/Maths/Vec.h +++ b/ZEngine/ZEngine/Core/Maths/Vec.h @@ -211,6 +211,11 @@ namespace ZEngine::Core::Maths return *this; } + Vec3 operator-() const + { + return Vec3(-x, -y, -z); + } + T magnitude() const { return sqrt(x * x + y * y + z * z); @@ -241,6 +246,14 @@ namespace ZEngine::Core::Maths w = w_; } + Vec4(const Vec3& vec3, T w_) + { + x = vec3.x; + y = vec3.y; + z = vec3.z; + w = w_; + } + T& operator[](size_t index) { ZENGINE_VALIDATE_ASSERT(index < 4, "Index out of range"); @@ -352,6 +365,18 @@ namespace ZEngine::Core::Maths return result; } + template + inline Vec3 radians(const Vec3& degrees) + { + return Vec3(radians(degrees.x), radians(degrees.y), radians(degrees.z)); + } + + template + inline Vec3 degrees(const Vec3& angles) + { + return Vec3(degrees(angles.x), degrees(angles.y), degrees(angles.z)); + } + using Vec2f = Vec2; using Vec3f = Vec3; using Vec4f = Vec4; diff --git a/ZEngine/ZEngine/Helpers/Helper.cpp b/ZEngine/ZEngine/Helpers/Helper.cpp index 4b0f4f99..9a85552d 100644 --- a/ZEngine/ZEngine/Helpers/Helper.cpp +++ b/ZEngine/ZEngine/Helpers/Helper.cpp @@ -1,6 +1,6 @@ +#include #include #include -#include #include #include #include @@ -96,16 +96,16 @@ namespace ZEngine::Helpers return meshes; } - glm::mat4 ConvertToMat4(const aiMatrix4x4& m) + ZEngine::Core::Maths::Mat4f ConvertToMat4(const aiMatrix4x4& m) { - glm::mat4 mm; + ZEngine::Core::Maths::Mat4f mm; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - mm[i][j] = m[i][j]; + mm(i, j) = m[i][j]; } } return mm; } -} // namespace ZEngine::Helpers +} // namespace ZEngine::Helpers \ No newline at end of file diff --git a/ZEngine/ZEngine/Helpers/MathHelper.h b/ZEngine/ZEngine/Helpers/MathHelper.h deleted file mode 100644 index d71a63fa..00000000 --- a/ZEngine/ZEngine/Helpers/MathHelper.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include -#include - -namespace ZEngine::Helpers -{ - glm::mat4 ConvertToMat4(const aiMatrix4x4&); -} \ No newline at end of file diff --git a/ZEngine/ZEngine/Importers/AssetTypes.h b/ZEngine/ZEngine/Importers/AssetTypes.h index 42bc5e7a..49e7c9f8 100644 --- a/ZEngine/ZEngine/Importers/AssetTypes.h +++ b/ZEngine/ZEngine/Importers/AssetTypes.h @@ -2,9 +2,9 @@ #include #include #include +#include #include #include -#include #include namespace ZEngine::Importers @@ -68,8 +68,8 @@ namespace ZEngine::Importers uuids::uuid NodeHierarchyUUID = {}; uuids::uuid MeshUUID = {}; Core::Containers::Array Hierarchies = {}; - Core::Containers::Array LocalTransforms = {}; - Core::Containers::Array GlobalTransforms = {}; + Core::Containers::Array LocalTransforms = {}; + Core::Containers::Array GlobalTransforms = {}; Core::Containers::Array Names = {}; Core::Containers::Array MaterialNames = {}; Core::Containers::HashMap NodeNames = {}; diff --git a/ZEngine/ZEngine/Importers/AssimpImporter.cpp b/ZEngine/ZEngine/Importers/AssimpImporter.cpp index 88621a0d..29d76aea 100644 --- a/ZEngine/ZEngine/Importers/AssimpImporter.cpp +++ b/ZEngine/ZEngine/Importers/AssimpImporter.cpp @@ -9,6 +9,7 @@ using namespace ZEngine::Helpers; using namespace ZEngine::Rendering::Meshes; using namespace ZEngine::Rendering::Scenes; using namespace ZEngine::Core::Containers; +using namespace ZEngine::Core::Maths; using namespace uuids; namespace fs = std::filesystem; @@ -226,7 +227,7 @@ namespace ZEngine::Importers material.AmbientColor[1] = color.g; material.AmbientColor[2] = color.b; material.AmbientColor[3] = color.a; - material.AmbientColor[3] = glm::min(material.AmbientColor[3], 1.0f); + material.AmbientColor[3] = min(material.AmbientColor[3], 1.0f); } if (aiGetMaterialColor(ai_material, AI_MATKEY_COLOR_DIFFUSE, &color) == AI_SUCCESS) @@ -235,7 +236,7 @@ namespace ZEngine::Importers material.AlbedoColor[1] = color.g; material.AlbedoColor[2] = color.b; material.AlbedoColor[3] = color.a; - material.AlbedoColor[3] = glm::min(material.AlbedoColor[3], 1.0f); + material.AlbedoColor[3] = min(material.AlbedoColor[3], 1.0f); } if (aiGetMaterialColor(ai_material, AI_MATKEY_COLOR_SPECULAR, &color) == AI_SUCCESS) @@ -244,7 +245,7 @@ namespace ZEngine::Importers material.SpecularColor[1] = color.g; material.SpecularColor[2] = color.b; material.SpecularColor[3] = color.a; - material.SpecularColor[3] = glm::min(material.SpecularColor[3], 1.0f); + material.SpecularColor[3] = min(material.SpecularColor[3], 1.0f); } if (aiGetMaterialColor(ai_material, AI_MATKEY_COLOR_EMISSIVE, &color) == AI_SUCCESS) @@ -253,7 +254,7 @@ namespace ZEngine::Importers material.EmissiveColor[1] = color.g; material.EmissiveColor[2] = color.b; material.EmissiveColor[3] = color.a; - material.EmissiveColor[3] = glm::min(material.EmissiveColor[3], 1.0f); + material.EmissiveColor[3] = min(material.EmissiveColor[3], 1.0f); } float opacity = 1.0f; @@ -261,7 +262,7 @@ namespace ZEngine::Importers if (aiGetMaterialFloat(ai_material, AI_MATKEY_OPACITY, &opacity) == AI_SUCCESS) { - material.Factors[0] = glm::clamp(1.f - opacity, 0.0f, 1.0f); + material.Factors[0] = clamp(1.f - opacity, 0.0f, 1.0f); if (material.Factors[0] >= (1.0f - opaqueness_threshold)) { material.Factors[0] = 0.0f; @@ -271,7 +272,7 @@ namespace ZEngine::Importers if (aiGetMaterialColor(ai_material, AI_MATKEY_COLOR_TRANSPARENT, &color) == AI_SUCCESS) { const float component_as_opacity = std::max(std::max(color.r, color.g), color.b); - material.Factors[0] = glm::clamp(component_as_opacity, 0.0f, 1.0f); + material.Factors[0] = clamp(component_as_opacity, 0.0f, 1.0f); if (material.Factors[0] >= (1.0f - opaqueness_threshold)) { material.Factors[0] = 0.0f; @@ -389,7 +390,7 @@ namespace ZEngine::Importers auto& name = hierarchy.Names.push_use({}); name.init(arena, node->mName.C_Str() ? node->mName.C_Str() : ""); - hierarchy.GlobalTransforms[node_id] = glm::mat4(1.0f); + hierarchy.GlobalTransforms[node_id] = Identity(); hierarchy.LocalTransforms[node_id] = ConvertToMat4(node->mTransformation); for (uint32_t i = 0; i < node->mNumMeshes; ++i) @@ -405,8 +406,8 @@ namespace ZEngine::Importers hierarchy.NodeMeshes[sub_node_id] = mesh; hierarchy.NodeMaterials[sub_node_id] = material_id; - hierarchy.GlobalTransforms[sub_node_id] = glm::mat4(1.0f); - hierarchy.LocalTransforms[sub_node_id] = glm::mat4(1.0f); + hierarchy.GlobalTransforms[sub_node_id] = Identity(); + hierarchy.LocalTransforms[sub_node_id] = Identity(); auto& asset_mat = materials[material_id]; auto& sub_mesh = asset_mesh.SubMeshes[mesh]; @@ -501,14 +502,14 @@ namespace ZEngine::Importers } } - glm::mat4 AssimpImporter::ConvertToMat4(const aiMatrix4x4& m) + Mat4f AssimpImporter::ConvertToMat4(const aiMatrix4x4& m) { - glm::mat4 mm; + Mat4f mm; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - mm[i][j] = m[i][j]; + mm(i, j) = m[i][j]; } } return mm; diff --git a/ZEngine/ZEngine/Importers/AssimpImporter.h b/ZEngine/ZEngine/Importers/AssimpImporter.h index 9bd455eb..a78fc34e 100644 --- a/ZEngine/ZEngine/Importers/AssimpImporter.h +++ b/ZEngine/ZEngine/Importers/AssimpImporter.h @@ -35,12 +35,12 @@ namespace ZEngine::Importers friend struct AssimpProgressHandler; - void ExtractMeshes(Core::Memory::ArenaAllocator*, const aiScene*, uuids::uuid_random_generator&, AssetMesh&); - void ExtractMaterials(Core::Memory::ArenaAllocator*, const aiScene*, uuids::uuid_random_generator&, Core::Containers::Array&, AssetNodeHierarchy&); - void ExtractTextures(Core::Memory::ArenaAllocator* arena, const aiScene*, uuids::uuid_random_generator&, Core::Containers::Array&, Core::Containers::Array&); - void CreateHierachy(Core::Memory::ArenaAllocator* arena, const aiScene*, uuids::uuid_random_generator&, AssetNodeHierarchy&, AssetMesh&, Core::Containers::Array&); + void ExtractMeshes(Core::Memory::ArenaAllocator*, const aiScene*, uuids::uuid_random_generator&, AssetMesh&); + void ExtractMaterials(Core::Memory::ArenaAllocator*, const aiScene*, uuids::uuid_random_generator&, Core::Containers::Array&, AssetNodeHierarchy&); + void ExtractTextures(Core::Memory::ArenaAllocator* arena, const aiScene*, uuids::uuid_random_generator&, Core::Containers::Array&, Core::Containers::Array&); + void CreateHierachy(Core::Memory::ArenaAllocator* arena, const aiScene*, uuids::uuid_random_generator&, AssetNodeHierarchy&, AssetMesh&, Core::Containers::Array&); - void TraverseNode(Core::Memory::ArenaAllocator* arena, const aiScene*, const aiNode*, AssetNodeHierarchy&, AssetMesh&, Core::Containers::Array&, int parent_node_id, int depth_level); - glm::mat4 ConvertToMat4(const aiMatrix4x4& m); + void TraverseNode(Core::Memory::ArenaAllocator* arena, const aiScene*, const aiNode*, AssetNodeHierarchy&, AssetMesh&, ZEngine::Core::Containers::Array&, int parent_node_id, int depth_level); + Core::Maths::Mat4f ConvertToMat4(const aiMatrix4x4& m); }; } // namespace ZEngine::Importers \ No newline at end of file diff --git a/ZEngine/ZEngine/Importers/IAssetImporter.cpp b/ZEngine/ZEngine/Importers/IAssetImporter.cpp index 450a0251..6f5785d9 100644 --- a/ZEngine/ZEngine/Importers/IAssetImporter.cpp +++ b/ZEngine/ZEngine/Importers/IAssetImporter.cpp @@ -5,6 +5,7 @@ using namespace uuids; using namespace ZEngine::Helpers; using namespace ZEngine::Core::Containers; +using namespace ZEngine::Core::Maths; namespace ZEngine::Importers { @@ -18,8 +19,8 @@ namespace ZEngine::Importers int node_id = (int) hierarchy.Hierarchies.size(); hierarchy.Hierarchies.push({.Parent = parent}); - hierarchy.LocalTransforms.push(glm::mat4(1.0f)); - hierarchy.GlobalTransforms.push(glm::mat4(1.0f)); + hierarchy.LocalTransforms.push(Identity()); + hierarchy.GlobalTransforms.push(Identity()); if (parent > -1) { diff --git a/ZEngine/ZEngine/Managers/AssetManager.cpp b/ZEngine/ZEngine/Managers/AssetManager.cpp index 5a354ea7..b0009985 100644 --- a/ZEngine/ZEngine/Managers/AssetManager.cpp +++ b/ZEngine/ZEngine/Managers/AssetManager.cpp @@ -269,8 +269,8 @@ namespace ZEngine::Managers h.NodeMaterials.init(&(s_Instance->Arena), hierarchies.NodeMaterials.size() > 32 ? hierarchies.NodeMaterials.size() * 2 : 64); Helpers::secure_memcpy(h.Hierarchies.data(), h.Hierarchies.size() * sizeof(AssetNodeHierarchy), hierarchies.Hierarchies.data(), hierarchies.Hierarchies.size() * sizeof(AssetNodeHierarchy)); - Helpers::secure_memcpy(h.LocalTransforms.data(), h.LocalTransforms.size() * sizeof(glm::mat4), hierarchies.LocalTransforms.data(), hierarchies.LocalTransforms.size() * sizeof(glm::mat4)); - Helpers::secure_memcpy(h.GlobalTransforms.data(), h.GlobalTransforms.size() * sizeof(glm::mat4), hierarchies.GlobalTransforms.data(), hierarchies.GlobalTransforms.size() * sizeof(glm::mat4)); + Helpers::secure_memcpy(h.LocalTransforms.data(), h.LocalTransforms.size() * sizeof(Core::Maths::Mat4f), hierarchies.LocalTransforms.data(), hierarchies.LocalTransforms.size() * sizeof(Core::Maths::Mat4f)); + Helpers::secure_memcpy(h.GlobalTransforms.data(), h.GlobalTransforms.size() * sizeof(Core::Maths::Mat4f), hierarchies.GlobalTransforms.data(), hierarchies.GlobalTransforms.size() * sizeof(Core::Maths::Mat4f)); for (auto& name : hierarchies.Names) { diff --git a/ZEngine/ZEngine/Maths/Math.cpp b/ZEngine/ZEngine/Maths/Math.cpp deleted file mode 100644 index b15245c7..00000000 --- a/ZEngine/ZEngine/Maths/Math.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include - -#define GLM_ENABLE_EXPERIMENTAL -#include - -namespace glm -{ - - bool DecomposeTransformComponent(const Matrix4& transform, Vector3& translation, Vector3& rotation, Vector3& scale) - { - // From glm::decompose in matrix_decompose.inl - - using T = float; - - mat4 LocalMatrix(transform); - - // Normalize the matrix. - if (epsilonEqual(LocalMatrix[3][3], static_cast(0), epsilon())) - return false; - - // First, isolate perspective. This is the messiest. - if (epsilonNotEqual(LocalMatrix[0][3], static_cast(0), epsilon()) || epsilonNotEqual(LocalMatrix[1][3], static_cast(0), epsilon()) || epsilonNotEqual(LocalMatrix[2][3], static_cast(0), epsilon())) - { - // Clear the perspective partition - LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] = static_cast(0); - LocalMatrix[3][3] = static_cast(1); - } - - // Next take care of translation (easy). - translation = vec3(LocalMatrix[3]); - LocalMatrix[3] = vec4(0, 0, 0, LocalMatrix[3].w); - - vec3 Row[3], Pdum3; - - // Now get scale and shear. - for (length_t i = 0; i < 3; ++i) - for (length_t j = 0; j < 3; ++j) - Row[i][j] = LocalMatrix[i][j]; - - // Compute X scale factor and normalize first row. - scale.x = length(Row[0]); - Row[0] = detail::scale(Row[0], static_cast(1)); - scale.y = length(Row[1]); - Row[1] = detail::scale(Row[1], static_cast(1)); - scale.z = length(Row[2]); - Row[2] = detail::scale(Row[2], static_cast(1)); - - // At this point, the matrix (in rows[]) is orthonormal. - // Check for a coordinate system flip. If the determinant - // is -1, then negate the matrix and the scaling factors. - - rotation.y = asin(-Row[0][2]); - if (cos(rotation.y) != 0) - { - rotation.x = atan2(Row[1][2], Row[2][2]); - rotation.z = atan2(Row[0][1], Row[0][0]); - } - else - { - rotation.x = atan2(-Row[2][0], Row[1][1]); - rotation.z = 0; - } - - return true; - } -} // namespace glm diff --git a/ZEngine/ZEngine/Maths/Math.h b/ZEngine/ZEngine/Maths/Math.h deleted file mode 100644 index 0e77759c..00000000 --- a/ZEngine/ZEngine/Maths/Math.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -namespace ZEngine -{ - namespace Maths = glm; -} - -// GLM extensions -namespace glm -{ - using Vector4 = vec4; - using Vector3 = vec3; - using Vector2 = vec2; - using Vector1 = vec1; - - using Matrix4 = mat4; - using Matrix3 = mat3; - using Matrix2 = mat2; - - using Quaternion = quat; - - // From TheCherno : https://github.com/TheCherno/Hazel/blob/master/Hazel/src/Hazel/Math/Math.h - bool DecomposeTransformComponent(const Matrix4& transform, Vector3& translation, Vector3& rotation, Vector3& scale); -} // namespace glm diff --git a/ZEngine/ZEngine/Rendering/Buffers/Bitmap.h b/ZEngine/ZEngine/Rendering/Buffers/Bitmap.h index 9cc5ced6..09c1a7a1 100644 --- a/ZEngine/ZEngine/Rendering/Buffers/Bitmap.h +++ b/ZEngine/ZEngine/Rendering/Buffers/Bitmap.h @@ -1,8 +1,8 @@ #pragma once +#include +#include #include #include -#include -#include #include #include @@ -29,9 +29,9 @@ namespace ZEngine::Rendering::Buffers * The A and B values are normalized coordinates in the range [-1, 1], calculated from pixel coordinates (i, j) * and the face size. * - * Reference: "Real-Time Rendering, Fourth Edition" by Tomas Akenine-Möller, Eric Haines, Naty Hoffman + * Reference: "Real-Time Rendering, Fourth Edition" by Tomas Akenine-M�ller, Eric Haines, Naty Hoffman */ - static glm::vec3 FaceCoordToXYZ(int i, int j, int face_id, int face_size) + static ZEngine::Core::Maths::Vec3f FaceCoordToXYZ(int i, int j, int face_id, int face_size) { const float A = 2.0f * float(i) / face_size; const float B = 2.0f * float(j) / face_size; @@ -41,21 +41,21 @@ namespace ZEngine::Rendering::Buffers * The y and z coordinates are set based on the normalized pixel coordinates. */ if (face_id == 0) - return glm::vec3(-1.0f, A - 1.0f, B - 1.0f); + return ZEngine::Core::Maths::Vec3f(-1.0f, A - 1.0f, B - 1.0f); /* * The left face is mapped to the positive x-axis, so the x-coordinate is set to A - 1.0f. * The y-coordinate is set to -1.0f, and the z-coordinate is set based on the normalized pixel coordinates. */ if (face_id == 1) - return glm::vec3(A - 1.0f, -1.0f, 1.0f - B); + return ZEngine::Core::Maths::Vec3f(A - 1.0f, -1.0f, 1.0f - B); /* * The top face is mapped to the positive y-axis, so the y-coordinate is set to A - 1.0f. * The x-coordinate is set to 1.0f, and the z-coordinate is set based on the normalized pixel coordinates. */ if (face_id == 2) - return glm::vec3(1.0f, A - 1.0f, 1.0f - B); + return ZEngine::Core::Maths::Vec3f(1.0f, A - 1.0f, 1.0f - B); /* * The bottom face is mapped to the negative y-axis, so the y-coordinate is set to 1.0f. @@ -63,23 +63,23 @@ namespace ZEngine::Rendering::Buffers * coordinates */ if (face_id == 3) - return glm::vec3(1.0f - A, 1.0f, 1.0f - B); + return ZEngine::Core::Maths::Vec3f(1.0f - A, 1.0f, 1.0f - B); /* * The front face is mapped to the positive z-axis, so the z-coordinate is set to 1.0f. *The x and y coordinates are set based on the normalized pixel coordinates. */ if (face_id == 4) - return glm::vec3(B - 1.0f, A - 1.0f, 1.0f); + return ZEngine::Core::Maths::Vec3f(B - 1.0f, A - 1.0f, 1.0f); /* * The back face is mapped to the negative z-axis, so the z-coordinate is set to -1.0f. * The x and y coordinates are set based on the normalized pixel coordinates. */ if (face_id == 5) - return glm::vec3(1.0f - B, A - 1.0f, -1.0f); + return ZEngine::Core::Maths::Vec3f(1.0f - B, A - 1.0f, -1.0f); - return glm::vec3{}; + return ZEngine::Core::Maths::Vec3f{}; } }; @@ -97,7 +97,7 @@ namespace ZEngine::Rendering::Buffers } ~Bitmap() = default; - void SetPixel(int x, int y, const glm::vec4& pixel) + void SetPixel(int x, int y, const ZEngine::Core::Maths::Vec4f& pixel) { if (Format == BitmapFormat::UNSIGNED_BYTE) { @@ -126,21 +126,21 @@ namespace ZEngine::Rendering::Buffers } } - glm::vec4 GetPixel(int x, int y) const + ZEngine::Core::Maths::Vec4f GetPixel(int x, int y) const { if (Format == BitmapFormat::UNSIGNED_BYTE) { const int ofs = Channel * (y * Width + x); - return glm::vec4(Channel > 0 ? float(Buffer[ofs + 0]) / 255.0f : 0.0f, Channel > 1 ? float(Buffer[ofs + 1]) / 255.0f : 0.0f, Channel > 2 ? float(Buffer[ofs + 2]) / 255.0f : 0.0f, Channel > 3 ? float(Buffer[ofs + 3]) / 255.0f : 0.0f); + return ZEngine::Core::Maths::Vec4f(Channel > 0 ? float(Buffer[ofs + 0]) / 255.0f : 0.0f, Channel > 1 ? float(Buffer[ofs + 1]) / 255.0f : 0.0f, Channel > 2 ? float(Buffer[ofs + 2]) / 255.0f : 0.0f, Channel > 3 ? float(Buffer[ofs + 3]) / 255.0f : 0.0f); } else if (Format == BitmapFormat::FLOAT) { const int ofs = Channel * (y * Width + x); const float* data = reinterpret_cast(Buffer.data()); - return glm::vec4(Channel > 0 ? data[ofs + 0] : 0.0f, Channel > 1 ? data[ofs + 1] : 0.0f, Channel > 2 ? data[ofs + 2] : 0.0f, Channel > 3 ? data[ofs + 3] : 0.0f); + return ZEngine::Core::Maths::Vec4f(Channel > 0 ? data[ofs + 0] : 0.0f, Channel > 1 ? data[ofs + 1] : 0.0f, Channel > 2 ? data[ofs + 2] : 0.0f, Channel > 3 ? data[ofs + 3] : 0.0f); } - return glm::vec4(); + return ZEngine::Core::Maths::Vec4f(); } inline static int BytePerChannel(BitmapFormat format) @@ -164,20 +164,20 @@ namespace ZEngine::Rendering::Buffers return Bitmap(); } - const int face_size = input_map.Width / 4; + const int face_size = input_map.Width / 4; - const int width = face_size * 3; - const int height = face_size * 4; + const int width = face_size * 3; + const int height = face_size * 4; - Bitmap vertical_cross = Bitmap(width, height, input_map.Channel, input_map.Format); + Bitmap vertical_cross = Bitmap(width, height, input_map.Channel, input_map.Format); - const glm::ivec2 face_offsets[] = { - glm::ivec2{ face_size, face_size * 3}, - glm::ivec2{ 0, face_size}, - glm::ivec2{ face_size, face_size}, - glm::ivec2{face_size * 2, face_size}, - glm::ivec2{ face_size, 0}, - glm::ivec2{ face_size, face_size * 2} + const ZEngine::Core::Maths::IVec2 face_offsets[] = { + ZEngine::Core::Maths::IVec2{ face_size, face_size * 3}, + ZEngine::Core::Maths::IVec2{ 0, face_size}, + ZEngine::Core::Maths::IVec2{ face_size, face_size}, + ZEngine::Core::Maths::IVec2{face_size * 2, face_size}, + ZEngine::Core::Maths::IVec2{ face_size, 0}, + ZEngine::Core::Maths::IVec2{ face_size, face_size * 2} }; const int clamped_width = input_map.Width - 1; @@ -189,28 +189,28 @@ namespace ZEngine::Rendering::Buffers { for (int j = 0; j < face_size; ++j) { - const glm::vec3 P = BitmapPixel::FaceCoordToXYZ(i, j, face, face_size); - const float R = hypot(P.x, P.y); - const float theta = atan2(P.y, P.x); - const float phi = atan2(P.z, R); + const ZEngine::Core::Maths::Vec3f P = BitmapPixel::FaceCoordToXYZ(i, j, face, face_size); + const float R = hypot(P.x, P.y); + const float theta = atan2(P.y, P.x); + const float phi = atan2(P.z, R); - const float Uf = float(2.0f * face_size * (theta + glm::pi()) / glm::pi()); - const float Vf = float(2.0f * face_size * (glm::pi() / 2.0f - phi) / glm::pi()); + const float Uf = float(2.0f * face_size * (theta + ZEngine::Core::Maths::PI) / ZEngine::Core::Maths::PI); + const float Vf = float(2.0f * face_size * (ZEngine::Core::Maths::PI / 2.0f - phi) / ZEngine::Core::Maths::PI); - const int U1 = glm::clamp(int(floor(Uf)), 0, clamped_width); - const int V1 = glm::clamp(int(floor(Vf)), 0, clamped_height); - const int U2 = glm::clamp(U1 + 1, 0, clamped_width); - const int V2 = glm::clamp(V1 + 1, 0, clamped_height); + const int U1 = ZEngine::Core::Maths::clamp(int(floor(Uf)), 0, clamped_width); + const int V1 = ZEngine::Core::Maths::clamp(int(floor(Vf)), 0, clamped_height); + const int U2 = ZEngine::Core::Maths::clamp(U1 + 1, 0, clamped_width); + const int V2 = ZEngine::Core::Maths::clamp(V1 + 1, 0, clamped_height); - const float s = Uf - U1; - const float t = Vf - V1; + const float s = Uf - U1; + const float t = Vf - V1; - const glm::vec4 A = input_map.GetPixel(U1, V1); - const glm::vec4 B = input_map.GetPixel(U2, V1); - const glm::vec4 C = input_map.GetPixel(U1, V2); - const glm::vec4 D = input_map.GetPixel(U2, V2); + const ZEngine::Core::Maths::Vec4f A = input_map.GetPixel(U1, V1); + const ZEngine::Core::Maths::Vec4f B = input_map.GetPixel(U2, V1); + const ZEngine::Core::Maths::Vec4f C = input_map.GetPixel(U1, V2); + const ZEngine::Core::Maths::Vec4f D = input_map.GetPixel(U2, V2); - const glm::vec4 color = A * (1 - s) * (1 - t) + B * (s) * (1 - t) + C * (1 - s) * t + D * (s) * (t); + const ZEngine::Core::Maths::Vec4f color = A * (1 - s) * (1 - t) + B * (s) * (1 - t) + C * (1 - s) * t + D * (s) * (t); vertical_cross.SetPixel(i + face_offsets[face].x, j + face_offsets[face].y, color); } } diff --git a/ZEngine/ZEngine/Rendering/Cameras/Camera.h b/ZEngine/ZEngine/Rendering/Cameras/Camera.h index 3bfdfa28..cfa719f9 100644 --- a/ZEngine/ZEngine/Rendering/Cameras/Camera.h +++ b/ZEngine/ZEngine/Rendering/Cameras/Camera.h @@ -1,43 +1,39 @@ #pragma once +#include #include #include -#define GLM_FORCE_RADIANS -#define GLM_FORCE_DEPTH_ZERO_TO_ONE -#include -#include - namespace ZEngine::Rendering::Cameras { struct Camera { - float Fov = 0.0f; - float AspectRatio = 0.0f; - float ClipNear = 0.1f; - float ClipFar = 1000.0f; + float Fov = 0.0f; + float AspectRatio = 0.0f; + float ClipNear = 0.1f; + float ClipFar = 1000.0f; /* * Coordinate Vectors */ - glm::vec3 Position = {0.0f, 0.0f, 0.0f}; - glm::vec3 Up = {0.0f, 1.0f, 0.0f}; - const glm::vec3 WorldUp = {0.0f, 1.0f, 0.0f}; - glm::vec3 Right = {0.0f, 0.0f, 0.0f}; - glm::vec3 Forward = {0.0f, 0.0f, 0.0f}; - glm::vec3 Target = {0.0f, 0.0f, -1.0f}; + ZEngine::Core::Maths::Vec3f Position = {0.0f, 0.0f, 0.0f}; + ZEngine::Core::Maths::Vec3f Up = {0.0f, 1.0f, 0.0f}; + const ZEngine::Core::Maths::Vec3f WorldUp = {0.0f, 1.0f, 0.0f}; + ZEngine::Core::Maths::Vec3f Right = {0.0f, 0.0f, 0.0f}; + ZEngine::Core::Maths::Vec3f Forward = {0.0f, 0.0f, 0.0f}; + ZEngine::Core::Maths::Vec3f Target = {0.0f, 0.0f, -1.0f}; /* * Matrices */ - glm::mat4 View = glm::identity(); - glm::mat4 Projection = glm::identity(); - glm::mat4 ViewProjection = glm::identity(); + ZEngine::Core::Maths::Mat4f View = ZEngine::Core::Maths::Identity(); + ZEngine::Core::Maths::Mat4f Projection = ZEngine::Core::Maths::Identity(); + ZEngine::Core::Maths::Mat4f ViewProjection = ZEngine::Core::Maths::Identity(); /* * Extras data */ - CameraType Type = CameraType::UNDEFINED; + CameraType Type = CameraType::UNDEFINED; - virtual glm::mat4 GetViewMatrix() = 0; - virtual glm::mat4 GetPerspectiveMatrix() const = 0; - virtual glm::vec3 GetPosition() const = 0; + virtual ZEngine::Core::Maths::Mat4f GetViewMatrix() = 0; + virtual ZEngine::Core::Maths::Mat4f GetPerspectiveMatrix() const = 0; + virtual ZEngine::Core::Maths::Vec3f GetPosition() const = 0; }; ZDEFINE_PTR(Camera); } // namespace ZEngine::Rendering::Cameras diff --git a/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.cpp b/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.cpp index 368c5ac3..dab22236 100644 --- a/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.cpp +++ b/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.cpp @@ -1,11 +1,11 @@ +#include #include -#include namespace ZEngine::Rendering::Cameras { void PerspectiveCamera::Initialize(float field_of_view, float aspect_ratio, float clip_near, float clip_far, float yaw_rad, float pitch_rad) { - Fov = glm::radians(field_of_view); + Fov = ZEngine::Core::Maths::radians(field_of_view); AspectRatio = aspect_ratio; ClipNear = clip_near; ClipFar = clip_far; @@ -15,24 +15,24 @@ namespace ZEngine::Rendering::Cameras m_pitch_angle = pitch_rad; } - void PerspectiveCamera::SetTarget(const glm::vec3& target) + void PerspectiveCamera::SetTarget(const ZEngine::Core::Maths::Vec3f& target) { Target = target; } - void PerspectiveCamera::SetPosition(const glm::vec3& position) + void PerspectiveCamera::SetPosition(const ZEngine::Core::Maths::Vec3f& position) { Position = position; } - void PerspectiveCamera::SetProjectionMatrix(const glm::mat4& projection) + void PerspectiveCamera::SetProjectionMatrix(const ZEngine::Core::Maths::Mat4f& projection) { Projection = projection; } - void PerspectiveCamera::Update(float time_step, const glm::vec2& mouse_position, bool mouse_pressed) + void PerspectiveCamera::Update(float time_step, const ZEngine::Core::Maths::Vec2f& mouse_position, bool mouse_pressed) { - const glm::vec2 delta = (mouse_position - m_mouse_pos) * 0.003f; + const ZEngine::Core::Maths::Vec2f delta = (mouse_position - m_mouse_pos) * 0.003f; if (mouse_pressed) { if (Movement.MousePan) @@ -64,7 +64,7 @@ namespace ZEngine::Rendering::Cameras speed = std::min(speed, 100.0f); m_distance -= delta * speed; - m_distance = glm::clamp(static_cast(m_distance), 3.0f, ClipFar); + m_distance = ZEngine::Core::Maths::clamp(static_cast(m_distance), 3.0f, ClipFar); } void PerspectiveCamera::SetDistance(double distance) @@ -90,30 +90,30 @@ namespace ZEngine::Rendering::Cameras m_viewport_height = height; } - glm::mat4 PerspectiveCamera::GetViewMatrix() + ZEngine::Core::Maths::Mat4f PerspectiveCamera::GetViewMatrix() { - Position = Target - GetForward() * static_cast(m_distance); - auto orientation = GetOrientation(); - glm::mat4 view = glm::translate(glm::mat4(1.0f), Position) * glm::mat4_cast(orientation); - view = glm::inverse(view); + Position = Target - GetForward() * static_cast(m_distance); + auto orientation = GetOrientation(); + ZEngine::Core::Maths::Mat4f view = ZEngine::Core::Maths::translate(ZEngine::Core::Maths::Identity(), Position) * ZEngine::Core::Maths::quaternionToMat4(orientation); + view = view.Inverse(); return view; } - glm::mat4 PerspectiveCamera::GetPerspectiveMatrix() const + ZEngine::Core::Maths::Mat4f PerspectiveCamera::GetPerspectiveMatrix() const { /* * Ref : https://johannesugb.github.io/gpu-programming/why-do-opengl-proj-matrices-fail-in-vulkan/ * Unlike the article, for our implementation we decided to use have the y-axis Up. * For future Gfx API we may want to revisit/adapt it. */ - glm::mat4 I = glm::identity(); - I[2][2] = -1; + ZEngine::Core::Maths::Mat4f I = ZEngine::Core::Maths::Identity(); + I[2][2] = -1; - float inv_a = m_viewport_height / m_viewport_width; - float tan_half_fov = glm::tan(Fov / 2); - float far_minus_near = ClipFar - ClipNear; + float inv_a = m_viewport_height / m_viewport_width; + float tan_half_fov = ZEngine::Core::Maths::tan(Fov / 2); + float far_minus_near = ClipFar - ClipNear; - glm::mat4 P(0); + ZEngine::Core::Maths::Mat4f P(ZEngine::Core::Maths::Identity()); P[0][0] = (inv_a / tan_half_fov); P[1][1] = (1.0f / tan_half_fov); P[2][2] = (ClipFar / far_minus_near); @@ -123,28 +123,28 @@ namespace ZEngine::Rendering::Cameras return P * I; } - glm::vec3 PerspectiveCamera::GetPosition() const + ZEngine::Core::Maths::Vec3f PerspectiveCamera::GetPosition() const { return Position; } - glm::quat PerspectiveCamera::GetOrientation() + ZEngine::Core::Maths::Quaternion PerspectiveCamera::GetOrientation() { - return glm::quat(glm::vec3(-m_pitch_angle, -m_yaw_angle, 0.0f)); + return ZEngine::Core::Maths::fromEulerAngles(-m_pitch_angle, -m_yaw_angle, 0.0f); } - glm::vec3 PerspectiveCamera::GetForward() + ZEngine::Core::Maths::Vec3f PerspectiveCamera::GetForward() { - return glm::rotate(GetOrientation(), glm::vec3(0.0f, 0.0f, -1.0f)); + return ZEngine::Core::Maths::rotate(GetOrientation(), ZEngine::Core::Maths::Vec3f(0.0f, 0.0f, -1.0f)); } - glm::vec3 PerspectiveCamera::GetUp() + ZEngine::Core::Maths::Vec3f PerspectiveCamera::GetUp() { - return glm::rotate(GetOrientation(), WorldUp); + return ZEngine::Core::Maths::rotate(GetOrientation(), WorldUp); } - glm::vec3 PerspectiveCamera::GetRight() + ZEngine::Core::Maths::Vec3f PerspectiveCamera::GetRight() { - return glm::rotate(GetOrientation(), glm::vec3(1.0f, 0.0f, 0.0f)); + return ZEngine::Core::Maths::rotate(GetOrientation(), ZEngine::Core::Maths::Vec3f(1.0f, 0.0f, 0.0f)); } } // namespace ZEngine::Rendering::Cameras diff --git a/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.h b/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.h index 30e681af..2f0ba856 100644 --- a/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.h +++ b/ZEngine/ZEngine/Rendering/Cameras/PerspectiveCamera.h @@ -1,4 +1,5 @@ #pragma once +#include #include namespace ZEngine::Rendering::Cameras @@ -10,27 +11,27 @@ namespace ZEngine::Rendering::Cameras PerspectiveCamera() = default; virtual ~PerspectiveCamera() = default; - virtual void Initialize(float field_of_view, float aspect_ratio, float clip_near, float clip_far, float yaw_rad = 0.0f, float pitch_rad = 0.0f); + virtual void Initialize(float field_of_view, float aspect_ratio, float clip_near, float clip_far, float yaw_rad = 0.0f, float pitch_rad = 0.0f); - virtual void SetTarget(const glm::vec3& target); - virtual void SetPosition(const glm::vec3& position); - virtual void SetProjectionMatrix(const glm::mat4& projection); + virtual void SetTarget(const ZEngine::Core::Maths::Vec3f& target); + virtual void SetPosition(const ZEngine::Core::Maths::Vec3f& position); + virtual void SetProjectionMatrix(const ZEngine::Core::Maths::Mat4f& projection); - virtual void Update(float time_step, const glm::vec2& mouse_position, bool mouse_pressed); + virtual void Update(float time_step, const ZEngine::Core::Maths::Vec2f& mouse_position, bool mouse_pressed); - virtual void Zoom(float delta); - virtual void SetDistance(double distance); - virtual std::pair PanSpeed() const; - virtual void SetViewport(float width, float height); + virtual void Zoom(float delta); + virtual void SetDistance(double distance); + virtual std::pair PanSpeed() const; + virtual void SetViewport(float width, float height); - virtual glm::mat4 GetViewMatrix() override; - virtual glm::mat4 GetPerspectiveMatrix() const override; - virtual glm::vec3 GetPosition() const override; + virtual ZEngine::Core::Maths::Mat4f GetViewMatrix() override; + virtual ZEngine::Core::Maths::Mat4f GetPerspectiveMatrix() const override; + virtual ZEngine::Core::Maths::Vec3f GetPosition() const override; - glm::quat GetOrientation(); - glm::vec3 GetForward(); - glm::vec3 GetUp(); - glm::vec3 GetRight(); + ZEngine::Core::Maths::Quaternion GetOrientation(); + ZEngine::Core::Maths::Vec3f GetForward(); + ZEngine::Core::Maths::Vec3f GetUp(); + ZEngine::Core::Maths::Vec3f GetRight(); public: struct Movement @@ -41,16 +42,16 @@ namespace ZEngine::Rendering::Cameras } Movement; protected: - glm::vec2 m_mouse_pos = glm::vec2(0); - float m_mouse_speed = 0.8f; - float m_acceleration = 2.0f; - float m_damping = 0.2f; - float m_max_speed = 0.02f; - float m_fast_coef = 10.0f; - double m_distance = 10; - float m_yaw_angle = 0.0f; - float m_pitch_angle = 0.0f; - float m_viewport_width = 1.0f; - float m_viewport_height = 1.0f; + ZEngine::Core::Maths::Vec2f m_mouse_pos = ZEngine::Core::Maths::Vec2f(0.0f, 0.0f); + float m_mouse_speed = 0.8f; + float m_acceleration = 2.0f; + float m_damping = 0.2f; + float m_max_speed = 0.02f; + float m_fast_coef = 10.0f; + double m_distance = 10; + float m_yaw_angle = 0.0f; + float m_pitch_angle = 0.0f; + float m_viewport_width = 1.0f; + float m_viewport_height = 1.0f; }; } // namespace ZEngine::Rendering::Cameras diff --git a/ZEngine/ZEngine/Rendering/Components/TransformComponent.h b/ZEngine/ZEngine/Rendering/Components/TransformComponent.h index 4792ab7c..ab380fd9 100644 --- a/ZEngine/ZEngine/Rendering/Components/TransformComponent.h +++ b/ZEngine/ZEngine/Rendering/Components/TransformComponent.h @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace ZEngine::Rendering::Components { @@ -7,57 +7,57 @@ namespace ZEngine::Rendering::Components { TransformComponent() = default; ~TransformComponent() = default; - TransformComponent(glm::mat4& transform) : m_transform(transform) {} + TransformComponent(ZEngine::Core::Maths::Mat4f& transform) : m_transform(transform) {} - void SetPosition(const Maths::Vector3& value) + void SetPosition(const ZEngine::Core::Maths::Vec3f& value) { m_position = value; } - void SetScaleSize(const Maths::Vector3& value) + void SetScaleSize(const ZEngine::Core::Maths::Vec3f& value) { m_scale_size = value; } - void SetRotation(const Maths::Vector3& rad_angles) + void SetRotation(const ZEngine::Core::Maths::Vec3f& rad_angles) { m_rotation = rad_angles; } - void SetRotationEulerAngles(const Maths::Vector3& euler_angles) + void SetRotationEulerAngles(const ZEngine::Core::Maths::Vec3f& euler_angles) { - m_rotation = Maths::radians(euler_angles); + m_rotation = ZEngine::Core::Maths::radians(euler_angles); } - const Maths::Vector3& GetPosition() const + const ZEngine::Core::Maths::Vec3f& GetPosition() const { return m_position; } - const Maths::Vector3& GetScaleSize() const + const ZEngine::Core::Maths::Vec3f& GetScaleSize() const { return m_scale_size; } - const Maths::Vector3& GetRotation() const + const ZEngine::Core::Maths::Vec3f& GetRotation() const { return m_rotation; } - Maths::Vector3 GetRotationEulerAngles() const + ZEngine::Core::Maths::Vec3f GetRotationEulerAngles() const { - return Maths::degrees(m_rotation); + return ZEngine::Core::Maths::degrees(m_rotation); } - const Maths::mat4& GetTransform() + const ZEngine::Core::Maths::Mat4f& GetTransform() { return m_transform; } private: - Maths::Vector3 m_position; - Maths::Vector3 m_rotation; - Maths::Vector3 m_scale_size; - glm::mat4 m_transform; + ZEngine::Core::Maths::Vec3f m_position; + ZEngine::Core::Maths::Vec3f m_rotation; + ZEngine::Core::Maths::Vec3f m_scale_size; + ZEngine::Core::Maths::Mat4f m_transform; }; } // namespace ZEngine::Rendering::Components diff --git a/ZEngine/ZEngine/Rendering/GPUTypes.h b/ZEngine/ZEngine/Rendering/GPUTypes.h index fb2ba72f..4171cd87 100644 --- a/ZEngine/ZEngine/Rendering/GPUTypes.h +++ b/ZEngine/ZEngine/Rendering/GPUTypes.h @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace ZEngine::Rendering { @@ -10,12 +10,12 @@ namespace ZEngine::Rendering gpuvec3() = default; gpuvec3(float a, float b, float c) : x(a), y(b), z(c) {} gpuvec3(float v) : x(v), y(v), z(v) {} - explicit gpuvec3(const glm::vec3& v) : x(v.x), y(v.y), z(v.z) {} + explicit gpuvec3(const ZEngine::Core::Maths::Vec3f& v) : x(v.x), y(v.y), z(v.z) {} template T As() { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { return T(x, y); } @@ -25,7 +25,7 @@ namespace ZEngine::Rendering } } - gpuvec3& operator=(const glm::vec3& v) + gpuvec3& operator=(const ZEngine::Core::Maths::Vec3f& v) { x = v.x; y = v.y; @@ -41,16 +41,16 @@ namespace ZEngine::Rendering gpuvec4() = default; gpuvec4(float a, float b, float c, float d) : x(a), y(b), z(c), w(d) {} gpuvec4(float v) : x(v), y(v), z(v), w(v) {} - explicit gpuvec4(const glm::vec4& v) : x(v.x), y(v.y), z(v.z), w(v.w) {} + explicit gpuvec4(const ZEngine::Core::Maths::Vec4f& v) : x(v.x), y(v.y), z(v.z), w(v.w) {} template T As() { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { return T(x, y, z); } - else if constexpr (std::is_same_v) + else if constexpr (std::is_same_v) { return T(x, y); } @@ -60,7 +60,7 @@ namespace ZEngine::Rendering } } - gpuvec4& operator=(const glm::vec4& v) + gpuvec4& operator=(const ZEngine::Core::Maths::Vec4f& v) { x = v.x; y = v.y; diff --git a/ZEngine/ZEngine/Rendering/Geometries/IGeometry.h b/ZEngine/ZEngine/Rendering/Geometries/IGeometry.h index 48c6042e..21dec81c 100644 --- a/ZEngine/ZEngine/Rendering/Geometries/IGeometry.h +++ b/ZEngine/ZEngine/Rendering/Geometries/IGeometry.h @@ -1,6 +1,6 @@ #pragma once +#include #include -#include #include #include #include @@ -23,12 +23,12 @@ namespace ZEngine::Rendering::Geometries m_vertices = std::move(vertices); } - virtual const Maths::Matrix4& GetTransform() const + virtual const ZEngine::Core::Maths::Mat4f& GetTransform() const { return m_transform; } - virtual void SetTransform(const Maths::Matrix4& transform) + virtual void SetTransform(const ZEngine::Core::Maths::Mat4f& transform) { m_transform = transform; } @@ -44,7 +44,7 @@ namespace ZEngine::Rendering::Geometries } protected: - Maths::Matrix4 m_transform{Maths::Matrix4(1.0f)}; + ZEngine::Core::Maths::Mat4f m_transform{ZEngine::Core::Maths::Identity()}; std::vector m_vertices{}; GeometryType m_geometry_type{GeometryType::CUSTOM}; }; diff --git a/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.cpp b/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.cpp index 8144ec88..52d834af 100644 --- a/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.cpp +++ b/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.cpp @@ -1,11 +1,12 @@ #include using namespace ZEngine::Helpers; +using namespace ZEngine::Core::Maths; namespace ZEngine::Rendering::Materials { - StandardMaterial::StandardMaterial() : ShaderMaterial(Shaders::ShaderBuiltInType::STANDARD), m_tile_factor(1.0f), m_diffuse_tint_color(glm::vec4(1.0f)), m_specular_tint_color(glm::vec4(1.0f)), m_diffuse_map(Textures::CreateTexture(1, 1)), m_specular_map(Textures::CreateTexture(1, 1)) + StandardMaterial::StandardMaterial() : ShaderMaterial(Shaders::ShaderBuiltInType::STANDARD), m_tile_factor(1.0f), m_diffuse_tint_color(Vec4f(1.0f, 1.0f, 1.0f, 1.0f)), m_specular_tint_color(Vec4f(1.0f, 1.0f, 1.0f, 1.0f)), m_diffuse_map(Textures::CreateTexture(1, 1)), m_specular_map(Textures::CreateTexture(1, 1)) { m_material_name = typeid(*this).name(); } @@ -15,12 +16,12 @@ namespace ZEngine::Rendering::Materials m_tile_factor = value; } - void StandardMaterial::SetDiffuseTintColor(const glm::vec4& value) + void StandardMaterial::SetDiffuseTintColor(const Vec4f& value) { m_diffuse_tint_color = value; } - void StandardMaterial::SetSpecularTintColor(const glm::vec4& value) + void StandardMaterial::SetSpecularTintColor(const Vec4f& value) { m_specular_tint_color = value; } @@ -50,12 +51,12 @@ namespace ZEngine::Rendering::Materials return m_shininess; } - const Maths::Vector4& StandardMaterial::GetDiffuseTintColor() const + const Vec4f& StandardMaterial::GetDiffuseTintColor() const { return m_diffuse_tint_color; } - const Maths::Vector4& StandardMaterial::GetSpecularTintColor() const + const Vec4f& StandardMaterial::GetSpecularTintColor() const { return m_specular_tint_color; } diff --git a/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.h b/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.h index 0c37a380..644c0871 100644 --- a/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.h +++ b/ZEngine/ZEngine/Rendering/Materials/StandardMaterial.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include @@ -12,31 +12,31 @@ namespace ZEngine::Rendering::Materials explicit StandardMaterial(); virtual ~StandardMaterial() = default; - void SetTileFactor(float value); - void SetDiffuseTintColor(const glm::vec4& value); - void SetSpecularTintColor(const glm::vec4& value); + void SetTileFactor(float value); + void SetDiffuseTintColor(const ZEngine::Core::Maths::Vec4f& value); + void SetSpecularTintColor(const ZEngine::Core::Maths::Vec4f& value); - void SetShininess(float value); + void SetShininess(float value); - void Apply(const Helpers::Ref&) override; + void Apply(const Helpers::Ref&) override; - void SetSpecularMap(const Textures::Texture* texture); - void SetDiffuseMap(const Textures::Texture* texture); + void SetSpecularMap(const Textures::Texture* texture); + void SetDiffuseMap(const Textures::Texture* texture); - float GetTileFactor() const; - float GetShininess() const; - const Maths::Vector4& GetDiffuseTintColor() const; - const Maths::Vector4& GetSpecularTintColor() const; + float GetTileFactor() const; + float GetShininess() const; + const ZEngine::Core::Maths::Vec4f& GetDiffuseTintColor() const; + const ZEngine::Core::Maths::Vec4f& GetSpecularTintColor() const; - Textures::Texture* GetSpecularMap() const; - Textures::Texture* GetDiffuseMap() const; + Textures::Texture* GetSpecularMap() const; + Textures::Texture* GetDiffuseMap() const; private: - float m_shininess; - float m_tile_factor; - Maths::Vector4 m_diffuse_tint_color; - Maths::Vector4 m_specular_tint_color; - Textures::Texture* m_diffuse_map; - Textures::Texture* m_specular_map; + float m_shininess; + float m_tile_factor; + ZEngine::Core::Maths::Vec4f m_diffuse_tint_color; + ZEngine::Core::Maths::Vec4f m_specular_tint_color; + Textures::Texture* m_diffuse_map; + Textures::Texture* m_specular_map; }; } // namespace ZEngine::Rendering::Materials diff --git a/ZEngine/ZEngine/Rendering/Meshes/MeshLight.h b/ZEngine/ZEngine/Rendering/Meshes/MeshLight.h index 205a0bb5..5a47c957 100644 --- a/ZEngine/ZEngine/Rendering/Meshes/MeshLight.h +++ b/ZEngine/ZEngine/Rendering/Meshes/MeshLight.h @@ -1,5 +1,4 @@ #pragma once -#include #include #include diff --git a/ZEngine/ZEngine/Rendering/Renderers/Contracts/RendererDataContract.h b/ZEngine/ZEngine/Rendering/Renderers/Contracts/RendererDataContract.h index 053835a3..8a46567f 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/Contracts/RendererDataContract.h +++ b/ZEngine/ZEngine/Rendering/Renderers/Contracts/RendererDataContract.h @@ -1,17 +1,17 @@ #pragma once -#include +#include namespace ZEngine::Rendering::Renderers::Contracts { struct UBOCameraLayout { - alignas(16) glm::mat4 View = glm::mat4(1.0f); - alignas(16) glm::mat4 Projection = glm::mat4(1.0f); - alignas(16) glm::vec4 Position = glm::vec4(1.0f); + alignas(16) ZEngine::Core::Maths::Mat4f View = ZEngine::Core::Maths::Identity(); + alignas(16) ZEngine::Core::Maths::Mat4f Projection = ZEngine::Core::Maths::Identity(); + alignas(16) ZEngine::Core::Maths::Vec4f Position = ZEngine::Core::Maths::Vec4f(0.0f, 0.0f, 0.0f, 1.0f); }; struct UBOModelLayout { - alignas(16) glm::mat4 Model = glm::mat4(1.0f); + alignas(16) ZEngine::Core::Maths::Mat4f Model = ZEngine::Core::Maths::Identity(); }; } // namespace ZEngine::Rendering::Renderers::Contracts diff --git a/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp b/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp index fced200d..2f23a86e 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp +++ b/ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp @@ -9,6 +9,7 @@ using namespace ZEngine::Rendering::Renderers::Contracts; using namespace ZEngine::Helpers; using namespace ZEngine::Rendering::Specifications; using namespace ZEngine::Core::Containers; +using namespace ZEngine::Core::Maths; namespace ZEngine::Rendering::Renderers { @@ -100,7 +101,7 @@ namespace ZEngine::Rendering::Renderers void GraphicRenderer::DrawScene(Hardwares::CommandBufferPtr const cb, Cameras::CameraPtr const camera) { auto asset_manager = Managers::AssetManager::Instance(); - auto ubo_camera_data = UBOCameraLayout{.View = camera->GetViewMatrix(), .Projection = camera->GetPerspectiveMatrix(), .Position = glm::vec4(camera->GetPosition(), 1.0f)}; + auto ubo_camera_data = UBOCameraLayout{.View = camera->GetViewMatrix(), .Projection = camera->GetPerspectiveMatrix(), .Position = Vec4f(camera->GetPosition(), 1.0f)}; auto material_buffer_set = Device->StorageBufferSetManager.Access(RenderSceneData->MaterialBufferHandle); auto camera_buffer_set = Device->UniformBufferSetManager.Access(RenderSceneData->SceneCameraBufferHandle); diff --git a/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.cpp b/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.cpp index be8edbea..6d1bbb2f 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.cpp +++ b/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.cpp @@ -8,7 +8,7 @@ namespace ZEngine::Rendering::Renderers::Storages _UpdateBuffer(); } - GraphicVertex::GraphicVertex(const glm::vec3& position, const glm::vec3& normal, const glm::vec2& texture_coord) : IVertex() + GraphicVertex::GraphicVertex(const ZEngine::Core::Maths::Vec3f& position, const ZEngine::Core::Maths::Vec3f& normal, const ZEngine::Core::Maths::Vec2f& texture_coord) : IVertex() { m_position = position; m_normal = normal; @@ -17,22 +17,22 @@ namespace ZEngine::Rendering::Renderers::Storages _UpdateBuffer(); } - glm::vec3 GraphicVertex::GetPosition() const + ZEngine::Core::Maths::Vec3f GraphicVertex::GetPosition() const { return m_position; } - glm::vec3 GraphicVertex::GetNormal() const + ZEngine::Core::Maths::Vec3f GraphicVertex::GetNormal() const { return m_normal; } - glm::vec2 GraphicVertex::GetTextureCoord() const + ZEngine::Core::Maths::Vec2f GraphicVertex::GetTextureCoord() const { return m_texture_coord; } - void GraphicVertex::SetPosition(const glm::vec3& value) + void GraphicVertex::SetPosition(const ZEngine::Core::Maths::Vec3f& value) { m_position = value; m_buffer[0] = m_position.x; @@ -40,7 +40,7 @@ namespace ZEngine::Rendering::Renderers::Storages m_buffer[2] = m_position.z; } - void GraphicVertex::SetNormal(const glm::vec3& value) + void GraphicVertex::SetNormal(const ZEngine::Core::Maths::Vec3f& value) { m_normal = value; m_buffer[3] = m_normal.x; @@ -48,17 +48,17 @@ namespace ZEngine::Rendering::Renderers::Storages m_buffer[5] = m_normal.z; } - void GraphicVertex::SetTextureCoord(const glm::vec2& value) + void GraphicVertex::SetTextureCoord(const ZEngine::Core::Maths::Vec2f& value) { m_texture_coord = value; m_buffer[6] = m_texture_coord.x; m_buffer[7] = m_texture_coord.y; } - void GraphicVertex::TransformPosition(const glm::mat4& matrix) + void GraphicVertex::TransformPosition(const ZEngine::Core::Maths::Mat4f& matrix) { - glm::vec4 position = glm::vec4(m_position, 1.0f); - position = matrix * position; + ZEngine::Core::Maths::Vec4f position = ZEngine::Core::Maths::Vec4f(m_position, 1.0f); + position = matrix * position; SetPosition({position.x, position.y, position.z}); } diff --git a/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.h b/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.h index 61b5420a..80bedbbd 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.h +++ b/ZEngine/ZEngine/Rendering/Renderers/Storages/GraphicVertex.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include namespace ZEngine::Rendering::Renderers::Storages @@ -14,19 +13,19 @@ namespace ZEngine::Rendering::Renderers::Storages public: explicit GraphicVertex(); - explicit GraphicVertex(const glm::vec3& position, const glm::vec3& normal = {0.0f, 0.0f, 0.0f}, const glm::vec2& texture_coord = {0.0f, 0.0f}); + explicit GraphicVertex(const ZEngine::Core::Maths::Vec3f& position, const ZEngine::Core::Maths::Vec3f& normal = {0.0f, 0.0f, 0.0f}, const ZEngine::Core::Maths::Vec2f& texture_coord = {0.0f, 0.0f}); ~GraphicVertex() = default; - glm::vec3 GetPosition() const; - glm::vec3 GetNormal() const; - glm::vec2 GetTextureCoord() const; + ZEngine::Core::Maths::Vec3f GetPosition() const; + ZEngine::Core::Maths::Vec3f GetNormal() const; + ZEngine::Core::Maths::Vec2f GetTextureCoord() const; - void SetPosition(const glm::vec3& value); - void SetNormal(const glm::vec3& value); - void SetTextureCoord(const glm::vec2& value); + void SetPosition(const ZEngine::Core::Maths::Vec3f& value); + void SetNormal(const ZEngine::Core::Maths::Vec3f& value); + void SetTextureCoord(const ZEngine::Core::Maths::Vec2f& value); - void TransformPosition(const glm::mat4& matrix); + void TransformPosition(const ZEngine::Core::Maths::Mat4f& matrix); const std::array& GetData() const { diff --git a/ZEngine/ZEngine/Rendering/Renderers/Storages/IVertex.h b/ZEngine/ZEngine/Rendering/Renderers/Storages/IVertex.h index 3d42bdf2..3025d8a4 100644 --- a/ZEngine/ZEngine/Rendering/Renderers/Storages/IVertex.h +++ b/ZEngine/ZEngine/Rendering/Renderers/Storages/IVertex.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include @@ -8,9 +8,9 @@ namespace ZEngine::Rendering::Renderers::Storages struct IVertex { - glm::vec3 m_position{0.0f, 0.0f, 0.0f}; - glm::vec3 m_normal{0.0f, 0.0f, 0.0f}; - glm::vec2 m_texture_coord{0.0f, 0.0f}; + ZEngine::Core::Maths::Vec3f m_position{0.0f, 0.0f, 0.0f}; + ZEngine::Core::Maths::Vec3f m_normal{0.0f, 0.0f, 0.0f}; + ZEngine::Core::Maths::Vec2f m_texture_coord{0.0f, 0.0f}; static const std::array& GetVertexInputBindingDescription() { diff --git a/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.cpp b/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.cpp index a79ad1e3..0ec1dad1 100644 --- a/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.cpp +++ b/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.cpp @@ -109,7 +109,7 @@ namespace ZEngine::Rendering::Scenes return name; } - void SceneEntity::SetTransform(glm::mat4 transform) + void SceneEntity::SetTransform(Core::Maths::Mat4f transform) { if (auto scene = m_weak_scene.lock()) { @@ -121,9 +121,9 @@ namespace ZEngine::Rendering::Scenes } } - glm::mat4 SceneEntity::GetTransform() const + Core::Maths::Mat4f SceneEntity::GetTransform() const { - glm::mat4 transform = {}; + Core::Maths::Mat4f transform = {}; if (auto scene = m_weak_scene.lock()) { if (m_node > 0) @@ -269,7 +269,7 @@ namespace ZEngine::Rendering::Scenes for (unsigned i = 0; i < device->SwapchainImageCount; ++i) { - // transform_buf->SetData(i, SceneData->GlobalTransforms); + // transform_buf->SetData(i, SceneData->GlobalTransforms); // vert_buf->SetData(i, SceneData->Vertices); // ind_buf->SetData(i, SceneData->Indices); // material_buf->SetData(i, SceneData->Materials); @@ -567,14 +567,14 @@ namespace ZEngine::Rendering::Scenes return SceneData->NodeNames.contains(node_identifier) ? SceneData->Names[SceneData->NodeNames[node_identifier]] : std::string_view(); } - glm::mat4& GraphicScene::GetSceneNodeLocalTransform(int node_identifier) + Core::Maths::Mat4f& GraphicScene::GetSceneNodeLocalTransform(int node_identifier) { std::lock_guard lock(m_mutex); ZENGINE_VALIDATE_ASSERT((node_identifier > INVALID_NODE_ID) && (node_identifier < SceneData->LocalTransforms.size()), "node identifier is invalid") return SceneData->LocalTransforms[node_identifier]; } - glm::mat4& GraphicScene::GetSceneNodeGlobalTransform(int node_identifier) + Core::Maths::Mat4f& GraphicScene::GetSceneNodeGlobalTransform(int node_identifier) { std::lock_guard lock(m_mutex); ZENGINE_VALIDATE_ASSERT(node_identifier > INVALID_NODE_ID && node_identifier < SceneData->GlobalTransforms.size(), "node identifier is invalid") diff --git a/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.h b/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.h index 0ef1f1bf..be0198ba 100644 --- a/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.h +++ b/ZEngine/ZEngine/Rendering/Scenes/GraphicScene.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -32,8 +33,8 @@ namespace ZEngine::Rendering::Scenes uint32_t CurrentIndexOffset = 0; Core::Containers::Array Hierarchies = {}; - Core::Containers::Array LocalTransforms = {}; - Core::Containers::Array GlobalTransforms = {}; + Core::Containers::Array LocalTransforms = {}; + Core::Containers::Array GlobalTransforms = {}; Core::Containers::Array Vertices = {}; Core::Containers::Array Indices = {}; @@ -77,8 +78,8 @@ namespace ZEngine::Rendering::Scenes uint32_t SIndexDataSize = 0; uint32_t SMeshCountOffset = 0; std::vector NodeHierarchies = {}; - std::vector LocalTransforms = {}; - std::vector GlobalTransforms = {}; + std::vector LocalTransforms = {}; + std::vector GlobalTransforms = {}; std::map> LevelSceneNodeChangedMap = {}; /* * New Properties @@ -126,9 +127,9 @@ namespace ZEngine::Rendering::Scenes ~SceneEntity() = default; void SetName(std::string_view name); - void SetTransform(glm::mat4 transform); + void SetTransform(Core::Maths::Mat4f transform); std::string_view GetName() const; - glm::mat4 GetTransform() const; + Core::Maths::Mat4f GetTransform() const; int GetNode() const; template @@ -214,8 +215,8 @@ namespace ZEngine::Rendering::Scenes int GetSceneNodeFirstChild(int node_identifier); std::vector GetSceneNodeSiblingCollection(int node_identifier); std::string_view GetSceneNodeName(int node_identifier); - glm::mat4& GetSceneNodeLocalTransform(int node_identifier); - glm::mat4& GetSceneNodeGlobalTransform(int node_identifier); + Core::Maths::Mat4f& GetSceneNodeLocalTransform(int node_identifier); + Core::Maths::Mat4f& GetSceneNodeGlobalTransform(int node_identifier); const SceneNodeHierarchy& GetSceneNodeHierarchy(int node_identifier); SceneEntity GetSceneNodeEntityWrapper(int node_identifier); std::future SetSceneNodeNameAsync(int node_identifier, std::string_view node_name); diff --git a/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.cpp b/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.cpp index 729507e5..8a20f886 100644 --- a/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.cpp +++ b/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.cpp @@ -22,9 +22,9 @@ using namespace ZEngine::Core; namespace YAML { template <> - struct convert + struct convert { - static Node encode(const glm::vec3& value) + static Node encode(const Maths::Vec3f& value) { Node node; node.push_back(value.x); @@ -32,7 +32,7 @@ namespace YAML node.push_back(value.z); } - static bool decode(const Node& node, glm::vec3& value) + static bool decode(const Node& node, Maths::Vec3f& value) { if (!node.IsSequence() || node.size() != 3) { @@ -47,9 +47,9 @@ namespace YAML }; template <> - struct convert + struct convert { - static Node encode(const glm::vec4& value) + static Node encode(const Maths::Vec4f& value) { Node node; node.push_back(value.x); @@ -58,7 +58,7 @@ namespace YAML node.push_back(value.w); } - static bool decode(const Node& node, glm::vec4& value) + static bool decode(const Node& node, Maths::Vec4f& value) { if (!node.IsSequence() || node.size() != 4) { diff --git a/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.h b/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.h index 772c71e0..f2454085 100644 --- a/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.h +++ b/ZEngine/ZEngine/Serializers/GraphicScene3DSerializer.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include #include @@ -8,21 +8,21 @@ namespace ZEngine::Serializers { - inline YAML::Emitter& operator<<(YAML::Emitter& emitter, const ZEngine::Maths::Vector4& v) + inline YAML::Emitter& operator<<(YAML::Emitter& emitter, const ZEngine::Core::Maths::Vec4f& v) { emitter << YAML::Flow; emitter << YAML::BeginSeq << v.x << v.y << v.z << v.w << YAML::EndSeq; return emitter; } - inline YAML::Emitter& operator<<(YAML::Emitter& emitter, const ZEngine::Maths::Vector3& v) + inline YAML::Emitter& operator<<(YAML::Emitter& emitter, const ZEngine::Core::Maths::Vec3f& v) { emitter << YAML::Flow; emitter << YAML::BeginSeq << v.x << v.y << v.z << YAML::EndSeq; return emitter; } - inline YAML::Emitter& operator<<(YAML::Emitter& emitter, const ZEngine::Maths::Vector2& v) + inline YAML::Emitter& operator<<(YAML::Emitter& emitter, const ZEngine::Core::Maths::Vec2f& v) { emitter << YAML::Flow; emitter << YAML::BeginSeq << v.x << v.y << YAML::EndSeq; diff --git a/ZEngine/tests/Maths/Matrix_test.cpp b/ZEngine/tests/Maths/Matrix_test.cpp index 83df6cc0..fa00ed95 100644 --- a/ZEngine/tests/Maths/Matrix_test.cpp +++ b/ZEngine/tests/Maths/Matrix_test.cpp @@ -410,3 +410,75 @@ TEST(MatrixTest, DeterminantFloat) auto d = Determinant(m3); EXPECT_NEAR(Determinant(m3), 1.0f, EPSILON); } + +TEST(MatrixTest, TranslateFunction) +{ + Mat4f identity = Identity(); + Vec3f translation(5.0f, -3.0f, 2.0f); + Mat4f result = translate(identity, translation); + + EXPECT_NEAR(result(0, 3), translation.x, EPSILON); + EXPECT_NEAR(result(1, 3), translation.y, EPSILON); + EXPECT_NEAR(result(2, 3), translation.z, EPSILON); + + EXPECT_NEAR(result(0, 0), 1.0f, EPSILON); + EXPECT_NEAR(result(1, 1), 1.0f, EPSILON); + EXPECT_NEAR(result(2, 2), 1.0f, EPSILON); + EXPECT_NEAR(result(3, 3), 1.0f, EPSILON); + + Mat4f existing = Identity(); + existing(0, 3) = 10.0f; + existing(1, 3) = 20.0f; + existing(2, 3) = 30.0f; + + Vec3f additional(1.0f, -2.0f, 3.0f); + Mat4f combined = translate(existing, additional); + + EXPECT_NEAR(combined(0, 3), 11.0f, EPSILON); + EXPECT_NEAR(combined(1, 3), 18.0f, EPSILON); + EXPECT_NEAR(combined(2, 3), 33.0f, EPSILON); +} + +TEST(MatrixTest, DecomposeTransformComponent) +{ + // Test 1: Identity matrix + Mat4f identity = Identity(); + Vec3f translation, rotation, scale; + + bool success = DecomposeTransformComponent(identity, translation, rotation, scale); + EXPECT_TRUE(success); + EXPECT_NEAR(translation.x, 0.0f, EPSILON); + EXPECT_NEAR(translation.y, 0.0f, EPSILON); + EXPECT_NEAR(translation.z, 0.0f, EPSILON); + EXPECT_NEAR(scale.x, 1.0f, EPSILON); + EXPECT_NEAR(scale.y, 1.0f, EPSILON); + EXPECT_NEAR(scale.z, 1.0f, EPSILON); + + Mat4f translationMatrix = Identity(); + translationMatrix(0, 3) = 5.0f; + translationMatrix(1, 3) = -3.0f; + translationMatrix(2, 3) = 2.0f; + + success = DecomposeTransformComponent(translationMatrix, translation, rotation, scale); + EXPECT_TRUE(success); + EXPECT_NEAR(translation.x, 5.0f, EPSILON); + EXPECT_NEAR(translation.y, -3.0f, EPSILON); + EXPECT_NEAR(translation.z, 2.0f, EPSILON); + EXPECT_NEAR(scale.x, 1.0f, EPSILON); + EXPECT_NEAR(scale.y, 1.0f, EPSILON); + EXPECT_NEAR(scale.z, 1.0f, EPSILON); + + Mat4f scaleMatrix = Identity(); + scaleMatrix(0, 0) = 2.0f; + scaleMatrix(1, 1) = 0.5f; + scaleMatrix(2, 2) = 3.0f; + + success = DecomposeTransformComponent(scaleMatrix, translation, rotation, scale); + EXPECT_TRUE(success); + EXPECT_NEAR(translation.x, 0.0f, EPSILON); + EXPECT_NEAR(translation.y, 0.0f, EPSILON); + EXPECT_NEAR(translation.z, 0.0f, EPSILON); + EXPECT_NEAR(scale.x, 2.0f, EPSILON); + EXPECT_NEAR(scale.y, 0.5f, EPSILON); + EXPECT_NEAR(scale.z, 3.0f, EPSILON); +} \ No newline at end of file diff --git a/ZEngine/tests/Maths/Quaternion_test.cpp b/ZEngine/tests/Maths/Quaternion_test.cpp index 550c2b90..584c73c8 100644 --- a/ZEngine/tests/Maths/Quaternion_test.cpp +++ b/ZEngine/tests/Maths/Quaternion_test.cpp @@ -404,3 +404,79 @@ TEST(QuaternionTest, ChainedOperations) float length = sqrt(result.dot(result)); EXPECT_NEAR(length, 1.0f, EPSILON); } + +TEST(QuaternionTest, QuaternionToMat4) +{ + Quaternion identity(0.0f, 0.0f, 0.0f, 1.0f); + Mat4f result = quaternionToMat4(identity); + + Mat4f expectedIdentity = Identity(); + for (size_t i = 0; i < 4; ++i) + { + for (size_t j = 0; j < 4; ++j) + { + EXPECT_NEAR(result(i, j), expectedIdentity(i, j), EPSILON); + } + } + + float angle = radians(90.0f); + Quaternion rotZ(0.0f, 0.0f, sin(angle * 0.5f), cos(angle * 0.5f)); + Mat4f rotMatrix = quaternionToMat4(rotZ); + + EXPECT_NEAR(rotMatrix(0, 0), 0.0f, EPSILON); + EXPECT_NEAR(rotMatrix(0, 1), -1.0f, EPSILON); + EXPECT_NEAR(rotMatrix(1, 0), 1.0f, EPSILON); + EXPECT_NEAR(rotMatrix(1, 1), 0.0f, EPSILON); + EXPECT_NEAR(rotMatrix(2, 2), 1.0f, EPSILON); + EXPECT_NEAR(rotMatrix(3, 3), 1.0f, EPSILON); + + Quaternion arbitrary(0.1f, 0.2f, 0.3f, 0.4f); + arbitrary = arbitrary.normalize(); + Mat4f arbMatrix = quaternionToMat4(arbitrary); + + EXPECT_NEAR(arbMatrix(0, 3), 0.0f, EPSILON); + EXPECT_NEAR(arbMatrix(1, 3), 0.0f, EPSILON); + EXPECT_NEAR(arbMatrix(2, 3), 0.0f, EPSILON); + EXPECT_NEAR(arbMatrix(3, 0), 0.0f, EPSILON); + EXPECT_NEAR(arbMatrix(3, 1), 0.0f, EPSILON); + EXPECT_NEAR(arbMatrix(3, 2), 0.0f, EPSILON); + EXPECT_NEAR(arbMatrix(3, 3), 1.0f, EPSILON); +} + +TEST(TransformTest, QuaternionRotate) +{ + Quaternion identity(0.0f, 0.0f, 0.0f, 1.0f); + Vec3f vector(1.0f, 2.0f, 3.0f); + Vec3f result = rotate(identity, vector); + + EXPECT_NEAR(result.x, vector.x, EPSILON); + EXPECT_NEAR(result.y, vector.y, EPSILON); + EXPECT_NEAR(result.z, vector.z, EPSILON); + + float angle = radians(90.0f); + Quaternion rotZ(0.0f, 0.0f, sin(angle * 0.5f), cos(angle * 0.5f)); + Vec3f xAxis(1.0f, 0.0f, 0.0f); + Vec3f rotatedX = rotate(rotZ, xAxis); + + EXPECT_NEAR(rotatedX.x, 0.0f, EPSILON); + EXPECT_NEAR(rotatedX.y, 1.0f, EPSILON); + EXPECT_NEAR(rotatedX.z, 0.0f, EPSILON); + + angle = radians(180.0f); + Quaternion rot180Y(0.0f, sin(angle * 0.5f), 0.0f, cos(angle * 0.5f)); + Vec3f zAxis(0.0f, 0.0f, 1.0f); + Vec3f rotatedZ = rotate(rot180Y, zAxis); + + EXPECT_NEAR(rotatedZ.x, 0.0f, EPSILON); + EXPECT_NEAR(rotatedZ.y, 0.0f, EPSILON); + EXPECT_NEAR(rotatedZ.z, -1.0f, EPSILON); + + Quaternion arbitrary(0.1f, 0.2f, 0.3f, 0.4f); + arbitrary = arbitrary.normalize(); + Vec3f originalVec(3.0f, 4.0f, 5.0f); + Vec3f rotatedVec = rotate(arbitrary, originalVec); + + float originalMagnitude = originalVec.magnitude(); + float rotatedMagnitude = rotatedVec.magnitude(); + EXPECT_NEAR(originalMagnitude, rotatedMagnitude, EPSILON); +} \ No newline at end of file diff --git a/ZEngine/tests/Memory/bitmap_test.cpp b/ZEngine/tests/Memory/bitmap_test.cpp index 8fdeeed8..aa4be8fa 100644 --- a/ZEngine/tests/Memory/bitmap_test.cpp +++ b/ZEngine/tests/Memory/bitmap_test.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -17,9 +18,9 @@ static bool approximatelyEqual(float a, float b, float epsilon) TEST(BitmapTest, GetOrSetPixel) { - glm::vec4 p(0.5, 0.5, 0.8, 0.0); + ZEngine::Core::Maths::Vec4f p(0.5, 0.5, 0.8, 0.0); - Bitmap bitmap(100, 100, 3, BitmapFormat::UNSIGNED_BYTE); + Bitmap bitmap(100, 100, 3, BitmapFormat::UNSIGNED_BYTE); bitmap.SetPixel(0, 0, p); auto pp = bitmap.GetPixel(0, 0); diff --git a/__externals/externals.cmake b/__externals/externals.cmake index e90d7436..b185b4e4 100644 --- a/__externals/externals.cmake +++ b/__externals/externals.cmake @@ -3,7 +3,6 @@ set(EXTERNAL_INCLUDE_DIRS ${EXTERNAL_DIR}/Vulkan-Headers/build/install/include ${EXTERNAL_DIR}/fmt/include - ${EXTERNAL_DIR}/glm/glm ${EXTERNAL_DIR}/imgui/src ${EXTERNAL_DIR}/tlsf/src ${EXTERNAL_DIR}/rapidhash/src @@ -43,7 +42,6 @@ target_link_libraries(imported::External_obeliskLibs INTERFACE target_link_libraries(imported::External_libs INTERFACE vulkan fmt - glm imgui spdlog glfw diff --git a/__externals/glm b/__externals/glm deleted file mode 160000 index 84f2045a..00000000 --- a/__externals/glm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 84f2045a79a4aa2454801a98e2de0401bd9c8aee From 04865f4bd5b4b92b58a2f9f3abda12fc7884b208 Mon Sep 17 00:00:00 2001 From: Jennife Chukwu Date: Mon, 1 Sep 2025 22:28:03 +0100 Subject: [PATCH 2/2] normalize test --- ZEngine/tests/Maths/Quaternion_test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ZEngine/tests/Maths/Quaternion_test.cpp b/ZEngine/tests/Maths/Quaternion_test.cpp index 584c73c8..a564c304 100644 --- a/ZEngine/tests/Maths/Quaternion_test.cpp +++ b/ZEngine/tests/Maths/Quaternion_test.cpp @@ -443,7 +443,7 @@ TEST(QuaternionTest, QuaternionToMat4) EXPECT_NEAR(arbMatrix(3, 3), 1.0f, EPSILON); } -TEST(TransformTest, QuaternionRotate) +TEST(QuaternionTest, QuaternionRotate) { Quaternion identity(0.0f, 0.0f, 0.0f, 1.0f); Vec3f vector(1.0f, 2.0f, 3.0f); @@ -464,8 +464,9 @@ TEST(TransformTest, QuaternionRotate) angle = radians(180.0f); Quaternion rot180Y(0.0f, sin(angle * 0.5f), 0.0f, cos(angle * 0.5f)); - Vec3f zAxis(0.0f, 0.0f, 1.0f); - Vec3f rotatedZ = rotate(rot180Y, zAxis); + rot180Y = rot180Y.normalize(); + Vec3f zAxis(0.0f, 0.0f, 1.0f); + Vec3f rotatedZ = rotate(rot180Y, zAxis); EXPECT_NEAR(rotatedZ.x, 0.0f, EPSILON); EXPECT_NEAR(rotatedZ.y, 0.0f, EPSILON);