feat: add imguizmo + trigger buxfix
This commit is contained in:
@@ -34,9 +34,12 @@ FirstPersonController::FirstPersonController(GameObject& parent)
|
||||
{
|
||||
}
|
||||
|
||||
void FirstPersonController::SetMouseCaptured(bool captured)
|
||||
void FirstPersonController::SetPossessed(bool possessed)
|
||||
{
|
||||
InputManager::GetInstance().SetMouseCaptured(captured);
|
||||
m_Possessed = possessed;
|
||||
m_JumpHeld = false;
|
||||
m_JumpBufferTimer = 0.0f;
|
||||
InputManager::GetInstance().SetMouseCaptured(possessed);
|
||||
}
|
||||
|
||||
void FirstPersonController::Start()
|
||||
@@ -65,26 +68,16 @@ void FirstPersonController::Update(float dt)
|
||||
{
|
||||
const auto& input = InputManager::GetInstance();
|
||||
|
||||
if (input.WasKeyPressed(SDL_SCANCODE_F5))
|
||||
{
|
||||
SetMouseCaptured(!IsMouseCaptured());
|
||||
}
|
||||
|
||||
m_FocusedInteractable = nullptr;
|
||||
|
||||
if (!IsMouseCaptured())
|
||||
if (!m_Possessed)
|
||||
{
|
||||
m_JumpHeld = false;
|
||||
if (input.WasMousePressed(SDL_BUTTON_LEFT) && !ImGui::GetIO().WantCaptureMouse)
|
||||
{
|
||||
SetMouseCaptured(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.WasKeyPressed(SDL_SCANCODE_ESCAPE))
|
||||
{
|
||||
SetMouseCaptured(false);
|
||||
SetPossessed(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -143,7 +136,7 @@ void FirstPersonController::FixedUpdate(float fixedDt)
|
||||
m_CoyoteTimer = m_Grounded ? m_CoyoteTime : std::max(m_CoyoteTimer - fixedDt, 0.0f);
|
||||
|
||||
const auto& input = InputManager::GetInstance();
|
||||
const bool sprinting = IsMouseCaptured() && input.IsKeyDown(SDL_SCANCODE_LSHIFT);
|
||||
const bool sprinting = m_Possessed && input.IsKeyDown(SDL_SCANCODE_LSHIFT);
|
||||
const glm::vec3 wishVelocity = GetWishDirection() * (sprinting ? m_SprintSpeed : m_WalkSpeed);
|
||||
|
||||
const float acceleration = m_Grounded ? m_GroundAcceleration : m_AirAcceleration;
|
||||
@@ -211,7 +204,7 @@ bool FirstPersonController::CheckGrounded() const
|
||||
|
||||
glm::vec3 FirstPersonController::GetWishDirection() const
|
||||
{
|
||||
if (!IsMouseCaptured())
|
||||
if (!m_Possessed)
|
||||
return glm::vec3{0.0f};
|
||||
|
||||
const auto& input = InputManager::GetInstance();
|
||||
@@ -255,10 +248,8 @@ void FirstPersonController::ImGuiInspector()
|
||||
ImGui::Text("Grounded: %s", m_Grounded ? "yes" : "no");
|
||||
ImGui::Text("Yaw: %.1f deg", glm::degrees(m_Yaw));
|
||||
ImGui::Text("Pitch: %.1f deg", glm::degrees(m_Pitch));
|
||||
bool captured = IsMouseCaptured();
|
||||
ImGui::Checkbox("Mouse Captured", &captured);
|
||||
if (captured != IsMouseCaptured()) {
|
||||
SetMouseCaptured(captured);
|
||||
if (bool possessed = m_Possessed; ImGui::Checkbox("Possessed", &possessed)) {
|
||||
SetPossessed(possessed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user