Seperate editor from engine lib

This commit is contained in:
2024-08-04 11:57:14 -04:00
parent 589cd75e5f
commit 849a1283cf
57 changed files with 806 additions and 609 deletions

View File

@@ -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)
target_compile_definitions(TitorEditor PUBLIC TITOR_EDITOR)
target_compile_features(TitorEditor PRIVATE cxx_std_23)

View File

@@ -4,6 +4,8 @@
#include "FileBrowser.hpp"
#include <cmath>
#include "engine/assets/stores.hpp"
#include "engine/filesystem/scanner/FileScanner.hpp"
#include "engine/filesystem/types.hpp"

View File

@@ -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();

View File

@@ -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 );

View File

@@ -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 ];
}
}

View File

@@ -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 ) };

View File

@@ -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() )