implement ray casting events

This commit is contained in:
ohyzha
2024-11-04 18:22:40 +02:00
parent 4956884d5f
commit 7febb370a8
9 changed files with 176 additions and 5 deletions

View File

@@ -0,0 +1,40 @@
#include "CameraController.hpp"
#include "Scene/Camera.hpp"
#include "Input/InputDeviceMouse.hpp"
#include "Input/InputDeviceController.hpp"
#include "Input/InputManager.hpp"
#include "Input/Touch/InputDeviceTouch.hpp"
namespace OpenVulkano
{
CameraController::CameraController(Scene::Camera* camera)
{
m_inputManager = Input::InputManager::GetInstance();
m_camera = camera;
m_actionCastRay = m_inputManager->GetAction("cast ray");
m_actionCastRay->BindKey(Input::InputKey::Mouse::BUTTON_1);
// BIND FOR TOUCH
m_actionCastRay->BindKey(Input::InputKey::Touch::AXIS_TAP_X);
m_actionCastRay->BindKey(Input::InputKey::Touch::AXIS_TAP_X);
}
void CameraController::Tick()
{
Input::InputDeviceMouse* mouse = static_cast<Input::InputDeviceMouse*>(m_inputManager->GetDevice(Input::InputDeviceType::MOUSE));
Input::InputDeviceTouch* touch = static_cast<Input::InputDeviceTouch*>(m_inputManager->GetDevice(Input::InputDeviceType::TOUCH));
if (m_camera->CanCastRay() && m_inputManager->GetButton(m_actionCastRay))
{
if (mouse && mouse->GetButtonDown(Input::InputKey::Mouse::BUTTON_1))
{
Math::Vector2i pos = mouse->GetMousePosition();
mouse->onLeftButtonClick.NotifyAll(pos);
}
else if (touch)
{
Math::Vector2i pos = touch->GetTapPosition();
touch->OnTap.NotifyAll(pos);
}
}
}
}