41 lines
1.4 KiB
C++
41 lines
1.4 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/.
|
|
*/
|
|
|
|
#include "MapCameraController.hpp"
|
|
#include "Input/InputManager.hpp"
|
|
#include "Scene/Camera.hpp"
|
|
|
|
namespace OpenVulkano
|
|
{
|
|
MapCameraController::MapCameraController(Scene::Camera* camera) : CameraController(camera)
|
|
{
|
|
auto input = Input::InputManager::GetInstance();
|
|
m_actionUp = input->GetAction("map_up");
|
|
m_actionSide = input->GetAction("map_side");
|
|
}
|
|
|
|
void MapCameraController::Tick()
|
|
{
|
|
if (!GetCamera()) return;
|
|
auto input = Input::InputManager::GetInstance();
|
|
Math::Vector3f_SIMD vec = m_dirUp * input->GetAxis(m_actionUp) + m_dirSide * input->GetAxis(m_actionSide);
|
|
vec /= GetCamera()->GetZoom();
|
|
vec /= GetCamera()->GetContentScaleFactor();
|
|
|
|
GetCamera()->SetMatrix(Math::Utils::translate(vec) * GetCamera()->GetMatrix());
|
|
}
|
|
|
|
void MapCameraController::SetDefaultKeybindings()
|
|
{
|
|
m_actionUp->BindKey(Input::InputKey::Controller::AXIS_LEFT_Y);
|
|
m_actionUp->BindKey(Input::InputKey::Touch::AXIS_PAN_Y);
|
|
m_actionUp->BindKey(Input::InputKey::Mouse::AXIS_Y);
|
|
m_actionSide->BindKey(Input::InputKey::Controller::AXIS_LEFT_X);
|
|
m_actionSide->BindKey(Input::InputKey::Touch::AXIS_PAN_X);
|
|
m_actionSide->BindKey(Input::InputKey::Mouse::AXIS_X);
|
|
}
|
|
}
|