Files
OpenVulkano/openVulkanoCpp/Controller/ArcballCameraController.hpp

60 lines
1.7 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "CameraController.hpp"
#include "Math/Math.hpp"
namespace OpenVulkano
{
namespace Input
{
class InputAction;
}
class ArcballCameraController final : public CameraController
{
Math::Vector4f_SIMD m_pivotPoint{ 0, 0, 0, 1 };
float yaw = 0, pitch = 0;
bool lockYaw = false, lockPitch = false;
Input::InputAction* m_actionForward = nullptr;
Input::InputAction* m_actionSide = nullptr;
Input::InputAction* m_actionUp = nullptr;
Input::InputAction* m_actionLookUp = nullptr;
Input::InputAction* m_actionLookSide = nullptr;
void SetupInputActions();
public:
ArcballCameraController() { SetupInputActions(); }
ArcballCameraController(Scene::Camera* camera) : CameraController(camera) { SetupInputActions(); SetActive(); }
void Tick() override;
[[nodiscard]] const Math::Vector4f_SIMD& GetPivotPoint() const { return m_pivotPoint; }
void SetPivotPoint(const Math::Vector4f_SIMD& pivotPoint) { m_pivotPoint = pivotPoint; }
void SetActive() override;
void SetDefaultKeybindings();
void Init(Scene::Camera *camera) override { CameraController::SetCamera(camera); SetActive(); }
void LockYaw(float value = INFINITY, bool locked = true) { lockYaw = locked; if (value != INFINITY) yaw = value; }
void LockPitch(float value = INFINITY, bool locked = true) { lockPitch = locked; if (value != INFINITY) pitch = value; }
[[nodiscard]] float GetYaw() const { return yaw; }
[[nodiscard]] float GetPitch() const { return pitch; }
void SetYaw(float y) { yaw = y; }
void SetPitch(float p) { pitch = p; }
};
}