diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f9445a..049a3d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,6 @@ include(dependencies/vulkan) include(dependencies/catch2) add_subdirectory(src) -add_subdirectory(tests) file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/bin/shaders") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/bin/assets") diff --git a/cmake_modules/dependencies/fmt.cmake b/cmake_modules/dependencies/fmt.cmake deleted file mode 100644 index e1691e9..0000000 --- a/cmake_modules/dependencies/fmt.cmake +++ /dev/null @@ -1,9 +0,0 @@ -if (NOT HAS_STD_FORMAT AND NOT ATLAS_IGNORE_STD_FORMAT EQUAL 1) - add_subdirectory(${CMAKE_SOURCE_DIR}/dependencies/fmt) - set(ATLAS_LINK_FMT 1) - option(SPDLOG_FMT_EXTERNAL "" ON) -else () - option(SPDLOG_FMT_EXTERNAL "" OFF) - #dummy lib to link to - set(ATLAS_LINK_FMT 0) -endif () diff --git a/cmake_modules/dependencies/spdlog.cmake b/cmake_modules/dependencies/spdlog.cmake index 1c0c90e..02d35f0 100644 --- a/cmake_modules/dependencies/spdlog.cmake +++ b/cmake_modules/dependencies/spdlog.cmake @@ -1 +1,2 @@ +set(SPDLOG_USE_STD_FORMAT ON) add_subdirectory(${CMAKE_SOURCE_DIR}/dependencies/spdlog ${CMAKE_BINARY_DIR}/bin) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c404f7..d12052e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(vma) add_subdirectory(engine) add_subdirectory(objectloaders) add_subdirectory(editor) +add_subdirectory(tests) \ No newline at end of file diff --git a/src/editor/CMakeLists.txt b/src/editor/CMakeLists.txt index 30cc735..d05eb43 100644 --- a/src/editor/CMakeLists.txt +++ b/src/editor/CMakeLists.txt @@ -12,4 +12,5 @@ file(GLOB_RECURSE SOURCE_FILES add_executable(TitorEditor ${SOURCE_FILES}) target_link_libraries(TitorEditor PRIVATE FGLEngine) target_include_directories(TitorEditor PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) -target_compile_definitions(TitorEditor PUBLIC IDHAN_EDITOR) \ No newline at end of file +target_compile_definitions(TitorEditor PUBLIC TITOR_EDITOR) +target_compile_features(TitorEditor PRIVATE cxx_std_23) diff --git a/src/editor/src/gui/FileBrowser.cpp b/src/editor/src/gui/FileBrowser.cpp index efdf158..0cbd1e7 100644 --- a/src/editor/src/gui/FileBrowser.cpp +++ b/src/editor/src/gui/FileBrowser.cpp @@ -4,6 +4,8 @@ #include "FileBrowser.hpp" +#include + #include "engine/assets/stores.hpp" #include "engine/filesystem/scanner/FileScanner.hpp" #include "engine/filesystem/types.hpp" diff --git a/src/editor/src/gui/camera.cpp b/src/editor/src/gui/camera.cpp index 8054ffd..9df728a 100644 --- a/src/editor/src/gui/camera.cpp +++ b/src/editor/src/gui/camera.cpp @@ -13,6 +13,84 @@ namespace fgl::engine::gui { + void handleCameraInput( const FrameInfo& info, Camera& camera ) + { + const auto delta_time { info.delta_time }; + + //If we aren't focused. We just return. + if ( !ImGui::IsWindowFocused() ) return; + + auto& original_rotation { camera.getTransform().rotation }; + + auto& yaw_change { original_rotation }; + auto& pitch_change { original_rotation }; + + constexpr double pitch_rate { 1.0 }; + constexpr double yaw_rate { 1.0 }; + + if ( ImGui::IsKeyDown( ImGuiKey_DownArrow ) ) + { + yaw_change.pitch() -= ( delta_time * pitch_rate ); + } + + if ( ImGui::IsKeyDown( ImGuiKey_UpArrow ) ) + { + yaw_change.pitch() += ( delta_time * pitch_rate ); + } + + if ( ImGui::IsKeyDown( ImGuiKey_LeftArrow ) ) + { + pitch_change.yaw() -= ( delta_time * yaw_rate ); + } + + if ( ImGui::IsKeyDown( ImGuiKey_RightArrow ) ) + { + pitch_change.yaw() += ( delta_time * yaw_rate ); + } + + Vector move_dir { 0.0f }; + + const Vector forward { camera.getForward() }; + const Vector up { camera.getUp() }; + const Vector right { camera.getRight() }; + + if ( ImGui::IsKeyDown( ImGuiKey_W ) ) + { + move_dir += forward; + } + + if ( ImGui::IsKeyDown( ImGuiKey_S ) ) + { + move_dir -= forward; + } + + if ( ImGui::IsKeyDown( ImGuiKey_D ) ) + { + move_dir += right; + } + + if ( ImGui::IsKeyDown( ImGuiKey_A ) ) + { + move_dir -= right; + } + + if ( ImGui::IsKeyDown( ImGuiKey_E ) ) + { + move_dir += up; + } + + if ( ImGui::IsKeyDown( ImGuiKey_Q ) ) + { + move_dir -= up; + } + + constexpr float move_speed { 0.5f }; + + camera.getTransform().translation += move_dir * ( move_speed * delta_time ); + + camera.updateMatrix(); + } + void drawCameraOutputs( FrameInfo& info ) { auto& camera_list { info.m_camera_list }; @@ -38,6 +116,12 @@ namespace fgl::engine::gui nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar ); + handleCameraInput( info, camera ); + + const auto [ x, y ] = ImGui::GetWindowSize(); + + camera.setExtent( { static_cast< std::uint32_t >( x ), static_cast< std::uint32_t >( y ) } ); + drawRenderingOutputs( info, camera ); ImGui::End(); diff --git a/src/editor/src/gui/core.cpp b/src/editor/src/gui/core.cpp index e376874..fcbcae9 100644 --- a/src/editor/src/gui/core.cpp +++ b/src/editor/src/gui/core.cpp @@ -93,7 +93,7 @@ namespace fgl::engine::gui inline void prepareDock( ImGuiID& primary_id ) { ImGui::DockBuilderRemoveNode( primary_id ); - ImGui::DockBuilderAddNode( primary_id, ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_PassthruCentralNode ); + ImGui::DockBuilderAddNode( primary_id, ImGuiDockNodeFlags_PassthruCentralNode ); ImGui::DockBuilderSetNodeSize( primary_id, ImGui::GetMainViewport()->WorkSize ); diff --git a/src/editor/src/gui/helpers.hpp b/src/editor/src/gui/helpers.hpp index e93d3ff..53c4c7a 100644 --- a/src/editor/src/gui/helpers.hpp +++ b/src/editor/src/gui/helpers.hpp @@ -15,31 +15,38 @@ namespace fgl::engine::gui inline void dragFloat3Rot( const char* const label, Rotation& rot ) { + enum Axis + { + Pitch = 0, + Roll = 1, + Yaw = 2 + }; + float dat[ 3 ] { rot.pitch(), rot.roll(), rot.yaw() }; - const float c_dat[ 3 ] { dat[ 0 ], dat[ 1 ], dat[ 2 ] }; + const float c_dat[ 3 ] { dat[ Pitch ], dat[ Roll ], dat[ Yaw ] }; constexpr float speed { 0.01f }; ImGui::DragFloat3( label, dat, speed ); - const float diff[ 3 ] { c_dat[ 0 ] - dat[ 0 ], c_dat[ 1 ] - dat[ 1 ], c_dat[ 2 ] - dat[ 2 ] }; + const float diff[ 3 ] { c_dat[ Pitch ] - dat[ Pitch ], c_dat[ Roll ] - dat[ Roll ], c_dat[ Yaw ] - dat[ Yaw ] }; constexpr float epsilon { std::numeric_limits< float >::epsilon() }; - const bool changed[ 3 ] { diff[ 0 ] > epsilon || diff[ 0 ]< epsilon, diff[ 1 ] > epsilon - || diff[ 1 ]< epsilon, diff[ 2 ] > epsilon || diff[ 2 ] < epsilon }; + const bool changed[ 3 ] { diff[ Pitch ] > epsilon || diff[ Pitch ]< -epsilon, diff[ Roll ] > epsilon + || diff[ Roll ]< -epsilon, diff[ Yaw ] > epsilon || diff[ Yaw ] < -epsilon }; - if ( changed[ 0 ] ) + if ( changed[ Pitch ] ) { - rot.pitch() += diff[ 0 ]; + rot.pitch() += diff[ Pitch ]; } - if ( changed[ 1 ] ) + if ( changed[ Roll ] ) { - rot.roll() += diff[ 1 ]; + rot.roll() += diff[ Roll ]; } - if ( changed[ 2 ] ) + if ( changed[ Yaw ] ) { - rot.yaw() += diff[ 2 ]; + rot.yaw() += diff[ Yaw ]; } } diff --git a/src/editor/src/gui/preview.cpp b/src/editor/src/gui/preview.cpp index e0f5e5c..ef9ab51 100644 --- a/src/editor/src/gui/preview.cpp +++ b/src/editor/src/gui/preview.cpp @@ -177,7 +177,7 @@ namespace fgl::engine::gui drawConfigBar( info, camera, frame_index, current ); - const float ratio { info.swap_chain.extentAspectRatio() }; + const float ratio { camera.aspectRatio() }; const auto imgui_size { ImGui::GetWindowSize() }; const auto target_size { calculateTargetSize( ratio, imgui_size ) }; diff --git a/src/editor/src/main.cpp b/src/editor/src/main.cpp index 36edd2d..970a302 100644 --- a/src/editor/src/main.cpp +++ b/src/editor/src/main.cpp @@ -26,8 +26,7 @@ int main() auto& editor_camera { camera_manager.getPrimary() }; - editor_camera->setPerspectiveProjection( - glm::radians( 90.0f ), engine_ctx.getWindowAspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); + editor_camera->setFOV( glm::radians( 90.0f ) ); //! Will be true until the window says it wants to close. while ( engine_ctx.good() ) diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index 798394b..a6cc6d7 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -47,13 +47,25 @@ endif () message("-- FGL_ENABLE_IMGUI: ${FGL_ENABLE_IMGUI}") if (FGL_ENABLE_IMGUI) - target_compile_definitions(FGLEngine PRIVATE ENABLE_IMGUI=1) - target_compile_definitions(FGLEngine PRIVATE ENABLE_IMGUI_DRAWERS=1) + target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI=1) + target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI_DRAWERS=1) else () - target_compile_definitions(FGLEngine PRIVATE ENABLE_IMGUI=0) - target_compile_definitions(FGLEngine PRIVATE ENABLE_IMGUI_DRAWERS=0) + target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI=0) + target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI_DRAWERS=0) endif () +if (NOT DEFINED FGL_ENABLE_TESTS) + set(FGL_ENABLE_TESTS 0) +endif () + +if (FGL_ENABLE_TESTS) + target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=1) + target_link_libraries(FGLEngine PUBLIC Catch2) +else () + target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=0) +endif () + + #GLM settings # GLM_FORCE_NO_CTOR_INIT target_compile_definitions(FGLEngine PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_FORCE_LEFT_HANDED) diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index bf5d1e3..00824c7 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -19,7 +19,6 @@ #include "engine/assets/TransferManager.hpp" #include "engine/debug/drawers.hpp" #include "engine/literals/size.hpp" -#include "engine/model/prebuilt/terrainModel.hpp" #include "model/builders/SceneBuilder.hpp" namespace fgl::engine @@ -36,7 +35,7 @@ namespace fgl::engine 16_KiB, vk::BufferUsageFlagBits::eIndirectBuffer, vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible ), - m_delta_time_ms( 0.0 ) + m_delta_time( 0.0 ) { ZoneScoped; using namespace fgl::literals::size_literals; @@ -55,10 +54,11 @@ namespace fgl::engine { // Get delta time const auto now { std::chrono::high_resolution_clock::now() }; - const std::chrono::duration< double, std::micro > time_diff { last_tick - now }; + const std::chrono::duration< double, std::chrono::seconds::period > time_diff { now - last_tick }; last_tick = now; - m_delta_time_ms = time_diff.count() * 1000.0f; + // Convert from ms to s + m_delta_time = time_diff.count(); } void EngineContext::tickSimulation() @@ -96,7 +96,7 @@ namespace fgl::engine FrameInfo frame_info { frame_index, present_idx, - m_delta_time_ms, + m_delta_time, command_buffer, nullptr, // Camera camera_manager.getCameras(), @@ -222,7 +222,7 @@ namespace fgl::engine EngineContext::~EngineContext() { -#if EXPOSE_IMGUI_FUNCS +#if TITOR_EDITOR gui::cleanupImGui(); #endif } diff --git a/src/engine/EngineContext.hpp b/src/engine/EngineContext.hpp index ad44aba..26bddc1 100644 --- a/src/engine/EngineContext.hpp +++ b/src/engine/EngineContext.hpp @@ -64,11 +64,11 @@ namespace fgl::engine std::chrono::time_point< std::chrono::high_resolution_clock > last_tick { std::chrono::high_resolution_clock::now() }; - double m_delta_time_ms; + double m_delta_time; void loadGameObjects(); -#ifdef IDHAN_EDITOR +#ifdef TITOR_EDITOR public: diff --git a/src/engine/FGL_DEFINES.hpp b/src/engine/FGL_DEFINES.hpp index 3acae88..d990f23 100644 --- a/src/engine/FGL_DEFINES.hpp +++ b/src/engine/FGL_DEFINES.hpp @@ -4,6 +4,8 @@ #pragma once +#include + #define FGL_DELETE_DEFAULT_CTOR( ClassName ) ClassName() = delete; #define FGL_DELETE_COPY_ASSIGN( ClassName ) ClassName& operator=( const ClassName& ) = delete; #define FGL_DELETE_COPY_CTOR( ClassName ) ClassName( const ClassName& ) = delete; @@ -42,4 +44,11 @@ std::unreachable() #else #define FGL_UNREACHABLE() std::unreachable() -#endif \ No newline at end of file +#endif + +#ifndef FGL_TESTS +#define FGL_TESTED_ASSERT( ... ) FGL_ASSERT( __VA_ARGS__ ); +#else +#include +#define FGL_TESTED_ASSERT( ... ) REQUIRE( __VA_ARGS__ ); +#endif diff --git a/src/engine/FrameInfo.hpp b/src/engine/FrameInfo.hpp index aef49e6..742902f 100644 --- a/src/engine/FrameInfo.hpp +++ b/src/engine/FrameInfo.hpp @@ -71,7 +71,7 @@ namespace fgl::engine { FrameIndex frame_idx; PresentIndex present_idx; - double frame_time_ms; + double delta_time; vk::raii::CommandBuffer& command_buffer; diff --git a/src/engine/KeyboardMovementController.cpp b/src/engine/KeyboardMovementController.cpp index 825270c..b5e1262 100644 --- a/src/engine/KeyboardMovementController.cpp +++ b/src/engine/KeyboardMovementController.cpp @@ -83,12 +83,12 @@ namespace fgl::engine Rotation pitch_rotation {}; if ( pitch_change > std::numeric_limits< float >::epsilon() - || pitch_change < std::numeric_limits< float >::epsilon() ) - pitch_rotation.pitch() += ( dt * pitch_change ); + || pitch_change < -std::numeric_limits< float >::epsilon() ) + pitch_rotation.pitch() += static_cast< float >( dt * pitch_change ); if ( yaw_change > std::numeric_limits< float >::epsilon() - || yaw_change < std::numeric_limits< float >::epsilon() ) - yaw_rotation.yaw() += ( dt * yaw_change ); + || yaw_change < -std::numeric_limits< float >::epsilon() ) + yaw_rotation.yaw() += static_cast< float >( dt * yaw_change ); target.getTransform().rotation = yaw_rotation * original_rotation * pitch_rotation; } diff --git a/src/engine/camera/Camera.cpp b/src/engine/camera/Camera.cpp index 743b587..3592415 100644 --- a/src/engine/camera/Camera.cpp +++ b/src/engine/camera/Camera.cpp @@ -12,6 +12,7 @@ #include "CameraInfo.hpp" #include "CameraRenderer.hpp" #include "CameraSwapchain.hpp" +#include "engine/logging/formatters/glm_formatters.hpp" namespace fgl::engine { @@ -30,7 +31,8 @@ namespace fgl::engine //TODO: Figure out frustum culling for orthographic projection. (If we even wanna use it) } - FGL_FLATTEN_HOT void Camera::setPerspectiveProjection( float fovy, float aspect, float near, float far ) + FGL_FLATTEN_HOT void Camera:: + setPerspectiveProjection( const float fovy, const float aspect, const float near, const float far ) { projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspectiveLH_ZO( fovy, aspect, near, far ) ); @@ -58,10 +60,22 @@ namespace fgl::engine return m_camera_info_descriptors[ index ]; } + void Camera::setFOV( const float fov_y ) + { + m_fov_y = fov_y; + setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); + } + void Camera::pass( FrameInfo& frame_info ) { assert( frame_info.camera == nullptr ); frame_info.camera = this; + + if ( m_swapchain->getExtent() != m_target_extent ) + { + remakeSwapchain( m_target_extent ); + } + updateInfo( frame_info.frame_idx ); m_renderer->pass( frame_info, *m_swapchain ); frame_info.camera = nullptr; @@ -83,7 +97,7 @@ namespace fgl::engine viewport.x = 0.0f; viewport.y = 0.0f; - const auto [ width, height ] = m_extent; + const auto& [ width, height ] = m_swapchain->getExtent(); viewport.width = static_cast< float >( width ); viewport.height = static_cast< float >( height ); viewport.minDepth = 0.0f; @@ -96,31 +110,17 @@ namespace fgl::engine void Camera::setScissor( const vk::raii::CommandBuffer& command_buffer ) { - const vk::Rect2D scissor { { 0, 0 }, m_extent }; + const vk::Rect2D scissor { { 0, 0 }, m_swapchain->getExtent() }; const std::vector< vk::Rect2D > scissors { scissor }; command_buffer.setScissor( 0, scissors ); } - void Camera::beginRenderpass( const vk::raii::CommandBuffer& command_buffer, const FrameInfo& info ) + void Camera::remakeSwapchain( vk::Extent2D extent ) { - vk::RenderPassBeginInfo begin_info {}; - begin_info.renderPass = getRenderpass(); - begin_info.framebuffer = this->getSwapchain().getFramebuffer( info.frame_idx ); - begin_info.renderArea = { .offset = { 0, 0 }, .extent = m_extent }; - - begin_info.setClearValues( this->getSwapchain().getClearValues() ); - - command_buffer.beginRenderPass( begin_info, vk::SubpassContents::eInline ); - - setViewport( command_buffer ); - setScissor( command_buffer ); - } - - void Camera::endRenderpass( const vk::raii::CommandBuffer& command_buffer ) - { - command_buffer.endRenderPass(); + this->setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); + m_swapchain = std::make_shared< CameraSwapchain >( m_renderer->getRenderpass(), extent ); } void Camera::setName( const std::string_view str ) @@ -128,10 +128,15 @@ namespace fgl::engine name = str; } + float Camera::aspectRatio() const + { + return m_swapchain->getAspectRatio(); + } + void Camera:: copyOutput( const vk::raii::CommandBuffer& command_buffer, const FrameIndex frame_index, Image& target ) { - assert( m_extent == target.getExtent() ); + assert( m_swapchain->getExtent() == target.getExtent() ); Image& source { this->getSwapchain().getOutput( frame_index ) }; @@ -180,7 +185,7 @@ namespace fgl::engine { barrier_from_source } ); vk::ImageCopy region {}; - region.extent = vk::Extent3D( m_extent, 1 ); + region.extent = vk::Extent3D( m_swapchain->getExtent(), 1 ); region.srcSubresource.aspectMask = vk::ImageAspectFlagBits::eColor; region.srcSubresource.layerCount = 1; @@ -238,25 +243,32 @@ namespace fgl::engine { barrier_to_source } ); } - FGL_FLATTEN_HOT void Camera::setView( WorldCoordinate pos, const Rotation& rotation, const ViewMode mode ) + void Camera::updateMatrix() + { + const auto& [ pos, scale, rotation ] = m_transform; + + const auto rotation_matrix { rotation.mat() }; + + const glm::vec3 forward { rotation_matrix * glm::vec4( constants::WORLD_FORWARD, 0.0f ) }; + + const glm::vec3 camera_up { rotation_matrix * glm::vec4( constants::WORLD_UP, 0.0f ) }; + + const WorldCoordinate center_pos { pos + forward }; + + view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAtLH( pos.vec(), center_pos.vec(), -camera_up ) ); + + inverse_view_matrix = glm::inverse( view_matrix ); + } + + FGL_FLATTEN_HOT void Camera::setView( const WorldCoordinate pos, const Rotation& rotation, const ViewMode mode ) { switch ( mode ) { case ViewMode::TaitBryan: { - const RotationMatrix rotation_matrix { rotation.mat() }; - - const glm::vec3 forward { rotation_matrix * glm::vec4( constants::WORLD_FORWARD, 0.0f ) }; - - const glm::vec3 camera_up { rotation_matrix * glm::vec4( constants::WORLD_UP, 0.0f ) }; - - const WorldCoordinate center_pos { pos + forward }; - - view_matrix = - Matrix< MatrixType::WorldToCamera >( glm::lookAtLH( pos.vec(), center_pos.vec(), -camera_up ) ); - - inverse_view_matrix = glm::inverse( view_matrix ); - + m_transform.translation = pos; + m_transform.rotation = rotation; + updateMatrix(); break; } case ViewMode::Euler: @@ -269,8 +281,6 @@ namespace fgl::engine throw std::runtime_error( "Unimplemented view mode" ); } - current_rotation = rotation; - updateFrustum(); } @@ -295,11 +305,11 @@ namespace fgl::engine } Camera::Camera( const vk::Extent2D extent, memory::Buffer& buffer ) : - m_extent( extent ), + m_target_extent( extent ), m_camera_frame_info( buffer, SwapChain::MAX_FRAMES_IN_FLIGHT ), - m_swapchain( std::make_shared< CameraSwapchain >( m_renderer->getRenderpass(), m_extent ) ) + m_swapchain( std::make_shared< CameraSwapchain >( m_renderer->getRenderpass(), m_target_extent ) ) { - this->setPerspectiveProjection( 90.0f, 16.0f / 9.0f, constants::NEAR_PLANE, constants::FAR_PLANE ); + this->setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE ); this->setView( WorldCoordinate( constants::CENTER ), Rotation( 0.0f, 0.0f, 0.0f ) ); for ( std::uint8_t i = 0; i < SwapChain::MAX_FRAMES_IN_FLIGHT; ++i ) @@ -315,8 +325,7 @@ namespace fgl::engine void Camera::setExtent( const vk::Extent2D extent ) { - m_extent = extent; - m_swapchain = std::make_shared< CameraSwapchain >( m_renderer->getRenderpass(), m_extent ); + m_target_extent = extent; } Frustum< CoordinateSpace::Model > @@ -371,11 +380,7 @@ namespace fgl::engine Matrix< MatrixType::ModelToWorld > Camera::frustumTranslationMatrix() const { - TransformComponent comp {}; - comp.translation = getPosition(); - comp.rotation = current_rotation; - - return comp.mat(); + return m_transform.mat(); } WorldCoordinate Camera::getFrustumPosition() const diff --git a/src/engine/camera/Camera.hpp b/src/engine/camera/Camera.hpp index a779612..002d8ed 100644 --- a/src/engine/camera/Camera.hpp +++ b/src/engine/camera/Camera.hpp @@ -40,7 +40,6 @@ namespace fgl::engine using CameraIDX = std::uint8_t; - class Camera { inline static CameraIDX camera_counter { 0 }; @@ -57,9 +56,10 @@ namespace fgl::engine Frustum< CoordinateSpace::World > frustum {}; WorldCoordinate last_frustum_pos { constants::WORLD_CENTER }; - Rotation current_rotation {}; + TransformComponent m_transform; - vk::Extent2D m_extent; + vk::Extent2D m_target_extent; + float m_fov_y { glm::radians( 90.0f ) }; PerFrameSuballocation< HostSingleT< CameraInfo > > m_camera_frame_info; @@ -75,12 +75,21 @@ namespace fgl::engine void updateFrustum(); +#ifdef EXPOSE_CAMERA_TESTS + //Constructor for tests + Camera( vk::Extent2D test_extent ) : m_target_extent( test_extent ) {} +#endif + Camera( vk::Extent2D extent, memory::Buffer& data_buffer ); friend class CameraManager; public: + float& x { m_transform.translation.x }; + float& y { m_transform.translation.y }; + float& z { m_transform.translation.z }; + FGL_DELETE_ALL_Ro5( Camera ); ~Camera(); @@ -93,7 +102,13 @@ namespace fgl::engine void setExtent( vk::Extent2D extent ); - Rotation getRotation() const { return current_rotation; } + const Rotation& getRotation() const { return m_transform.rotation; } + + Rotation& getRotation() { return m_transform.rotation; } + + const TransformComponent& getTransform() const { return m_transform; } + + TransformComponent& getTransform() { return m_transform; } WorldCoordinate getFrustumPosition() const; @@ -147,6 +162,8 @@ namespace fgl::engine void updateInfo( FrameIndex frame_index ); descriptors::DescriptorSet& getDescriptor( FrameIndex index ); + void setFOV( const float fov_y ); + //! Performs the render pass for this camera void pass( FrameInfo& frame_info ); @@ -155,12 +172,20 @@ namespace fgl::engine void setViewport( const vk::raii::CommandBuffer& command_buffer ); void setScissor( const vk::raii::CommandBuffer& command_buffer ); - void beginRenderpass( const vk::raii::CommandBuffer& command_buffer, const FrameInfo& info ); - void endRenderpass( const vk::raii::CommandBuffer& command_buffer ); + void remakeSwapchain( vk::Extent2D extent ); void setName( std::string_view str ); + float aspectRatio() const; + void copyOutput( const vk::raii::CommandBuffer& command_buffer, FrameIndex frame_index, Image& target ); + void updateMatrix(); + +#ifdef EXPOSE_CAMERA_TESTS + + Camera CREATE_TESTING_CAMERA() { return { { 1920, 1080 } }; } + +#endif }; } // namespace fgl::engine diff --git a/src/engine/camera/CameraManager.cpp b/src/engine/camera/CameraManager.cpp index a3d4876..9869caf 100644 --- a/src/engine/camera/CameraManager.cpp +++ b/src/engine/camera/CameraManager.cpp @@ -40,10 +40,11 @@ namespace fgl::engine m_data_buffer( 4_KiB, vk::BufferUsageFlagBits::eUniformBuffer, vk::MemoryPropertyFlagBits::eHostVisible ) { Camera::initCameraRenderer(); - debug::setDebugDrawingCamera( *getPrimary() ); m_primary_camera = createCamera( { 1920, 1080 } ); m_primary_camera->setName( CAMERA_EDITOR_NAME ); + + debug::setDebugDrawingCamera( getPrimary() ); } std::shared_ptr< Camera > CameraManager::createCamera( const vk::Extent2D extent ) diff --git a/src/engine/camera/CameraSwapchain.cpp b/src/engine/camera/CameraSwapchain.cpp index 4a313ae..7c8e879 100644 --- a/src/engine/camera/CameraSwapchain.cpp +++ b/src/engine/camera/CameraSwapchain.cpp @@ -111,6 +111,11 @@ namespace fgl::engine return *gbuffer.composite.m_attachment_resources.m_images[ index ]; } + float CameraSwapchain::getAspectRatio() + { + return static_cast< float >( m_extent.width ) / static_cast< float >( m_extent.height ); + } + CameraSwapchain::CameraSwapchain( vk::raii::RenderPass& renderpass, const vk::Extent2D extent ) : m_extent( extent ), m_renderpass( renderpass ), diff --git a/src/engine/camera/CameraSwapchain.hpp b/src/engine/camera/CameraSwapchain.hpp index 62d725c..cb86af8 100644 --- a/src/engine/camera/CameraSwapchain.hpp +++ b/src/engine/camera/CameraSwapchain.hpp @@ -58,6 +58,8 @@ namespace fgl::engine vk::Extent2D getExtent() const; Image& getOutput( const FrameIndex index ); + + float getAspectRatio(); }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/constants.hpp b/src/engine/constants.hpp index 73d618e..181d8dc 100644 --- a/src/engine/constants.hpp +++ b/src/engine/constants.hpp @@ -17,10 +17,6 @@ namespace fgl::engine::constants constexpr glm::vec3 WORLD_CENTER { 0.0f, 0.0f, 0.0f }; - // Z UP - constexpr glm::vec3 WORLD_UP { 0.0f, 0.0f, 1.0f }; - constexpr glm::vec3 WORLD_DOWN { -WORLD_UP }; - // X RIGHT constexpr glm::vec3 WORLD_RIGHT { 1.0f, 0.0f, 0.0f }; constexpr glm::vec3 WORLD_LEFT { -WORLD_RIGHT }; @@ -29,6 +25,10 @@ namespace fgl::engine::constants constexpr glm::vec3 WORLD_FORWARD { 0.0f, 1.0f, 0.0f }; constexpr glm::vec3 WORLD_BACKWARD { -WORLD_FORWARD }; + // Z UP + constexpr glm::vec3 WORLD_UP { 0.0f, 0.0f, 1.0f }; + constexpr glm::vec3 WORLD_DOWN { -WORLD_UP }; + constexpr float DEFAULT_FLOAT { std::numeric_limits< float >::max() }; constexpr float NEAR_PLANE { 0.1f }; @@ -40,5 +40,6 @@ namespace fgl::engine::constants constexpr auto FRUSTUM_ORIGIN { constants::WORLD_CENTER }; constexpr glm::mat4 MAT4_IDENTITY { 1.0f }; + constexpr glm::mat3 MAT3_IDENTITY { 1.0f }; } // namespace fgl::engine::constants diff --git a/src/engine/debug/drawers.cpp b/src/engine/debug/drawers.cpp index 5918526..9e0d5b3 100644 --- a/src/engine/debug/drawers.cpp +++ b/src/engine/debug/drawers.cpp @@ -23,17 +23,18 @@ namespace fgl::engine::debug { - inline static std::optional< Camera* > debug_camera { std::nullopt }; + inline static std::optional< std::shared_ptr< Camera > > debug_camera { std::nullopt }; Camera& getDebugDrawingCamera() { - assert( debug_camera.has_value() && "Debug camera not set" ); + assert( debug_camera.has_value() && debug_camera.value() != nullptr && "Debug camera not set" ); return *debug_camera.value(); } - void setDebugDrawingCamera( Camera& cam ) + void setDebugDrawingCamera( std::shared_ptr< Camera >& cam ) { - debug_camera = &cam; + assert( cam ); + debug_camera = cam; } const ImVec2 windowSize() diff --git a/src/engine/debug/drawers.hpp b/src/engine/debug/drawers.hpp index cfa0425..e08a66d 100644 --- a/src/engine/debug/drawers.hpp +++ b/src/engine/debug/drawers.hpp @@ -4,6 +4,8 @@ #pragma once +#include + #include "engine/primitives/Frustum.hpp" #include "engine/primitives/lines/LineSegment.hpp" #include "engine/primitives/planes/PointPlane.hpp" @@ -42,64 +44,61 @@ namespace fgl::engine namespace fgl::engine::debug { Camera& getDebugDrawingCamera(); - void setDebugDrawingCamera( Camera& ); + void setDebugDrawingCamera( std::shared_ptr< Camera >& ); namespace world { void drawBoundingBox( - const OrientedBoundingBox< CoordinateSpace::World >& box, const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + const OrientedBoundingBox< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); void drawBoundingBox( - const AxisAlignedBoundingBox< CoordinateSpace::World >& box, const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + const AxisAlignedBoundingBox< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); void drawBoundingBox( - const AxisAlignedBoundingCube< CoordinateSpace::World >& box, - const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + const AxisAlignedBoundingCube< CoordinateSpace::World >& box, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); void drawLine( - const Coordinate< CoordinateSpace::World > start, - const Coordinate< CoordinateSpace::World > end, - const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + Coordinate< CoordinateSpace::World > start, + Coordinate< CoordinateSpace::World > end, + glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - void drawPointLabel( const Coordinate< CoordinateSpace::World > point, const std::string label ); + void drawPointLabel( Coordinate< CoordinateSpace::World > point, std::string label ); void drawLineI( - const LineSegment< CoordinateSpace::World > line, - const glm::vec3 color = { 1.0f, 1.0f, 1.0f }, - const float thickness = 1.0f ); + LineSegment< CoordinateSpace::World > line, + glm::vec3 color = { 1.0f, 1.0f, 1.0f }, + float thickness = 1.0f ); void drawLine( - const LineSegment< CoordinateSpace::World > line, - const glm::vec3 color = { 1.0f, 1.0f, 1.0f }, - const float thickness = 1.0f ); + LineSegment< CoordinateSpace::World > line, + glm::vec3 color = { 1.0f, 1.0f, 1.0f }, + float thickness = 1.0f ); - void drawPointText( - const Coordinate< CoordinateSpace::World > point, const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + void drawPointText( Coordinate< CoordinateSpace::World > point, glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - void drawBoolAlpha( - const Coordinate< CoordinateSpace::World > point, const bool value, const glm::vec2 offset = {} ); + void drawBoolAlpha( Coordinate< CoordinateSpace::World > point, bool value, glm::vec2 offset = {} ); void drawPoint( - const Coordinate< CoordinateSpace::World > point, - const std::string label = "", - const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + Coordinate< CoordinateSpace::World > point, + std::string label = "", + glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); void drawVector( - const Coordinate< CoordinateSpace::World > point, + Coordinate< CoordinateSpace::World > point, Vector vector, - const std::string label = "", - const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + std::string label = "", + glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); void drawVector( - const Coordinate< CoordinateSpace::World > point, + Coordinate< CoordinateSpace::World > point, NormalVector vector, - const std::string label = "", - const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + std::string label = "", + glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); - void drawFrustum( const Frustum< CoordinateSpace::World >& frustum, const WorldCoordinate coordinate ); + void drawFrustum( const Frustum< CoordinateSpace::World >& frustum, WorldCoordinate coordinate ); void drawFrustum(); void drawPlane( const Plane< CoordinateSpace::World >& plane, - const WorldCoordinate point, - const std::string label = "", - const glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); + WorldCoordinate point, + std::string label = "", + glm::vec3 color = { 1.0f, 1.0f, 1.0f } ); } // namespace world @@ -107,13 +106,12 @@ namespace fgl::engine::debug { void drawText( - const glm::vec2 position, + glm::vec2 position, const std::string& text, - const glm::vec3 color = { 1.0f, 1.0f, 1.0f }, - const glm::vec2 offset = {} ); + glm::vec3 color = { 1.0f, 1.0f, 1.0f }, + glm::vec2 offset = {} ); - void drawBoolAlpha( - const glm::vec2 screen_point, const Camera& camera, const bool value, const glm::vec2 offset = {} ); + void drawBoolAlpha( glm::vec2 screen_point, const Camera& camera, bool value, glm::vec2 offset = {} ); } // namespace screen diff --git a/src/engine/gameobjects/components/ComponentEditorInterface.hpp b/src/engine/gameobjects/components/ComponentEditorInterface.hpp index 97626c6..66455ff 100644 --- a/src/engine/gameobjects/components/ComponentEditorInterface.hpp +++ b/src/engine/gameobjects/components/ComponentEditorInterface.hpp @@ -4,7 +4,7 @@ #pragma once -#ifdef IDHAN_EDITOR +#ifdef TITOR_EDITOR #include #endif @@ -13,7 +13,7 @@ namespace fgl::engine struct ComponentEditorInterface { -#ifdef IDHAN_EDITOR +#ifdef TITOR_EDITOR virtual void drawImGui() = 0; virtual std::string_view name() const = 0; #endif diff --git a/src/engine/gameobjects/components/GameObjectComponent.hpp b/src/engine/gameobjects/components/GameObjectComponent.hpp index 37870fa..669c3f9 100644 --- a/src/engine/gameobjects/components/GameObjectComponent.hpp +++ b/src/engine/gameobjects/components/GameObjectComponent.hpp @@ -20,7 +20,7 @@ namespace fgl::engine struct GameObjectComponent : public GameObjectComponentBase { constexpr static ComponentID ID { T_ID }; - ComponentTransform m_transform; + ComponentTransform m_transform { WorldCoordinate( 0.0f ), Scale( 1.0 ), Rotation() }; virtual ComponentID id() const override final { return ID; } }; diff --git a/src/engine/gameobjects/components/ModelComponent.hpp b/src/engine/gameobjects/components/ModelComponent.hpp index b75d26b..c39e759 100644 --- a/src/engine/gameobjects/components/ModelComponent.hpp +++ b/src/engine/gameobjects/components/ModelComponent.hpp @@ -20,7 +20,7 @@ namespace fgl::engine ModelComponent( std::shared_ptr< Model >&& model ) : m_model( std::forward< decltype( m_model ) >( model ) ) {} -#ifdef IDHAN_EDITOR +#ifdef TITOR_EDITOR void drawImGui() override; std::string_view name() const override diff --git a/src/engine/logging/formatters/filesystem.hpp b/src/engine/logging/formatters/filesystem.hpp index 1aa9987..ddcf156 100644 --- a/src/engine/logging/formatters/filesystem.hpp +++ b/src/engine/logging/formatters/filesystem.hpp @@ -4,30 +4,12 @@ #pragma once -#ifdef HAVE_STD_FORMAT -#include -namespace format_ns = std; - -#else -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#pragma GCC diagnostic ignored "-Wswitch-default" -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -#include -namespace format_ns = fmt; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -#endif - #include +#include #include +namespace format_ns = std; + template <> struct format_ns::formatter< std::filesystem::path > { @@ -73,7 +55,3 @@ struct format_ns::formatter< format_ns::format_string<> > format_context::iterator format( const format_ns::format_string<>& str, format_context& ctx ) const; }; - - - - diff --git a/src/engine/logging/formatters/glm_formatters.cpp b/src/engine/logging/formatters/glm_formatters.cpp new file mode 100644 index 0000000..0f8e0b8 --- /dev/null +++ b/src/engine/logging/formatters/glm_formatters.cpp @@ -0,0 +1,5 @@ +// +// Created by kj16609 on 8/2/24. +// + +#include "glm_formatters.hpp" \ No newline at end of file diff --git a/src/engine/logging/formatters/glm_formatters.hpp b/src/engine/logging/formatters/glm_formatters.hpp new file mode 100644 index 0000000..4cddac6 --- /dev/null +++ b/src/engine/logging/formatters/glm_formatters.hpp @@ -0,0 +1,38 @@ +// +// Created by kj16609 on 8/2/24. +// + +#pragma once + +#include + +#include + +template <> +struct std::formatter< glm::mat4 > +{ + constexpr format_parse_context::iterator parse( std::format_parse_context& ctx ) { return ctx.begin(); } + + format_context::iterator format( const glm::mat4& mat4, format_context& ctx ) const + { + return std::format_to( + ctx.out(), + "mat4:\n\t[{}, {}, {}, {}]\n\t[{}, {}, {}, {}]\n\t[{}, {}, {}, {}]\n\t[{}, {}, {}, {}]", + mat4[ 0 ][ 0 ], + mat4[ 0 ][ 1 ], + mat4[ 0 ][ 2 ], + mat4[ 0 ][ 3 ], + mat4[ 1 ][ 0 ], + mat4[ 1 ][ 1 ], + mat4[ 1 ][ 2 ], + mat4[ 1 ][ 3 ], + mat4[ 2 ][ 0 ], + mat4[ 2 ][ 1 ], + mat4[ 2 ][ 2 ], + mat4[ 2 ][ 3 ], + mat4[ 3 ][ 0 ], + mat4[ 3 ][ 1 ], + mat4[ 3 ][ 2 ], + mat4[ 3 ][ 3 ] ); + } +}; diff --git a/src/engine/math/taitBryanMatrix.cpp b/src/engine/math/taitBryanMatrix.cpp deleted file mode 100644 index 61a054e..0000000 --- a/src/engine/math/taitBryanMatrix.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// -// Created by kj16609 on 2/19/24. -// - -#include "taitBryanMatrix.hpp" - -#include -#include -#include - -#include "engine/primitives/Rotation.hpp" -#include "engine/primitives/matricies/RotationMatrix.hpp" - -namespace fgl::engine -{ - - using CosSinPair = std::tuple< float, float >; - - inline std::tuple< CosSinPair, CosSinPair, CosSinPair > - extract( const glm::vec3 rotation, const RotationOrder order ) - { - switch ( order ) - { - case XZY: - return { { glm::cos( rotation.x ), glm::sin( rotation.x ) }, - { glm::cos( rotation.z ), glm::sin( rotation.z ) }, - { glm::cos( rotation.y ), glm::sin( rotation.y ) } }; - case XYZ: // DEFAULT - return { { glm::cos( rotation.x ), glm::sin( rotation.x ) }, - { glm::cos( rotation.y ), glm::sin( rotation.y ) }, - { glm::cos( rotation.z ), glm::sin( rotation.z ) } }; - case YXZ: - return { { glm::cos( rotation.y ), glm::sin( rotation.y ) }, - { glm::cos( rotation.x ), glm::sin( rotation.x ) }, - { glm::cos( rotation.z ), glm::sin( rotation.z ) } }; - case YZX: - return { { glm::cos( rotation.y ), glm::sin( rotation.y ) }, - { glm::cos( rotation.z ), glm::sin( rotation.z ) }, - { glm::cos( rotation.x ), glm::sin( rotation.x ) } }; - case ZYX: - return { { glm::cos( rotation.z ), glm::sin( rotation.z ) }, - { glm::cos( rotation.y ), glm::sin( rotation.y ) }, - { glm::cos( rotation.x ), glm::sin( rotation.x ) } }; - case ZXY: - return { { glm::cos( rotation.z ), glm::sin( rotation.z ) }, - { glm::cos( rotation.x ), glm::sin( rotation.x ) }, - { glm::cos( rotation.y ), glm::sin( rotation.y ) } }; - case END_OF_ENUM: - throw std::runtime_error( "Unimplemented rotation order" ); - } - - FGL_UNREACHABLE(); - } - - glm::mat3 taitBryanMatrix( const glm::vec3 rotation, const RotationOrder order ) - { - glm::mat3 mat { 1.0f }; - - const auto [ p1, p2, p3 ] = extract( rotation, order ); - - const auto& [ c1, s1 ] = p1; - const auto& [ c2, s2 ] = p2; - const auto& [ c3, s3 ] = p3; - - switch ( order ) - { - case RotationOrder::XZY: - { - const glm::vec3 row_0 { ( c2 * c3 ), -( s2 ), ( c2 * s3 ) }; - - const glm::vec3 row_1 { ( s1 * s3 ) + ( c1 * c3 * s2 ), - ( c1 * c2 ), - ( c1 * s2 * s3 ) - ( c3 * s1 ) }; - - const glm::vec3 row_2 { ( c3 * s1 * s2 ) - ( c1 * s3 ), - ( c2 * s1 ), - ( c1 * c3 ) + ( s1 * s2 * s3 ) }; - - mat[ 0 ] = glm::vec4( row_0, 0.0f ); - mat[ 1 ] = glm::vec4( row_1, 0.0f ); - mat[ 2 ] = glm::vec4( row_2, 0.0f ); - return RotationMatrix( mat ); - } - case RotationOrder::XYZ: - { - const glm::vec3 row_0 { ( c2 * c3 ), -( c2 * s3 ), s2 }; - const glm::vec3 row_1 { ( c1 * s3 ) + ( c3 * s1 * s2 ), - ( c1 * c3 ) - ( s1 * s2 * s3 ), - -( c2 * s1 ) }; - const glm::vec3 row_2 { ( s1 * s3 ) - ( c1 * c3 * s2 ), - ( c3 * s1 ) + ( c1 * s2 * s3 ), - ( c1 * c2 ) }; - - mat[ 0 ] = glm::vec4( row_0, 0.0f ); - mat[ 1 ] = glm::vec4( row_1, 0.0f ); - mat[ 2 ] = glm::vec4( row_2, 0.0f ); - return RotationMatrix( mat ); - } - case RotationOrder::YXZ: - { - const glm::vec3 row_0 { ( c1 * c3 ) + ( s1 * s2 * s3 ), ( c3 * s1 * s2 ) - ( c1 * s3 ), c2 * s1 }; - const glm::vec3 row_1 { c2 * s3, c2 * c3, -s2 }; - const glm::vec3 row_2 { ( c1 * s2 * s3 ) - ( c3 * s1 ), ( c1 * c3 * s2 ) + ( s1 * s3 ), c1 * c2 }; - - mat[ 0 ] = glm::vec4( row_0, 0.0f ); - mat[ 1 ] = glm::vec4( row_1, 0.0f ); - mat[ 2 ] = glm::vec4( row_2, 0.0f ); - return RotationMatrix( mat ); - } - case RotationOrder::YZX: - { - const glm::vec3 row_0 { ( c1 * c2 ), - ( s1 * s3 ) - ( c1 * c3 * s2 ), - ( c3 * s1 ) + ( c1 * s2 * s3 ) }; - const glm::vec3 row_1 { s2, c2 * c3, -( c2 * s3 ) }; - const glm::vec3 row_2 { -( c2 * s1 ), - ( c1 * s3 ) + ( c3 * s1 * s2 ), - ( c1 * c3 ) - ( s1 * s2 * s3 ) }; - - mat[ 0 ] = glm::vec4( row_0, 0.0f ); - mat[ 1 ] = glm::vec4( row_1, 0.0f ); - mat[ 2 ] = glm::vec4( row_2, 0.0f ); - return RotationMatrix( mat ); - } - case RotationOrder::ZYX: // Roll, Pitch, Yaw - { - const glm::vec3 row_0 { ( c1 * c2 ), - ( c1 * s2 * s3 ) - ( c3 * s1 ), - ( s1 * s3 ) + ( c1 * c3 * s2 ) }; - const glm::vec3 row_1 { ( c2 * s1 ), - ( c1 * c3 ) + ( s1 * s2 * s3 ), - ( c3 * s1 * s2 ) - ( c1 * s3 ) }; - const glm::vec3 row_2 { -s2, c2 * s3, c2 * c3 }; - - mat[ 0 ] = glm::vec4( row_0, 0.0f ); - mat[ 1 ] = glm::vec4( row_1, 0.0f ); - mat[ 2 ] = glm::vec4( row_2, 0.0f ); - return RotationMatrix( mat ); - } - case RotationOrder::ZXY: // Roll, Yaw, Pitch - { - const glm::vec3 row_0 { ( c1 * c3 ) - ( s1 * s2 * s3 ), - -( c2 * s1 ), - ( c1 * s3 ) + ( c3 * s1 * s2 ) }; - - const glm::vec3 row_1 { ( c3 * s1 ) + ( c1 * s2 * s3 ), - ( c1 * c2 ), - ( s1 * s3 ) - ( c1 * c3 * s2 ) }; - - const glm::vec3 row_2 { -( c2 * s3 ), ( s2 ), ( c2 * c3 ) }; - - mat[ 0 ] = glm::vec4( row_0, 0.0f ); - mat[ 1 ] = glm::vec4( row_1, 0.0f ); - mat[ 2 ] = glm::vec4( row_2, 0.0f ); - return RotationMatrix( mat ); - } - case RotationOrder::END_OF_ENUM: - [[fallthrough]]; - default: - throw std::runtime_error( "Unimplemented rotation order" ); - } - } - -} // namespace fgl::engine diff --git a/src/engine/math/taitBryanMatrix.hpp b/src/engine/math/taitBryanMatrix.hpp deleted file mode 100644 index 8b93fe9..0000000 --- a/src/engine/math/taitBryanMatrix.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// -// Created by kj16609 on 2/19/24. -// - -#pragma once - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Weffc++" -#include -#pragma GCC diagnostic pop - -namespace fgl::engine -{ - struct Rotation; - class RotationMatrix; - - enum RotationOrder - { - XZY, - XYZ, - YXZ, - YZX, - ZYX, - ZXY, - END_OF_ENUM, - DEFAULT = XZY - }; - - glm::mat3 taitBryanMatrix( const glm::vec3 rotation, const RotationOrder order = DEFAULT ); - - inline glm::mat3 taitBryanMatrix( const float x, const float y, const float z, const RotationOrder order = DEFAULT ) - { - return taitBryanMatrix( glm::vec3( x, y, z ), order ); - } - -} // namespace fgl::engine diff --git a/src/engine/pipeline/Pipeline.cpp b/src/engine/pipeline/Pipeline.cpp index ba19a8d..3f91fe6 100644 --- a/src/engine/pipeline/Pipeline.cpp +++ b/src/engine/pipeline/Pipeline.cpp @@ -62,6 +62,16 @@ namespace fgl::engine::internal return m_device->createGraphicsPipeline( VK_NULL_HANDLE, pipeline_info ); } + Pipeline::Pipeline( + Device& device, + vk::raii::PipelineLayout layout, + PipelineConfigInfo info, + std::vector< std::unique_ptr< ShaderHandle > > shaders ) : + m_device( device ), + m_layout( std::move( layout ) ), + m_vk_pipeline( createGraphicsPipeline( shaders, info, m_layout ) ) + {} + void Pipeline::bind( vk::raii::CommandBuffer& command_buffer ) { command_buffer.bindPipeline( vk::PipelineBindPoint::eGraphics, m_vk_pipeline ); diff --git a/src/engine/pipeline/Pipeline.hpp b/src/engine/pipeline/Pipeline.hpp index fec1c7b..8fe5169 100644 --- a/src/engine/pipeline/Pipeline.hpp +++ b/src/engine/pipeline/Pipeline.hpp @@ -39,11 +39,7 @@ namespace fgl::engine::internal Device& device, vk::raii::PipelineLayout layout, PipelineConfigInfo info, - std::vector< std::unique_ptr< ShaderHandle > > shaders ) : - m_device( device ), - m_layout( std::move( layout ) ), - m_vk_pipeline( createGraphicsPipeline( shaders, info, m_layout ) ) - {} + std::vector< std::unique_ptr< ShaderHandle > > shaders ); Pipeline( const Pipeline& other ) = delete; Pipeline& operator=( const Pipeline& ) = delete; diff --git a/src/engine/primitives/Frustum.cpp b/src/engine/primitives/Frustum.cpp index 2cba36f..ad5215a 100644 --- a/src/engine/primitives/Frustum.cpp +++ b/src/engine/primitives/Frustum.cpp @@ -82,7 +82,7 @@ namespace fgl::engine WorldCoordinate first_exit { enter_intersections.at( 0 ) }; float distance { signedDistance( line.getDirection(), line.getEnd(), line.getPosition() ) }; - assert( distance > 0.0f ); + //assert( distance > 0.0f ); for ( const auto intersection_point : enter_intersections ) { diff --git a/src/engine/primitives/Rotation.cpp b/src/engine/primitives/Rotation.cpp index 9ca96c4..072e8eb 100644 --- a/src/engine/primitives/Rotation.cpp +++ b/src/engine/primitives/Rotation.cpp @@ -7,38 +7,87 @@ #define GLM_ENABLE_EXPERIMENTAL #include -#include - -#include "engine/math/taitBryanMatrix.hpp" +#include "engine/debug/drawers.hpp" namespace fgl::engine { - //! Converts 3-axis rotation (euler) to a quaternion - glm::quat toQuat( const float pitch, const float roll, const float yaw ) - { - const glm::vec3 rotation { glm::vec3( pitch, roll, yaw ) * glm::vec3( 0.5f ) }; - const glm::vec3 rot_cos { glm::cos( rotation ) }; - const glm::vec3 rot_sin { glm::sin( rotation ) }; - - auto extractFloats = []( const glm::vec3& vec ) -> std::tuple< const float&, const float&, const float& > - { return std::make_tuple( vec.x, vec.y, vec.z ); }; - - const auto& [ cp, cr, cy ] = extractFloats( rot_cos ); - const auto& [ sp, sr, sy ] = extractFloats( rot_sin ); - - return { sr * cp * sy - cr * sp * sy, - cr * sp * cy + sr * cp * sy, - cr * cp * sy - sr * sp * cy, - cr * cp * cy + sr * sp * sy }; - } - Rotation::Rotation() : glm::quat( 1.0f, 0.0f, 0.0f, 0.0f ) {} - Rotation::Rotation( const float pitch_r, const float roll_r, const float yaw_r ) : - glm::quat( glm::toQuat( taitBryanMatrix( pitch_r, roll_r, yaw_r ) ) ) - {} + inline glm::quat buildQuat( const glm::vec3 euler ) + { + // euler should be in `pitch, roll, yaw` order + const auto pitch { glm::angleAxis( euler.x, constants::WORLD_RIGHT ) }; + const auto roll { glm::angleAxis( euler.y, constants::WORLD_FORWARD ) }; + const auto yaw { glm::angleAxis( euler.z, constants::WORLD_UP ) }; + + return pitch * roll * yaw; + } + + inline float pitch( const glm::quat& q ) + { + const float y { 2.0f * ( q.y * q.z + q.w * q.x ) }; + const float x { q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z }; + + if ( glm::all( glm::equal( glm::vec2( x, y ), glm::vec2( 0.0f ), glm::epsilon< float >() ) ) ) return 0.0f; + + return glm::atan( y, x ); + } + + inline float roll( const glm::quat& q ) + { + return std::asin( glm::clamp( -2.0f * ( q.x * q.z - q.w * q.y ), -1.0f, 1.0f ) ); + } + + inline float yaw( const glm::quat& q ) + { + const float y { 2.0f * ( q.x * q.y + q.w * q.z ) }; + const float x { q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z }; + + if ( glm::all( glm::equal( glm::vec2( x, y ), glm::vec2( 0.0f ), glm::epsilon< float >() ) ) ) return 0.0f; + + return glm::atan( y, x ); + } + + // Because of how glm does stuff. We need to invert the roll. + Rotation::Rotation( const float pitch, const float roll, const float yaw ) : + glm::quat( buildQuat( { pitch, roll, yaw } ) ) + { + FGL_ASSERT( ::fgl::engine::pitch( *this ) - pitch < glm::epsilon< float >() ); + FGL_ASSERT( ::fgl::engine::yaw( *this ) - yaw < glm::epsilon< float >() ); + FGL_ASSERT( ::fgl::engine::roll( *this ) - roll < glm::epsilon< float >() ); + } + + RotationModifier< RotationModifierType::Roll > Rotation::roll() + { + return RotationModifier< RotationModifierType::Roll >( *this ); + } + + ConstRotationModifier< RotationModifierType::Pitch > Rotation::pitch() const + { + return ConstRotationModifier< RotationModifierType::Pitch >( *this ); + } + + RotationModifier< RotationModifierType::Pitch > Rotation::pitch() + { + return RotationModifier< RotationModifierType::Pitch >( *this ); + } + + ConstRotationModifier< RotationModifierType::Roll > Rotation::roll() const + { + return ConstRotationModifier< RotationModifierType::Roll >( *this ); + } + + RotationModifier< RotationModifierType::Yaw > Rotation::yaw() + { + return RotationModifier< RotationModifierType::Yaw >( *this ); + } + + ConstRotationModifier< RotationModifierType::Yaw > Rotation::yaw() const + { + return ConstRotationModifier< RotationModifierType::Yaw >( *this ); + } Rotation& Rotation::operator=( const Rotation& rotation ) { @@ -46,9 +95,18 @@ namespace fgl::engine return *this; } + Rotation& Rotation::operator=( const glm::quat& rotation ) + { + glm::quat::operator=( rotation ); + return *this; + } + Rotation& Rotation::operator+=( const Rotation& rotation ) { glm::quat::operator+=( rotation ); + + *this = glm::normalize( *this ); + return *this; } @@ -69,12 +127,12 @@ namespace fgl::engine RotationMatrix Rotation::mat() const { - return { glm::mat4_cast( *this ) }; + return { glm::mat3_cast( *this ) }; } - Rotation Rotation::operator*( const Rotation rot ) const + Rotation Rotation::operator*( const Rotation& other ) const { - return Rotation( glm::normalize( static_cast< glm::quat >( *this ) * static_cast< glm::quat >( rot ) ) ); + return Rotation( glm::normalize( static_cast< glm::quat >( *this ) * static_cast< glm::quat >( other ) ) ); } } // namespace fgl::engine diff --git a/src/engine/primitives/Rotation.hpp b/src/engine/primitives/Rotation.hpp index e462ec2..66c0009 100644 --- a/src/engine/primitives/Rotation.hpp +++ b/src/engine/primitives/Rotation.hpp @@ -27,121 +27,75 @@ namespace fgl::engine { enum class RotationModifierType { - Pitch, - Roll, - Yaw + Pitch = 0, + Roll = 1, + Yaw = 2, }; struct Rotation; + template < RotationModifierType ModifierType, bool is_const = false > + class RotationModifier; + template < RotationModifierType ModifierType > - class RotationModifier - { - using enum RotationModifierType; - - Rotation& rot; - - friend struct Rotation; - - RotationModifier() = delete; - - RotationModifier( Rotation& i_rot ) : rot( i_rot ) {} - - public: - - Rotation& operator+=( const float scalar ); - Rotation& operator-=( const float scalar ); - - operator float() const; - - float value() const { return static_cast< float >( *this ); } - - float value() { return static_cast< float >( *this ); } - }; + using ConstRotationModifier = RotationModifier< ModifierType, true >; struct Rotation : private glm::quat { - friend class RotationModifier< RotationModifierType::Pitch >; - friend class RotationModifier< RotationModifierType::Roll >; - friend class RotationModifier< RotationModifierType::Yaw >; - - public: + template < RotationModifierType ModifierType, bool is_const > + friend class RotationModifier; Rotation(); - explicit Rotation( const float pitch_r, const float roll_r, const float yaw_r ); + explicit Rotation( float pitch, float roll, float yaw ); Rotation( const Rotation& other ) = default; - Rotation( const glm::quat other ) : glm::quat( other ) {} + explicit Rotation( const glm::quat other ) : glm::quat( other ) {} - FGL_FORCE_INLINE_FLATTEN auto pitch() { return RotationModifier< RotationModifierType::Pitch >( *this ); } + explicit Rotation( const float scalar ) : Rotation( scalar, scalar, scalar ) {} - FGL_FORCE_INLINE_FLATTEN auto roll() { return RotationModifier< RotationModifierType::Roll >( *this ); } - - FGL_FORCE_INLINE_FLATTEN auto yaw() { return RotationModifier< RotationModifierType::Yaw >( *this ); } - - FGL_FORCE_INLINE float pitch() const + enum RotationReference { - //TODO: Ask entry to explain this stuff - const float sinr_cosp { 2.0f * ( w * x + y * z ) }; - const float cosr_cosp { 1.0f - 2.0f * ( x * x + y * y ) }; - return std::atan2( sinr_cosp, cosr_cosp ); - } + Local, + Global + }; - FGL_FORCE_INLINE float roll() const - { - const float sinp { glm::sqrt( 1.0f + 2.0f * ( w * y - x * z ) ) }; - const float cosp { glm::sqrt( 1.0f - 2.0f * ( w * y - x * z ) ) }; - return 2.0f * std::atan2( sinp, cosp ) - ( std::numbers::pi_v< float > / 2.0f ); - } + RotationModifier< RotationModifierType::Pitch > pitch(); + ConstRotationModifier< RotationModifierType::Pitch > pitch() const; - FGL_FORCE_INLINE float yaw() const - { - const float siny_cosp { 2.0f * ( w * z + x * y ) }; - const float cosy_cosp { 1.0f - 2.0f * ( y * y + z * z ) }; - return std::atan2( siny_cosp, cosy_cosp ); - } + RotationModifier< RotationModifierType::Roll > roll(); + ConstRotationModifier< RotationModifierType::Roll > roll() const; + + RotationModifier< RotationModifierType::Yaw > yaw(); + ConstRotationModifier< RotationModifierType::Yaw > yaw() const; Rotation& operator=( const Rotation& rotation ); + Rotation& operator=( const glm::quat& rotation ); Rotation& operator+=( const Rotation& rotation ); NormalVector forward() const; + NormalVector back() const { return -forward(); } + NormalVector right() const; + NormalVector left() const { return -right(); } + NormalVector up() const; + NormalVector down() const { return -up(); } + RotationMatrix mat() const; - Rotation operator*( const Rotation other ) const; + Rotation operator*( const Rotation& other ) const; bool operator==( const Rotation& other ) const = default; }; - template < RotationModifierType ModifierType > - FGL_FORCE_INLINE_FLATTEN RotationModifier< ModifierType >::operator float() const - { - switch ( ModifierType ) - { - case RotationModifierType::Pitch: - return const_cast< const Rotation& >( rot ).pitch(); - case RotationModifierType::Roll: - return const_cast< const Rotation& >( rot ).roll(); - case RotationModifierType::Yaw: - return const_cast< const Rotation& >( rot ).yaw(); - } - FGL_UNREACHABLE(); - } - - namespace constants - { - constexpr glm::vec3 DEFAULT_ROTATION { 0.0f, 0.0f, 0.0f }; - } - template < RotationModifierType MT > - consteval glm::vec3 getModifierAxis() + glm::vec3 getModifierAxis() { switch ( MT ) { @@ -150,25 +104,130 @@ namespace fgl::engine case RotationModifierType::Roll: return constants::WORLD_FORWARD; case RotationModifierType::Yaw: - return constants::WORLD_DOWN; + return -constants::WORLD_UP; + default: + FGL_UNREACHABLE(); } FGL_UNREACHABLE(); } - template < RotationModifierType ModifierType > - Rotation& RotationModifier< ModifierType >::operator+=( const float scalar ) + template < RotationModifierType ModifierType, bool is_const > + class RotationModifier { - rot = Rotation( static_cast< glm::quat >( rot ) * glm::angleAxis( scalar, getModifierAxis< ModifierType >() ) ); - return rot; + using enum RotationModifierType; + + using RotationType = std::conditional_t< is_const, const Rotation&, Rotation& >; + + RotationType rot; + + friend struct Rotation; + + RotationModifier() = delete; + + explicit RotationModifier( RotationType& i_rot ) : rot( i_rot ) {} + + public: + + Rotation& operator+=( const float scalar ) + { + static_assert( !is_const, "Cannot perform operator-= on a const rotation" ); + + const glm::quat modifier { glm::angleAxis( scalar, getModifierAxis< ModifierType >() ) }; + + switch ( ModifierType ) + { + case Pitch: + [[fallthrough]]; + case Roll: + rot = static_cast< glm::quat >( rot ) * modifier; // local + break; + case Yaw: + rot = modifier * static_cast< glm::quat >( rot ); // global + break; + default: + FGL_UNREACHABLE(); + } + + return rot; + } + + Rotation& operator-=( const float scalar ) + { + static_assert( !is_const, "Cannot perform operator-= on a const rotation" ); + + const auto modifier { glm::angleAxis( -scalar, getModifierAxis< ModifierType >() ) }; + + switch ( ModifierType ) + { + case Pitch: + [[fallthrough]]; + case Roll: + rot = static_cast< glm::quat >( rot ) * modifier; // local + break; + case Yaw: + rot = modifier * static_cast< glm::quat >( rot ); // global + break; + default: + FGL_UNREACHABLE(); + } + return rot; + } + + Rotation& operator=( const float scalar ) + { + glm::vec3 euler { glm::eulerAngles( rot ) }; + + switch ( ModifierType ) + { + default: + FGL_UNREACHABLE(); + case Pitch: + euler.x = scalar; + break; + case Roll: + euler.y = scalar; + break; + case Yaw: + euler.z = scalar; + break; + } + + return rot; + } + + operator float() const; + + float value() const; + }; + + template < RotationModifierType ModifierType, bool is_const > + FGL_FORCE_INLINE_FLATTEN inline RotationModifier< ModifierType, is_const >::operator float() const + { + return value(); } - template < RotationModifierType ModifierType > - Rotation& RotationModifier< ModifierType >::operator-=( const float scalar ) + template < RotationModifierType ModifierType, bool is_const > + float RotationModifier< ModifierType, is_const >::value() const { - rot = - Rotation( static_cast< glm::quat >( rot ) * glm::angleAxis( -scalar, getModifierAxis< ModifierType >() ) ); - return rot; + switch ( ModifierType ) + { + default: + FGL_UNREACHABLE(); + case Pitch: + return glm::pitch( rot ); + case Roll: + return glm::roll( rot ); + case Yaw: + return glm::yaw( rot ); + } + + FGL_UNREACHABLE(); + } + + namespace constants + { + constexpr glm::vec3 DEFAULT_ROTATION { 0.0f, 0.0f, 0.0f }; } } // namespace fgl::engine diff --git a/src/engine/primitives/TransformComponent.cpp b/src/engine/primitives/TransformComponent.cpp index 35859f7..d557a42 100644 --- a/src/engine/primitives/TransformComponent.cpp +++ b/src/engine/primitives/TransformComponent.cpp @@ -4,8 +4,6 @@ #include "TransformComponent.hpp" -#include "engine/math/taitBryanMatrix.hpp" - namespace fgl::engine { @@ -26,4 +24,19 @@ namespace fgl::engine return Matrix< MatrixType::ModelToWorld >( mat4() ); } + NormalVector TransformComponent::forward() const + { + return rotation.forward(); + } + + NormalVector TransformComponent::right() const + { + return rotation.right(); + } + + NormalVector TransformComponent::up() const + { + return rotation.up(); + } + } // namespace fgl::engine diff --git a/src/engine/primitives/TransformComponent.hpp b/src/engine/primitives/TransformComponent.hpp index 3fdf5a1..509a63e 100644 --- a/src/engine/primitives/TransformComponent.hpp +++ b/src/engine/primitives/TransformComponent.hpp @@ -25,6 +25,18 @@ namespace fgl::engine glm::mat4 mat4() const; Matrix< MatrixType::ModelToWorld > mat() const; + + NormalVector forward() const; + + NormalVector backwards() const { return -forward(); } + + NormalVector right() const; + + NormalVector left() const { return -right(); } + + NormalVector up() const; + + NormalVector down() const { return -up(); } }; } // namespace fgl::engine diff --git a/src/engine/primitives/matricies/RotationMatrix.hpp b/src/engine/primitives/matricies/RotationMatrix.hpp index 90730ad..3230b2b 100644 --- a/src/engine/primitives/matricies/RotationMatrix.hpp +++ b/src/engine/primitives/matricies/RotationMatrix.hpp @@ -19,7 +19,7 @@ namespace fgl::engine {}; //This will return a normal vector since it's purely a rotation - NormalVector operator*( const RotationMatrix rot_mat, const NormalVector vec ); - Vector operator*( const RotationMatrix rot_mat, const Vector vec ); + NormalVector operator*( const RotationMatrix& rot_mat, const NormalVector vec ); + Vector operator*( const RotationMatrix& rot_mat, const Vector& vec ); } // namespace fgl::engine diff --git a/src/engine/primitives/matricies/mult_operators.cpp b/src/engine/primitives/matricies/mult_operators.cpp index 614475a..cb3771e 100644 --- a/src/engine/primitives/matricies/mult_operators.cpp +++ b/src/engine/primitives/matricies/mult_operators.cpp @@ -2,6 +2,8 @@ // Created by kj16609 on 2/28/24. // +#include + #include "RotationMatrix.hpp" #include "engine/primitives/vectors/NormalVector.hpp" #include "engine/primitives/vectors/Vector.hpp" @@ -9,14 +11,14 @@ namespace fgl::engine { - NormalVector operator*( const RotationMatrix rot_mat, const NormalVector vec ) + NormalVector operator*( const RotationMatrix& rot_mat, const NormalVector vec ) { - return NormalVector( static_cast< glm::mat4 >( rot_mat ) * glm::vec4( vec.vec(), 0.0f ) ); + return NormalVector( static_cast< glm::mat3 >( rot_mat ) * vec.vec() ); } - Vector operator*( const RotationMatrix rot_mat, const Vector vec ) + Vector operator*( const RotationMatrix& rot_mat, const Vector& vec ) { - return Vector( static_cast< glm::mat4 >( rot_mat ) * glm::vec4( vec.vec(), 0.0f ) ); + return Vector( static_cast< glm::mat3 >( rot_mat ) * vec.vec() ); } } // namespace fgl::engine diff --git a/src/engine/primitives/vectors/NormalVector.cpp b/src/engine/primitives/vectors/NormalVector.cpp index 97a6dec..0773a91 100644 --- a/src/engine/primitives/vectors/NormalVector.cpp +++ b/src/engine/primitives/vectors/NormalVector.cpp @@ -9,7 +9,7 @@ namespace fgl::engine { - NormalVector::NormalVector( const glm::vec3 vector ) : glm::vec3( glm::normalize( vector ) ) + constexpr NormalVector::NormalVector( const glm::vec3 vector ) : glm::vec3( glm::normalize( vector ) ) {} NormalVector::NormalVector( const fgl::engine::Vector vector ) : NormalVector( vector.vec() ) diff --git a/src/engine/primitives/vectors/NormalVector.hpp b/src/engine/primitives/vectors/NormalVector.hpp index 0514ca8..ec70c0e 100644 --- a/src/engine/primitives/vectors/NormalVector.hpp +++ b/src/engine/primitives/vectors/NormalVector.hpp @@ -38,7 +38,7 @@ namespace fgl::engine NormalVector( const Vector vec ); - explicit NormalVector( const glm::vec3 vec ); + explicit constexpr NormalVector( const glm::vec3 vec ); Vector operator*( const float scalar ) const; diff --git a/src/engine/primitives/vectors/Vector.hpp b/src/engine/primitives/vectors/Vector.hpp index f47c2b5..48d47f7 100644 --- a/src/engine/primitives/vectors/Vector.hpp +++ b/src/engine/primitives/vectors/Vector.hpp @@ -26,6 +26,10 @@ namespace fgl::engine { public: + using glm::vec3::x; + using glm::vec3::y; + using glm::vec3::z; + const glm::vec3& vec() const { return static_cast< const glm::vec3& >( *this ); } glm::vec3& vec() { return static_cast< glm::vec3& >( *this ); } @@ -68,6 +72,7 @@ namespace fgl::engine { return coord - *this; } + }; inline Vector operator-( const Vector vec ) diff --git a/src/engine/texture/Texture.cpp b/src/engine/texture/Texture.cpp index babe74e..ca009e8 100644 --- a/src/engine/texture/Texture.cpp +++ b/src/engine/texture/Texture.cpp @@ -24,11 +24,26 @@ namespace fgl::engine { - //TODO: We should be trying to re-use IDs that are released from textures so we can prevent this number from getting extremely large. - std::uint32_t getNextID() + using TextureID = std::uint32_t; + static std::queue< TextureID > unused_ids {}; + + TextureID getNextID() { - static std::uint32_t id { 0 }; - return id++; + static TextureID id { 0 }; + + if ( unused_ids.size() > 0 ) + { + const TextureID pulled_id { unused_ids.front() }; + unused_ids.pop(); + + log::debug( "Gave ID {} to texture", pulled_id ); + + return pulled_id; + } + else + { + return id++; + } } std::tuple< std::vector< std::byte >, int, int, vk::Format > @@ -145,6 +160,7 @@ namespace fgl::engine Texture::~Texture() { if ( m_imgui_set != VK_NULL_HANDLE ) ImGui_ImplVulkan_RemoveTexture( m_imgui_set ); + unused_ids.push( m_texture_id ); } vk::DescriptorImageInfo Texture::getDescriptor() const diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..a3f2cbe --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +if (NOT DEFINED FGL_ENABLE_TESTS) + set(FGL_ENABLE_TESTS 0) +endif () + + +if (FGL_ENABLE_TESTS) + message("-- FGL_ENABLE_TESTS: Enabled") + enable_testing() + + file(GLOB_RECURSE FGL_TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/**.cpp") + + set(CMAKE_CXX_STANDARD_REQUIRED 23) + + add_executable(FGLTests ${FGL_TEST_SOURCES}) + target_link_libraries(FGLTests PRIVATE FGLEngine Catch2::Catch2WithMain) + target_compile_definitions(FGLTests PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_FORCE_LEFT_HANDED) + target_compile_features(FGLTests PRIVATE cxx_std_23) + + include(CTest) + include(Catch) + catch_discover_tests(FGLTests) +else () + message("-- FGL_ENABLE_TESTS: Disabled") +endif () \ No newline at end of file diff --git a/tests/src/BoundingBoxTest.cpp b/src/tests/src/BoundingBoxTest.cpp.disabled similarity index 100% rename from tests/src/BoundingBoxTest.cpp rename to src/tests/src/BoundingBoxTest.cpp.disabled diff --git a/tests/src/CameraTesting.cpp b/src/tests/src/CameraTesting.cpp.disabled similarity index 98% rename from tests/src/CameraTesting.cpp rename to src/tests/src/CameraTesting.cpp.disabled index acfa979..95de5da 100644 --- a/tests/src/CameraTesting.cpp +++ b/src/tests/src/CameraTesting.cpp.disabled @@ -7,7 +7,7 @@ #include #define EXPOSE_CAMERA_INTERNAL -#include "engine/Camera.hpp" +#include "engine/camera/Camera.hpp" #include "gtest_printers.hpp" using namespace fgl::engine; @@ -30,7 +30,7 @@ TEST_CASE( "Camera", "[camera]" ) WHEN( "Camera is it's default orientation" ) { - camera.setView( constants::WORLD_CENTER, Rotation( 0.0f ) ); + camera.setView( WorldCoordinate( constants::WORLD_CENTER ), Rotation( 0.0f ) ); CAPTURE( camera.view_matrix ); diff --git a/tests/src/FrustumTesting.cpp b/src/tests/src/FrustumTesting.cpp.disabled similarity index 96% rename from tests/src/FrustumTesting.cpp rename to src/tests/src/FrustumTesting.cpp.disabled index ccbb138..a26ce66 100644 --- a/tests/src/FrustumTesting.cpp +++ b/src/tests/src/FrustumTesting.cpp.disabled @@ -6,9 +6,9 @@ #include -#define EXPOSE_FRUSTUM_INTERNALS -#define EXPOSE_CAMERA_INTERNAL -#include "engine/Camera.hpp" +#define EXPOSE_FRUSTUM_TESTS +#define EXPOSE_CAMERA_TESTS +#include "engine/camera/Camera.hpp" #include "engine/primitives/Frustum.hpp" #include "engine/primitives/boxes/OrientedBoundingBox.hpp" #include "gtest_printers.hpp" @@ -21,7 +21,7 @@ constexpr float ASPECT_RATIO { static_cast< float >( width ) / static_cast< floa TEST_CASE( "Frustum", "[frustum][rotation][translation]" ) { - Camera camera {}; + Camera camera { Camera::CREATE_TESTING_CAMERA() }; camera.setPerspectiveProjection( 90.0f, ASPECT_RATIO, constants::NEAR_PLANE, constants::FAR_PLANE ); GIVEN( "A default frustum from a default camera" ) @@ -42,7 +42,8 @@ TEST_CASE( "Frustum", "[frustum][rotation][translation]" ) { const LineSegment< CoordinateSpace::World > line { constants::WORLD_BACKWARD + ( constants::WORLD_UP * 1.0f ), - constants::WORLD_BACKWARD + ( constants::WORLD_DOWN * 1.0f ) }; + constants::WORLD_BACKWARD + ( constants::WORLD_DOWN * 1.0f ) + }; THEN( "The signed distance of the end to the start should be positive" ) { @@ -161,7 +162,8 @@ TEST_CASE( "Frustum", "[frustum][rotation][translation]" ) { const LineSegment< CoordinateSpace::World > line { constants::WORLD_FORWARD + ( constants::WORLD_UP * 2.0f ), - constants::WORLD_FORWARD + ( constants::WORLD_DOWN * 2.0f ) }; + constants::WORLD_FORWARD + ( constants::WORLD_DOWN * 2.0f ) + }; THEN( "The line should intersect the frustum" ) { diff --git a/tests/src/PlaneTests.cpp b/src/tests/src/PlaneTests.cpp.disabled similarity index 88% rename from tests/src/PlaneTests.cpp rename to src/tests/src/PlaneTests.cpp.disabled index f99ee39..e4159e3 100644 --- a/tests/src/PlaneTests.cpp +++ b/src/tests/src/PlaneTests.cpp.disabled @@ -7,9 +7,11 @@ #include #define EXPOSE_CAMERA_INTERNAL -#include "engine/Camera.hpp" #include "engine/primitives/Frustum.hpp" +#include "engine/primitives/TransformComponent.hpp" +#include "engine/primitives/lines/LineSegment.hpp" #include "gtest_printers.hpp" +#include "operators/vector.hpp" using namespace fgl::engine; @@ -26,18 +28,19 @@ TEST_CASE( "Planes", "[frustum][rotation][translation]" ) THEN( "Direction should be WORLD_FORWARD" ) { - REQUIRE( plane.direction() == constants::WORLD_FORWARD ); + REQUIRE( plane.getDirection() == NormalVector( constants::WORLD_FORWARD ) ); } THEN( "Position should be Y+ infinity" ) { - REQUIRE( plane.getPosition() == constants::DEFAULT_VEC3 * constants::WORLD_FORWARD ); + REQUIRE( plane.getPosition() == WorldCoordinate( constants::DEFAULT_VEC3 * constants::WORLD_FORWARD ) ); } } + /* GIVEN( "A Plane pointing at WORLD_FORWARD with a distance of 0.5" ) { - const Plane< CoordinateSpace::Model > plane { constants::WORLD_FORWARD, 0.5f }; + const Plane< CoordinateSpace::Model > plane { Coordinate< CoordinateSpace::Model >( constants::WORLD_FORWARD ), 0.5f }; TransformComponent component { WorldCoordinate( constants::WORLD_CENTER ), glm::vec3( 1.0f ), @@ -132,7 +135,7 @@ TEST_CASE( "Planes", "[frustum][rotation][translation]" ) REQUIRE( translated_plane.getPosition() == constants::WORLD_RIGHT * 1.5f ); } } - } + }*/ } TEST_CASE( "Plane intersections", "[frustum][intersection]" ) @@ -143,11 +146,11 @@ TEST_CASE( "Plane intersections", "[frustum][intersection]" ) AND_GIVEN( "A plane facing toward line.start" ) { - const Plane< CoordinateSpace::World > plane { glm::normalize( line.start ), 0.0f }; + const Plane< CoordinateSpace::World > plane { glm::normalize( line.start.vec() ), 0.0f }; THEN( "The line should intersect" ) { - REQUIRE( plane.intersects( line ) ); + REQUIRE( line.intersects( plane ) ); AND_THEN( "The line intersection should be at origin" ) { @@ -170,7 +173,8 @@ TEST_CASE( "Plane intersections", "[frustum][intersection]" ) GIVEN( "A line going from WORLD_LEFT - WORLD_FRONT * 20.0 to WORLD_LEFT + WORLD_FRONT * 20.0f" ) { const LineSegment< CoordinateSpace::World > line { constants::WORLD_LEFT - ( constants::WORLD_FORWARD * 20.0f ), - constants::WORLD_LEFT + ( constants::WORLD_FORWARD * 20.0f ) }; + constants::WORLD_LEFT + + ( constants::WORLD_FORWARD * 20.0f ) }; AND_GIVEN( "A plane facing toward WORLD_FORWARD at distance -2.0f" ) { @@ -192,8 +196,8 @@ TEST_CASE( "Plane intersections", "[frustum][intersection]" ) { const LineSegment< fgl::engine::CoordinateSpace::World > line { constants::WORLD_UP * 5.0f - constants::WORLD_BACKWARD, - constants::WORLD_DOWN * 5.0f - - constants::WORLD_BACKWARD }; + constants::WORLD_DOWN * 5.0f - constants::WORLD_BACKWARD + }; AND_GIVEN( "A plane facing UP + FORWARD" ) { diff --git a/tests/src/TransformTests.cpp b/src/tests/src/TransformTests.cpp similarity index 80% rename from tests/src/TransformTests.cpp rename to src/tests/src/TransformTests.cpp index 398fff3..2a074b3 100644 --- a/tests/src/TransformTests.cpp +++ b/src/tests/src/TransformTests.cpp @@ -4,9 +4,9 @@ #include -#include "engine/math/taitBryanMatrix.hpp" #include "engine/primitives/TransformComponent.hpp" #include "gtest_printers.hpp" +#include "operators/vector.hpp" using namespace fgl::engine; @@ -14,7 +14,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) { TransformComponent component; - component.translation = constants::WORLD_CENTER; + component.translation = WorldCoordinate( constants::WORLD_CENTER ); component.scale = glm::vec3( 1.0f ); component.rotation = Rotation( 0.0f ); @@ -31,7 +31,6 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) THEN( "The rotation matrix is the identity matrix" ) { - REQUIRE( constants::MAT4_IDENTITY == taitBryanMatrix( component.rotation ) ); REQUIRE( constants::MAT4_IDENTITY == component.mat4() ); } @@ -39,20 +38,30 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) WHEN( "Rotated +90 Pitch" ) { //Rotate by pitch - component.rotation.pitch() = glm::radians( 90.0f ); - - const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) }; + component.rotation.pitch() = glm::radians( glm::radians( 90.0f ) ); THEN( "Forward should be WORLD_UP" ) { - REQUIRE( rotated_point == constants::WORLD_UP ); + REQUIRE( component.forward() == NormalVector( constants::WORLD_UP ) ); + } + + THEN( "WORLD_FORWARD should be rotated to WORLD_UP" ) + { + REQUIRE( + component.rotation.mat() * NormalVector( constants::WORLD_FORWARD ) + == NormalVector( constants::WORLD_UP ) ); + } + + THEN( "Pitch should be 90.0f" ) + { + REQUIRE( component.rotation.pitch() == glm::radians( 90.0f ) ); } } // Tests behaviour that a point from WORLD_FORWARD should end up WORLD_DOWN when pitched -90 degrees WHEN( "Rotated -90 Pitch" ) { - component.rotation.pitch() = -glm::radians( 90.0f ); + component.rotation.pitch() = -glm::radians( glm::radians( 90.0f ) ); const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) }; @@ -65,7 +74,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) // Tests behaviour that a point from WORLD_FORWARD should end up WORLD_RIGHT when yawed 90 degrees WHEN( "Rotated +90 Yaw" ) { - component.rotation.yaw() = glm::radians( 90.0f ); + component.rotation.yaw() = glm::radians( glm::radians( 90.0f ) ); const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) }; @@ -78,7 +87,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) // Tests behaviour that a point from WORLD_FORWARD should end up WORLD_LEFT when yawed -90 degrees WHEN( "Rotated -90 Yaw" ) { - component.rotation.yaw() = -glm::radians( 90.0f ); + component.rotation.yaw() = -glm::radians( glm::radians( 90.0f ) ); const glm::vec3 rotated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) }; @@ -92,7 +101,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) //This behaviour assumes that WORLD_RIGHT is 90 deg YAW+ from WORLD_FORWARD WHEN( "Rotated +90 Roll" ) { - component.rotation.roll() = glm::radians( 90.0f ); + component.rotation.roll() = glm::radians( glm::radians( 90.0f ) ); const glm::vec3 rotated_point { component.mat4() * glm::vec4( constants::WORLD_RIGHT, 1.0f ) }; @@ -105,7 +114,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) //Tests behaviour that a point from WORLD_RIGHT should end up WORLD_UP when rolled -90 degrees WHEN( "Rotated -90 Roll" ) { - component.rotation.roll() = -glm::radians( 90.0f ); + component.rotation.roll() = -glm::radians( glm::radians( 90.0f ) ); const glm::vec3 rotated_point { component.mat4() * glm::vec4( constants::WORLD_RIGHT, 1.0f ) }; @@ -116,6 +125,8 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) } } + + SECTION( "Translation" ) { WHEN( "Translated Z+" ) @@ -159,7 +170,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) { WHEN( "Translated X+1 and Rotated Y+90" ) { - component.rotation.yaw() = glm::radians( 90.0f ); + component.rotation.yaw() = glm::radians( glm::radians( 90.0f ) ); component.translation.right() += 1.0f; const glm::vec3 translated_point { component.mat4() * glm::vec4( constants::WORLD_FORWARD, 1.0f ) }; @@ -172,7 +183,7 @@ TEST_CASE( "Transform", "[transform][rotation][translation]" ) SECTION( "Translated X+1 Yaw-90" ) { - component.rotation.yaw() = glm::radians( -90.0f ); + component.rotation.yaw() = glm::radians( -glm::radians( 90.0f ) ); component.translation.right() += 1.0f; const glm::vec3 translated_point { component.mat4() * glm::vec4( TEST_POINT, 1.0f ) }; diff --git a/tests/src/VectorTests.cpp b/src/tests/src/VectorTests.cpp similarity index 57% rename from tests/src/VectorTests.cpp rename to src/tests/src/VectorTests.cpp index a8543f3..2d95606 100644 --- a/tests/src/VectorTests.cpp +++ b/src/tests/src/VectorTests.cpp @@ -4,9 +4,12 @@ #include +#include + #include "engine/primitives/TransformComponent.hpp" #include "engine/primitives/vectors/Vector.hpp" #include "gtest_printers.hpp" +#include "operators/vector.hpp" using namespace fgl::engine; @@ -31,7 +34,7 @@ TEST_CASE( "Vector", "[vector][transforms]" ) WHEN( "Rotated +90 yaw" ) { - Vector rotation_vec { constants::WORLD_FORWARD }; + Vector rotation_vec { NormalVector( constants::WORLD_FORWARD ) }; //Rotate by 90 degrees on yaw TransformComponent transform; @@ -41,13 +44,13 @@ TEST_CASE( "Vector", "[vector][transforms]" ) THEN( "Forward should be WORLD_RIGHT" ) { - REQUIRE( value == constants::WORLD_RIGHT ); + REQUIRE( value == Vector( constants::WORLD_RIGHT ) ); } } WHEN( "Rotated -90 yaw" ) { - Vector rotation_vec { constants::WORLD_FORWARD }; + Vector rotation_vec { NormalVector( constants::WORLD_FORWARD ) }; //Rotate by 90 degrees on yaw TransformComponent transform; @@ -57,7 +60,7 @@ TEST_CASE( "Vector", "[vector][transforms]" ) THEN( "Forward should be WORLD_LEFT" ) { - REQUIRE( value == constants::WORLD_LEFT ); + REQUIRE( value == Vector( constants::WORLD_LEFT ) ); } } } @@ -82,22 +85,48 @@ TEST_CASE( "Rotation", "[vector][transforms]" ) THEN( "Forward should be WORLD_FORWARD" ) { - REQUIRE( rot.forward() == constants::WORLD_FORWARD ); + REQUIRE( rot.forward() == NormalVector( constants::WORLD_FORWARD ) ); } THEN( "Backwards should be WORLD_BACKWARD" ) { - REQUIRE( rot.backwards() == constants::WORLD_BACKWARD ); + REQUIRE( -rot.forward() == NormalVector( constants::WORLD_BACKWARD ) ); } THEN( "Right should be WORLD_RIGHT" ) { - REQUIRE( rot.right( constants::WORLD_UP ) == constants::WORLD_RIGHT ); + REQUIRE( rot.right() == NormalVector( constants::WORLD_RIGHT ) ); } THEN( "Left should be WORLD_LEFT" ) { - REQUIRE( rot.left( constants::WORLD_UP ) == constants::WORLD_LEFT ); + REQUIRE( -rot.right() == NormalVector( constants::WORLD_LEFT ) ); + } + } + + GIVEN( "A rotation constructed" ) + { + constexpr auto rad_90 { glm::radians( 90.0f ) }; + + AND_WHEN( "Given 90.0f pitch" ) + { + Rotation rotation { rad_90, 0.0f, 0.0f }; + + REQUIRE( rotation.pitch() == Catch::Approx( rad_90 ).epsilon( 0.01 ) ); + } + + AND_WHEN( "Given 90.0f yaw" ) + { + Rotation rotation { 0.0f, rad_90, 0.0f }; + + REQUIRE( rotation.yaw() == Catch::Approx( rad_90 ).epsilon( 0.01 ) ); + } + + AND_WHEN( "Given 90.0f roll" ) + { + Rotation rotation { 0.0f, 0.0f, rad_90 }; + + REQUIRE( rotation.roll() == Catch::Approx( rad_90 ).epsilon( 0.01 ) ); } } @@ -109,22 +138,22 @@ TEST_CASE( "Rotation", "[vector][transforms]" ) THEN( "Forward should be WORLD_RIGHT" ) { - REQUIRE( rot.forward() == constants::WORLD_RIGHT ); + REQUIRE( rot.forward() == NormalVector( constants::WORLD_RIGHT ) ); } THEN( "Backwards should be WORLD_LEFT" ) { - REQUIRE( rot.backwards() == constants::WORLD_LEFT ); + REQUIRE( rot.back() == NormalVector( constants::WORLD_LEFT ) ); } THEN( "Right should be WORLD_BACKWARD" ) { - REQUIRE( rot.right( constants::WORLD_UP ) == constants::WORLD_BACKWARD ); + REQUIRE( rot.right() == NormalVector( constants::WORLD_BACKWARD ) ); } THEN( "Left should be WORLD_FORWARD" ) { - REQUIRE( rot.left( constants::WORLD_UP ) == constants::WORLD_FORWARD ); + REQUIRE( rot.left() == NormalVector( constants::WORLD_FORWARD ) ); } } @@ -134,22 +163,22 @@ TEST_CASE( "Rotation", "[vector][transforms]" ) THEN( "Forward should be WORLD_LEFT" ) { - REQUIRE( rot.forward() == constants::WORLD_LEFT ); + REQUIRE( rot.forward() == NormalVector( constants::WORLD_LEFT ) ); } THEN( "Backwards should be WORLD_RIGHT" ) { - REQUIRE( rot.backwards() == constants::WORLD_RIGHT ); + REQUIRE( rot.back() == NormalVector( constants::WORLD_RIGHT ) ); } THEN( "Right should be WORLD_FORWARD" ) { - REQUIRE( rot.right( constants::WORLD_UP ) == constants::WORLD_FORWARD ); + REQUIRE( rot.right() == NormalVector( constants::WORLD_FORWARD ) ); } THEN( "Left should be WORLD_BACKWARD" ) { - REQUIRE( rot.left( constants::WORLD_UP ) == constants::WORLD_BACKWARD ); + REQUIRE( rot.left() == NormalVector( constants::WORLD_BACKWARD ) ); } } } diff --git a/tests/src/gtest_printers.hpp b/src/tests/src/gtest_printers.hpp similarity index 79% rename from tests/src/gtest_printers.hpp rename to src/tests/src/gtest_printers.hpp index df839e1..21e46a3 100644 --- a/tests/src/gtest_printers.hpp +++ b/src/tests/src/gtest_printers.hpp @@ -26,7 +26,7 @@ namespace Catch { static std::string convert( const fgl::engine::Vector& vec ) { - return StringMaker< glm::vec3 >::convert( static_cast< glm::vec3 >( vec ) ); + return StringMaker< glm::vec3 >::convert( static_cast< glm::vec3 >( vec.vec() ) ); } }; @@ -35,7 +35,7 @@ namespace Catch { static std::string convert( const fgl::engine::Rotation& rot ) { - return StringMaker< glm::vec3 >::convert( static_cast< glm::vec3 >( rot ) ); + return StringMaker< glm::vec3 >::convert( { rot.pitch(), rot.roll(), rot.yaw() } ); } }; @@ -58,6 +58,15 @@ namespace Catch } }; + template <> + struct StringMaker< fgl::engine::NormalVector > + { + static std::string convert( const fgl::engine::NormalVector vec ) + { + return StringMaker< fgl::engine::Vector >::convert( static_cast< fgl::engine::Vector >( vec ) ); + } + }; + } // namespace Catch #ifndef NDEBUG @@ -70,5 +79,5 @@ namespace glm } // namespace glm #else -#warning "Debug mode not enabled. Tests will pass when checking for floating point equality." +#warning "Debug mode not enabled. Tests will fail when checking for floating point equality." #endif diff --git a/src/tests/src/operators/vector.hpp b/src/tests/src/operators/vector.hpp new file mode 100644 index 0000000..93970dc --- /dev/null +++ b/src/tests/src/operators/vector.hpp @@ -0,0 +1,32 @@ +// +// Created by kj16609 on 8/4/24. +// + +#pragma once + +namespace fgl::engine +{ + + inline bool operator==( const NormalVector& left, const NormalVector& right ) + { + const glm::vec3 high_range { left.vec() + glm::vec3( std::numeric_limits< float >::epsilon() ) }; + const glm::vec3 low_range { left.vec() - glm::vec3( std::numeric_limits< float >::epsilon() ) }; + + const auto within_high { glm::lessThanEqual( right.vec(), high_range ) }; + const auto within_low { glm::greaterThanEqual( right.vec(), low_range ) }; + + return glm::all( within_high ) && glm::all( within_low ); + } + + inline bool operator==( const Vector& left, const Vector& right ) + { + const glm::vec3 high_range { left.vec() + glm::vec3( std::numeric_limits< float >::epsilon() ) }; + const glm::vec3 low_range { left.vec() - glm::vec3( std::numeric_limits< float >::epsilon() ) }; + + const auto within_high { glm::lessThanEqual( right.vec(), high_range ) }; + const auto within_low { glm::greaterThanEqual( right.vec(), low_range ) }; + + return glm::all( within_high ) && glm::all( within_low ); + } + +} // namespace fgl::engine diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index d24851b..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - - -if (DEFINED FGL_ENABLE_TESTS) - enable_testing() - - file(GLOB_RECURSE FGL_TEST_SOURCES "*.cpp") - - add_executable(FGLTests ${FGL_TEST_SOURCES}) - target_link_libraries(FGLTests FGLEngine Catch2::Catch2WithMain) - target_compile_definitions(FGLTests PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_FORCE_LEFT_HANDED) - - include(CTest) - include(Catch) - catch_discover_tests(FGLTests) -endif () \ No newline at end of file diff --git a/tests/src/taitBryanMatrixTests.cpp b/tests/src/taitBryanMatrixTests.cpp deleted file mode 100644 index be5f3e9..0000000 --- a/tests/src/taitBryanMatrixTests.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by kj16609 on 2/19/24. -// - -#include - -#include "engine/Camera.hpp" -#include "engine/math/taitBryanMatrix.hpp" -#include "gtest_printers.hpp" - -using namespace fgl::engine; - -TEST_CASE( "Tait-Bryan rotations", "[matrix][rotation][camera]" ) -{ - WHEN( "Rotation is default constructed" ) - { - THEN( "The rotation is (0,0,0)" ) - { - Rotation rotation; - REQUIRE( rotation.pitch() == 0.0f ); - REQUIRE( rotation.yaw() == 0.0f ); - REQUIRE( rotation.roll() == 0.0f ); - } - } - - WHEN( "Given a default rotation (0,0,0)" ) - { - Rotation rot; - - THEN( "The rotation matrix is the identity matrix" ) - { - REQUIRE( constants::MAT4_IDENTITY == taitBryanMatrix( rot ) ); - } - } -}