diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 25a65db..c534380 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -476,7 +476,7 @@ namespace fgl::engine { auto sponza = GameObject::createGameObject(); sponza.model = model; - sponza.transform.translation = { 0.0f + ( y * 30 ), 1.0f, 0.0f + ( x * 20 ) }; + sponza.transform.translation = { 0.0f + ( y * 30 ), 0.0f + ( x * 20 ), 0.0f }; sponza.transform.scale = { 0.007f, 0.007f, 0.007f }; sponza.transform.rotation = { 0.0f, 0.0f, 0.0f }; diff --git a/src/engine/KeyboardMovementController.cpp b/src/engine/KeyboardMovementController.cpp index 3f6c079..3c27b43 100644 --- a/src/engine/KeyboardMovementController.cpp +++ b/src/engine/KeyboardMovementController.cpp @@ -27,8 +27,6 @@ namespace fgl::engine void KeyboardMovementController::moveInPlaneXZ( GLFWwindow* window, float dt, fgl::engine::GameObject& target ) { - ImGui::Begin( "CameraMovement" ); - Rotation rotate { 0.0f }; if ( glfwGetKey( window, key_mappings.look_right ) == GLFW_PRESS ) rotate.yaw() += 1.f; @@ -108,13 +106,6 @@ namespace fgl::engine if ( glm::dot( move_dir, move_dir ) > std::numeric_limits< float >::epsilon() ) target.transform.translation += ( move_speed * dt ) * glm::normalize( move_dir ); - - ImGui::Text( "Transform" ); - ImGui::InputFloat( "X", &target.transform.translation.x, -10.0, 10.0 ); - ImGui::InputFloat( "Y", &target.transform.translation.y, -10.0, 10.0 ); - ImGui::InputFloat( "Z", &target.transform.translation.z, -10.0, 10.0 ); - - ImGui::End(); } } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/debug/drawers.cpp b/src/engine/debug/drawers.cpp index ff35410..c100d4a 100644 --- a/src/engine/debug/drawers.cpp +++ b/src/engine/debug/drawers.cpp @@ -10,6 +10,8 @@ #include "engine/primitives/Vector.hpp" #include "tracy_colors.hpp" +#ifndef NDEBUG + namespace fgl::engine::debug { const ImVec2 windowSize() @@ -253,3 +255,5 @@ namespace fgl::engine::debug } // namespace screen } // namespace fgl::engine::debug + +#endif diff --git a/src/engine/debug/drawers.hpp b/src/engine/debug/drawers.hpp index abefbed..b63d823 100644 --- a/src/engine/debug/drawers.hpp +++ b/src/engine/debug/drawers.hpp @@ -26,6 +26,7 @@ namespace fgl::engine } // namespace fgl::engine +#ifndef NDEBUG namespace fgl::engine::debug { @@ -100,4 +101,64 @@ namespace fgl::engine::debug } // namespace screen -} // namespace fgl::engine::debug \ No newline at end of file +} // namespace fgl::engine::debug +#else + +namespace fgl::engine::debug +{ + namespace world + { + //Dummy functions + inline void drawBoundingBox( const BoundingBox< CoordinateSpace::World >&, Camera&, const glm::vec3 ) + {} + + inline void drawBoundingBox( const BoundingBox< CoordinateSpace::World >&, Camera& ) + {} + + inline void drawLine( + const Coordinate< CoordinateSpace::World >, + const Coordinate< CoordinateSpace::World >, + const Camera&, + const glm::vec3 ) + {} + + inline void drawPointLabel( const Coordinate< CoordinateSpace::World >, const std::string, const Camera& ) + {} + + inline void drawLine( const Line< CoordinateSpace::World >, const Camera&, const glm::vec3 ) + {} + + inline void drawPointText( const Coordinate< CoordinateSpace::World >, const Camera&, const glm::vec3 ) + {} + + inline void + drawBoolAlpha( const Coordinate< CoordinateSpace::World >, const Camera&, const bool, const glm::vec2 ) + {} + + inline void + drawPoint( const Coordinate< CoordinateSpace::World >, const Camera&, const std::string, const glm::vec3 ) + {} + + inline void drawVector( + const Coordinate< CoordinateSpace::World >, Vector, const Camera&, const std::string, const glm::vec3 ) + {} + + inline void drawFrustum( const Frustum< CoordinateSpace::World >&, const Camera&, const WorldCoordinate ) + {} + + inline void drawFrustum( const Camera& ) + {} + + inline void drawPlane( + const Plane< CoordinateSpace::World >&, + const WorldCoordinate, + const Camera&, + const std::string, + const glm::vec3 ) + {} + + } // namespace world + +} // namespace fgl::engine::debug + +#endif diff --git a/src/engine/math/taitBryanMatrix.cpp b/src/engine/math/taitBryanMatrix.cpp index d0f03fa..805b11c 100644 --- a/src/engine/math/taitBryanMatrix.cpp +++ b/src/engine/math/taitBryanMatrix.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "engine/primitives/Rotation.hpp" diff --git a/src/engine/systems/EntityRendererSystem.cpp b/src/engine/systems/EntityRendererSystem.cpp index 0e255f1..3493020 100644 --- a/src/engine/systems/EntityRendererSystem.cpp +++ b/src/engine/systems/EntityRendererSystem.cpp @@ -99,10 +99,10 @@ namespace fgl::engine obj.model->getBoundingBox( Matrix< MatrixType::ModelToWorld >( obj.transform.mat4() ) ) }; - debug::world::drawBoundingBox( model_bounding_box, info.camera ); - if ( !model_bounding_box.isInFrustum( info.camera_frustum ) ) continue; + debug::world::drawBoundingBox( model_bounding_box, info.camera ); + for ( const auto& primitive : obj.model->m_primitives ) { ZoneScopedN( "Queue Primitive" ); @@ -130,29 +130,6 @@ namespace fgl::engine //Draw command for this mesh already exists. Simply add a count to it auto [ existing_cmd, model_matrix ] = *itter; - //Sort each model matrix by distance from camera. Render closest first - const auto camera_pos { info.camera.getPosition() }; - - { - ZoneScopedN( "Sort model matricies by distance" ); - std::sort( - model_matrix.begin(), - model_matrix.end(), - [ camera_pos ]( const ModelMatrixInfo& first, const ModelMatrixInfo& second ) -> bool - { - const auto& first_pos_v4 { first.model_matrix[ 3 ] }; - const auto& second_pos_v4 { second.model_matrix[ 3 ] }; - - const glm::vec3 first_pos { first_pos_v4.x, first_pos_v4.y, first_pos_v4.z }; - const glm::vec3 second_pos { second_pos_v4.x, second_pos_v4.y, second_pos_v4.z }; - - const auto first_distance { glm::distance( first_pos, camera_pos ) }; - const auto second_distance { glm::distance( second_pos, camera_pos ) }; - - return first_distance < second_distance; - } ); - } - draw_pairs.erase( itter ); existing_cmd.instanceCount++; model_matrix.emplace_back( matrix_info ); @@ -176,12 +153,27 @@ namespace fgl::engine std::vector< vk::DrawIndexedIndirectCommand > draw_commands; std::vector< ModelMatrixInfo > model_matrices; + const auto camera_pos { info.camera.getPosition() }; + + auto sortFunc = [ camera_pos ]( const ModelMatrixInfo first, const ModelMatrixInfo second ) -> bool + { + const glm::vec3 first_pos { first.model_matrix[ 3 ] }; + const float first_distance { glm::distance( first_pos, camera_pos ) }; + + const glm::vec3 second_pos { second.model_matrix[ 3 ] }; + const float second_distance { glm::distance( second_pos, camera_pos ) }; + + return first_distance < second_distance; + }; + TracyCZoneN( filter_zone_TRACY, "Reorganize draw commands", true ); for ( auto& itter : draw_pairs ) { auto cmd { itter.first }; cmd.firstInstance = model_matrices.size(); - auto& matricies { itter.second }; + auto matricies { std::move( itter.second ) }; + + std::sort( matricies.begin(), matricies.end(), sortFunc ); draw_commands.emplace_back( cmd ); model_matrices.insert( model_matrices.end(), matricies.begin(), matricies.end() );