2020-04-26 15:37:49 -06:00
|
|
|
// Copyright 2020 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-04-26 15:37:49 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include "Common/Matrix.h"
|
2020-06-18 22:44:17 -06:00
|
|
|
#include "Core/FreeLookConfig.h"
|
2020-04-26 15:37:49 -06:00
|
|
|
|
|
|
|
class PointerWrap;
|
|
|
|
|
|
|
|
class CameraController
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CameraController() = default;
|
|
|
|
virtual ~CameraController() = default;
|
|
|
|
|
|
|
|
CameraController(const CameraController&) = delete;
|
|
|
|
CameraController& operator=(const CameraController&) = delete;
|
|
|
|
|
|
|
|
CameraController(CameraController&&) = delete;
|
|
|
|
CameraController& operator=(CameraController&&) = delete;
|
|
|
|
|
2021-04-24 21:59:35 -06:00
|
|
|
virtual Common::Matrix44 GetView() const = 0;
|
2021-05-08 13:36:44 -06:00
|
|
|
virtual Common::Vec2 GetFieldOfViewMultiplier() const = 0;
|
2021-04-24 21:59:35 -06:00
|
|
|
|
|
|
|
virtual void DoState(PointerWrap& p) = 0;
|
|
|
|
|
|
|
|
virtual bool IsDirty() const = 0;
|
|
|
|
virtual void SetClean() = 0;
|
|
|
|
|
|
|
|
virtual bool SupportsInput() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CameraControllerInput : public CameraController
|
|
|
|
{
|
|
|
|
public:
|
2021-05-08 13:36:44 -06:00
|
|
|
Common::Vec2 GetFieldOfViewMultiplier() const final override;
|
2021-04-24 21:59:35 -06:00
|
|
|
|
|
|
|
void DoState(PointerWrap& p) override;
|
|
|
|
|
|
|
|
bool IsDirty() const final override { return m_dirty; }
|
|
|
|
void SetClean() final override { m_dirty = false; }
|
|
|
|
|
|
|
|
bool SupportsInput() const final override { return true; }
|
2020-04-26 15:37:49 -06:00
|
|
|
|
|
|
|
virtual void MoveVertical(float amt) = 0;
|
|
|
|
virtual void MoveHorizontal(float amt) = 0;
|
|
|
|
|
2020-06-11 23:21:50 -06:00
|
|
|
virtual void MoveForward(float amt) = 0;
|
2020-04-26 15:37:49 -06:00
|
|
|
|
|
|
|
virtual void Rotate(const Common::Vec3& amt) = 0;
|
2020-10-22 22:09:14 -06:00
|
|
|
virtual void Rotate(const Common::Quaternion& quat) = 0;
|
2020-04-26 15:37:49 -06:00
|
|
|
|
|
|
|
virtual void Reset() = 0;
|
|
|
|
|
2021-04-24 21:59:35 -06:00
|
|
|
void IncreaseFovX(float fov);
|
|
|
|
void IncreaseFovY(float fov);
|
|
|
|
float GetFovStepSize() const;
|
|
|
|
|
|
|
|
void ModifySpeed(float multiplier);
|
|
|
|
void ResetSpeed();
|
|
|
|
float GetSpeed() const;
|
|
|
|
|
|
|
|
private:
|
2021-05-08 13:17:31 -06:00
|
|
|
static constexpr float MIN_FOV_MULTIPLIER = 0.025f;
|
|
|
|
static constexpr float DEFAULT_SPEED = 60.0f;
|
|
|
|
static constexpr float DEFAULT_FOV_MULTIPLIER = 1.0f;
|
2021-04-24 21:59:35 -06:00
|
|
|
|
2021-05-08 13:17:31 -06:00
|
|
|
float m_fov_x_multiplier = DEFAULT_FOV_MULTIPLIER;
|
|
|
|
float m_fov_y_multiplier = DEFAULT_FOV_MULTIPLIER;
|
|
|
|
float m_speed = DEFAULT_SPEED;
|
2021-04-24 21:59:35 -06:00
|
|
|
bool m_dirty = false;
|
2020-04-26 15:37:49 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class FreeLookCamera
|
|
|
|
{
|
|
|
|
public:
|
2020-12-25 21:19:09 -07:00
|
|
|
FreeLookCamera();
|
2020-06-18 22:44:17 -06:00
|
|
|
void SetControlType(FreeLook::ControlType type);
|
2021-04-24 21:59:35 -06:00
|
|
|
Common::Matrix44 GetView() const;
|
2021-05-08 13:36:44 -06:00
|
|
|
Common::Vec2 GetFieldOfViewMultiplier() const;
|
2020-04-26 15:37:49 -06:00
|
|
|
|
|
|
|
void DoState(PointerWrap& p);
|
|
|
|
|
2020-06-18 22:49:07 -06:00
|
|
|
bool IsActive() const;
|
|
|
|
|
2021-04-24 21:59:35 -06:00
|
|
|
CameraController* GetController() const;
|
|
|
|
|
2020-04-26 15:37:49 -06:00
|
|
|
private:
|
2020-06-18 22:44:17 -06:00
|
|
|
std::optional<FreeLook::ControlType> m_current_type;
|
2020-04-26 15:37:49 -06:00
|
|
|
std::unique_ptr<CameraController> m_camera_controller;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FreeLookCamera g_freelook_camera;
|