Files
Seele/src/Editor/Window/ViewportControl.cpp
T

86 lines
2.1 KiB
C++
Raw Normal View History

2022-11-17 16:47:42 +01:00
#include "ViewportControl.h"
#include "Component/Camera.h"
2024-01-16 19:24:49 +01:00
#include <iostream>
2022-11-17 16:47:42 +01:00
using namespace Seele;
2023-02-24 22:09:07 +01:00
using namespace Seele::Editor;
2022-11-17 16:47:42 +01:00
2023-01-21 18:43:21 +01:00
ViewportControl::ViewportControl(const URect& viewportDimensions, Vector initialPos)
2022-11-17 16:47:42 +01:00
: position(initialPos)
, fieldOfView(glm::radians(70.f))
, aspectRatio(static_cast<float>(viewportDimensions.size.x) / viewportDimensions.size.y)
, pitch(0)
2023-11-06 14:47:21 +01:00
, yaw(glm::pi<float>()/-2.0f)
2022-11-17 16:47:42 +01:00
{
std::cout << yaw << " " << pitch << std::endl;
}
ViewportControl::~ViewportControl()
{
}
void ViewportControl::update(Component::Camera& camera, float deltaTime)
{
float cameraMove = deltaTime * 20;
if(keys[KeyCode::KEY_LEFT_SHIFT])
{
cameraMove *= 4;
}
2023-01-21 18:43:21 +01:00
Vector moveVector = Vector();
Vector forward = glm::normalize(springArm);
Vector side = glm::cross(Vector(0, 1, 0), forward);
2022-11-17 16:47:42 +01:00
if(keys[KeyCode::KEY_W])
{
moveVector += forward * cameraMove;
}
if(keys[KeyCode::KEY_S])
{
moveVector += forward * -cameraMove;
}
if(keys[KeyCode::KEY_A])
{
moveVector += side * cameraMove;
}
if(keys[KeyCode::KEY_D])
{
moveVector += side * -cameraMove;
}
if(keys[KeyCode::KEY_E])
{
moveVector += glm::vec3(0, cameraMove, 0);
}
if(keys[KeyCode::KEY_Q])
{
moveVector += glm::vec3(0, -cameraMove, 0);
}
2024-01-05 21:16:36 +01:00
throw std::logic_error("Not implemented");
2022-11-17 16:47:42 +01:00
}
void ViewportControl::keyCallback(KeyCode key, InputAction action)
{
keys[static_cast<size_t>(key)] = action != InputAction::RELEASE;
}
void ViewportControl::mouseMoveCallback(double xPos, double yPos)
{
mouseX = static_cast<float>(xPos);
mouseY = static_cast<float>(yPos);
}
void ViewportControl::mouseButtonCallback(MouseButton button, InputAction action)
{
if(button == MouseButton::MOUSE_BUTTON_1)
{
mouse1 = action != InputAction::RELEASE;
}
if(button == MouseButton::MOUSE_BUTTON_2)
{
mouse2 = action != InputAction::RELEASE;
}
}
2023-01-21 18:43:21 +01:00
void ViewportControl::viewportResize(URect dimensions)
2022-11-17 16:47:42 +01:00
{
aspectRatio = static_cast<float>(dimensions.size.x) / dimensions.size.y;
}