feat: add interactable component and test button

This commit is contained in:
2026-10-16 23:25:11 +02:00
parent faba4171ec
commit 7dd5ee7903
14 changed files with 236 additions and 6 deletions
+26 -1
View File
@@ -2,9 +2,11 @@
#include <destrum/Components/CameraComponent.h>
#include <destrum/FS/AssetFS.h>
#include <destrum/Graphics/Managers/Renderer2D.h>
#include <destrum/Scene/Scene.h>
#include <components/FirstPersonController.h>
#include <components/Interactable.h>
#include <components/GameComponentRegistry.h>
LightKeeper::LightKeeper() : App()
@@ -69,6 +71,29 @@ void LightKeeper::customUpdate(float dt)
updateDebugUi();
}
void LightKeeper::drawCrosshair()
{
if (!isPlayerViewActive()) {
return;
}
const bool focused = mainScene.playerController->GetFocusedInteractable() != nullptr;
const glm::vec4 color = focused ? glm::vec4{1.0f, 0.8f, 0.25f, 1.0f} : glm::vec4{1.0f, 1.0f, 1.0f, 0.8f};
const float armLength = focused ? 16.0f : 10.0f;
constexpr float thickness = 2.0f;
const VkExtent3D extent = renderer.getDrawImage().extent;
const glm::vec2 center{static_cast<float>(extent.width) * 0.5f, static_cast<float>(extent.height) * 0.5f};
auto& renderer2D = Renderer2D::GetInstance();
const float halfArm = armLength * 0.5f;
renderer2D.DrawLine(center - glm::vec2{halfArm, 0.0f}, center + glm::vec2{halfArm, 0.0f}, thickness, color);
renderer2D.DrawLine(center - glm::vec2{0.0f, halfArm}, center + glm::vec2{0.0f, halfArm}, thickness, color);
if (focused) {
renderer2D.DrawEllipseOutline(center, glm::vec2{14.0f}, thickness, color);
}
}
bool LightKeeper::isPlayerViewActive() const
{
return mainScene.playerController != nullptr && mainScene.playerController->IsMouseCaptured();
@@ -92,8 +117,8 @@ void LightKeeper::customDraw()
renderer.beginDrawing(gfxDevice);
submitDebugDraws();
drawCrosshair();
// The player camera is placed here, after the fixed steps, so it can be interpolated between them
if (isPlayerViewActive())
{
camera.SetRotation(mainScene.playerController->GetYaw(), mainScene.playerController->GetPitch());