Added editor gridlines and cardinal axes
This commit is contained in:
parent
41e1f01f29
commit
82e0e4df5c
|
@ -72,6 +72,9 @@ namespace Sandbox
|
|||
SHSystemManager::CreateSystem<SHAudioSystem>();
|
||||
SHSystemManager::CreateSystem<SHCameraSystem>();
|
||||
SHSystemManager::CreateSystem<SHDebugDrawSystem>();
|
||||
|
||||
// Link up SHDebugDraw
|
||||
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
|
||||
|
||||
#ifdef SHEDITOR
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
@ -127,9 +130,6 @@ namespace Sandbox
|
|||
SHSceneManager::InitSceneManager<SBTestScene>("TestScene");
|
||||
|
||||
SHFrameRateController::UpdateFRC();
|
||||
|
||||
// Link up SHDebugDraw
|
||||
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
|
||||
}
|
||||
|
||||
void SBApplication::Update(void)
|
||||
|
@ -146,10 +146,6 @@ namespace Sandbox
|
|||
if(editor->editorState == SHEditor::State::PLAY)
|
||||
SHSceneManager::SceneUpdate(0.016f);
|
||||
#endif
|
||||
SHDebugDraw::Line(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), SHVec3(-5.0f, 0.0f, 0.0f), SHVec3(5.0f, 0.0f, 0.0f));
|
||||
SHDebugDraw::Line(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), SHVec3(-5.0f, 1.0f, 0.0f), SHVec3(5.0f, 1.0f, 0.0f));
|
||||
SHDebugDraw::Cube(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), {}, SHVec3(1.0f, 1.0f, 1.0f));
|
||||
SHDebugDraw::Sphere(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), {}, 3.0f);
|
||||
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f);
|
||||
editor->PollPicking();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <backends/imgui_impl_vulkan.h>
|
||||
|
||||
#include "Graphics/MiddleEnd/Interface/SHMousePickSystem.h"
|
||||
#include "Tools/SHDebugDraw.h"
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
|
@ -77,7 +78,6 @@ namespace SHADE
|
|||
//#==============================================================#
|
||||
void SHEditor::Init()
|
||||
{
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
if(auto context = ImGui::CreateContext())
|
||||
{
|
||||
|
@ -120,6 +120,17 @@ namespace SHADE
|
|||
window->Init();
|
||||
}
|
||||
|
||||
/* Editor View Gridlines */
|
||||
SetUpGridLines(true, true);
|
||||
// Handle state changes so that we only show in edit mode
|
||||
std::shared_ptr<SHEventReceiverSpec<SHEditor>> stateChangeEventReceiver
|
||||
{
|
||||
std::make_shared<SHEventReceiverSpec<SHEditor>>(this, &SHEditor::onEditorStateChanged)
|
||||
};
|
||||
SHEventManager::SubscribeTo(SH_EDITOR_ON_PLAY_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(stateChangeEventReceiver));
|
||||
SHEventManager::SubscribeTo(SH_EDITOR_ON_PAUSE_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(stateChangeEventReceiver));
|
||||
SHEventManager::SubscribeTo(SH_EDITOR_ON_STOP_EVENT, std::dynamic_pointer_cast<SHEventReceiver>(stateChangeEventReceiver));
|
||||
|
||||
SHLOG_INFO("Successfully initialised SHADE Engine Editor")
|
||||
}
|
||||
|
||||
|
@ -180,6 +191,97 @@ namespace SHADE
|
|||
io->Fonts->Build();
|
||||
}
|
||||
|
||||
void SHEditor::SetUpGridLines(bool drawGrid, bool drawAxes)
|
||||
{
|
||||
// Clear existing lines
|
||||
SHDebugDraw::ClearPersistentDraws();
|
||||
|
||||
static constexpr float DELTA = 1.0f;
|
||||
static constexpr int EXTENT_COUNT = static_cast<int>(500.0f /* TODO: Remove hard code */ / DELTA);
|
||||
static constexpr float LINE_HALF_LENGTH = (DELTA * static_cast<float>(EXTENT_COUNT)) * 0.5f;
|
||||
|
||||
// Render Grid
|
||||
static const SHColour GRID_COL = { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
if (drawGrid)
|
||||
{
|
||||
for (int i = 1; i < EXTENT_COUNT; ++i)
|
||||
{
|
||||
// X-Axis Lines
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
GRID_COL,
|
||||
SHVec3 { -LINE_HALF_LENGTH, 0.0f, i * DELTA },
|
||||
SHVec3 { LINE_HALF_LENGTH, 0.0f, i * DELTA }
|
||||
);
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
GRID_COL,
|
||||
SHVec3 { -LINE_HALF_LENGTH, 0.0f, i * -DELTA },
|
||||
SHVec3 { LINE_HALF_LENGTH, 0.0f, i * -DELTA }
|
||||
);
|
||||
// Y-Axis Lines
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
GRID_COL,
|
||||
SHVec3 { i * DELTA, 0.0f, -LINE_HALF_LENGTH },
|
||||
SHVec3 { i * DELTA, 0.0f, LINE_HALF_LENGTH }
|
||||
);
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
GRID_COL,
|
||||
SHVec3 { -i * DELTA, 0.0f, -LINE_HALF_LENGTH },
|
||||
SHVec3 { -i * DELTA, 0.0f, LINE_HALF_LENGTH }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Render World Axes
|
||||
if (drawAxes || drawGrid)
|
||||
{
|
||||
const SHColour X_AXIS_COL = drawAxes ? SHColour::RED : GRID_COL;
|
||||
const SHColour Y_AXIS_COL = drawAxes ? SHColour::GREEN : GRID_COL;
|
||||
const SHColour Z_AXIS_COL = drawAxes ? SHColour::BLUE : GRID_COL;
|
||||
// X
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
X_AXIS_COL,
|
||||
SHVec3 { -LINE_HALF_LENGTH, 0.0f, 0.0f },
|
||||
SHVec3 { LINE_HALF_LENGTH, 0.0f, 0.0f }
|
||||
);
|
||||
// Y
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
Y_AXIS_COL,
|
||||
SHVec3 { 0.0f, -LINE_HALF_LENGTH, 0.0f },
|
||||
SHVec3 { 0.0f, LINE_HALF_LENGTH, 0.0f }
|
||||
);
|
||||
// Z
|
||||
SHDebugDraw::PersistentLine
|
||||
(
|
||||
Z_AXIS_COL,
|
||||
SHVec3 { 0.0f, 0.0f, -LINE_HALF_LENGTH },
|
||||
SHVec3 { 0.0f, 0.0f, LINE_HALF_LENGTH }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SHEventHandle SHEditor::onEditorStateChanged(SHEventPtr eventPtr)
|
||||
{
|
||||
auto eventData = reinterpret_cast<const SHEventSpec<SHEditorStateChangeEvent>*>(eventPtr.get());
|
||||
switch (editorState)
|
||||
{
|
||||
case State::PAUSE:
|
||||
case State::STOP:
|
||||
SetUpGridLines(true, true);
|
||||
break;
|
||||
case State::PLAY:
|
||||
default:
|
||||
SHDebugDraw::ClearPersistentDraws();
|
||||
break;
|
||||
}
|
||||
return eventData->handle;
|
||||
}
|
||||
|
||||
void SHEditor::Exit()
|
||||
{
|
||||
for (const auto& window : SHEditorWindowManager::editorWindows | std::views::values)
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
#include "Resource/SHHandle.h"
|
||||
#include "EditorWindow/SHEditorWindow.h"
|
||||
#include "Tools/SHLog.h"
|
||||
#include "Gizmos/SHTransformGizmo.h"
|
||||
|
||||
#include "Gizmos/SHTransformGizmo.h"`
|
||||
#include "Events/SHEventDefines.h"
|
||||
#include "Events/SHEvent.h"
|
||||
|
||||
//#==============================================================#
|
||||
//|| Library Includes ||
|
||||
|
@ -194,6 +195,10 @@ namespace SHADE
|
|||
|
||||
void InitFonts() noexcept;
|
||||
|
||||
void SetUpGridLines(bool drawGrid, bool drawAxes);
|
||||
|
||||
SHEventHandle onEditorStateChanged(SHEventPtr eventPtr);
|
||||
|
||||
// Handle to command pool used for ImGui Vulkan Backend
|
||||
Handle<SHVkCommandPool> imguiCommandPool;
|
||||
// Handle to command buffer used for ImGui Vulkan Backend
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace SHADE
|
|||
// Get Current frame index
|
||||
const uint32_t FRAME_IDX = GFX_SYSTEM->GetCurrentFrameIndex();
|
||||
|
||||
// Set Pipeline
|
||||
// Set Pipelin
|
||||
cmdBuffer->BindPipeline(GFX_SYSTEM->GetDebugDrawPipeline());
|
||||
cmdBuffer->SetLineWidth(LineWidth);
|
||||
|
||||
|
|
Loading…
Reference in New Issue