feat: add imguizmo + trigger buxfix

This commit is contained in:
2026-10-18 11:45:37 +02:00
parent 70c940c476
commit 4bd99b25d1
37 changed files with 700 additions and 58 deletions
+52 -3
View File
@@ -33,6 +33,7 @@ void LightKeeper::customInit()
const float aspectRatio = static_cast<float>(m_params.renderSize.x) / static_cast<float>(m_params.renderSize.y);
camera.setAspectRatio(aspectRatio);
camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
window.Maximize();
setupSkybox();
@@ -44,6 +45,7 @@ void LightKeeper::customInit()
hudFont = Font::LoadFromFile(AssetFS::GetInstance().GetFullPath("engine://fonts/Roboto-Medium.ttf"));
hudFont.Upload(gfxDevice, resources);
}
void LightKeeper::setupSkybox()
@@ -62,6 +64,8 @@ void LightKeeper::setupSkybox()
void LightKeeper::customUpdate(float dt)
{
updateViewMode();
// LightKeeper owns a camera that hides App::camera; update this instance
// after SDL events have been consumed.
if (!isPlayerViewActive() && getSceneCamera() == nullptr)
@@ -79,6 +83,45 @@ void LightKeeper::customUpdate(float dt)
updateDebugUi();
}
void LightKeeper::updateViewMode()
{
auto& input = InputManager::GetInstance();
FirstPersonController* player = mainScene.playerController;
if (player != nullptr && input.WasKeyPressed(SDL_SCANCODE_F5))
{
player->SetPossessed(!player->IsPossessed());
}
if (!isPlayerViewActive())
{
const bool looking = input.IsMouseDown(SDL_BUTTON_RIGHT);
if (looking != input.IsMouseCaptured())
{
input.SetMouseCaptured(looking);
}
}
}
void LightKeeper::drawViewModeHint()
{
if (isPlayerViewActive() || mainScene.playerController == nullptr) {
return;
}
constexpr std::string_view hint = "Free camera RMB look WASD / Q E move F5 play";
constexpr float hintSize = 18.0f;
const VkExtent3D extent = renderer.getDrawImage().extent;
const glm::vec2 hintExtent = hudFont.MeasureText(hint, hintSize);
Renderer2D::GetInstance().DrawText(
hudFont,
hint,
{16.0f, static_cast<float>(extent.height) - hintExtent.y - 12.0f},
hintSize,
TextStyle{.color = {1.0f, 1.0f, 1.0f, 0.85f}, .outline = 2.0f, .outlineColor = {0.0f, 0.0f, 0.0f, 0.6f}});
}
void LightKeeper::drawCrosshair()
{
if (!isPlayerViewActive()) {
@@ -114,7 +157,7 @@ void LightKeeper::drawCrosshair()
bool LightKeeper::isPlayerViewActive() const
{
return mainScene.playerController != nullptr && mainScene.playerController->IsMouseCaptured();
return mainScene.playerController != nullptr && mainScene.playerController->IsPossessed();
}
CameraComponent* LightKeeper::getSceneCamera() const
@@ -126,6 +169,12 @@ CameraComponent* LightKeeper::getSceneCamera() const
return activeScenes.front()->GetCurrentCamera();
}
Camera& LightKeeper::getViewCamera()
{
CameraComponent* sceneCamera = isPlayerViewActive() ? nullptr : getSceneCamera();
return sceneCamera != nullptr ? sceneCamera->GetCamera(camera.GetAspectRatio()) : camera;
}
void LightKeeper::customDraw()
{
const auto cmd = gfxDevice.beginFrame();
@@ -136,6 +185,7 @@ void LightKeeper::customDraw()
renderer.beginDrawing(gfxDevice);
submitDebugDraws();
drawCrosshair();
drawViewModeHint();
if (isPlayerViewActive())
{
@@ -145,8 +195,7 @@ void LightKeeper::customDraw()
camera.CalculateProjectionMatrix();
}
CameraComponent* sceneCamera = isPlayerViewActive() ? nullptr : getSceneCamera();
Camera& viewCamera = sceneCamera != nullptr ? sceneCamera->GetCamera(camera.GetAspectRatio()) : camera;
Camera& viewCamera = getViewCamera();
const SceneEnvironment& environment = SceneManager::GetInstance().GetCurrentScene().GetEnvironment();
const GameRenderer::SceneData sceneData{