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

61 lines
2.0 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)
2024-06-09 12:20:04 +02:00
: position(initialPos), fieldOfView(glm::radians(70.f)),
aspectRatio(static_cast<float>(viewportDimensions.size.x) / viewportDimensions.size.y), pitch(0), yaw(glm::pi<float>() / -2.0f) {
2022-11-17 16:47:42 +01:00
std::cout << yaw << " " << pitch << std::endl;
}
2024-06-09 12:20:04 +02:00
ViewportControl::~ViewportControl() {}
2022-11-17 16:47:42 +01:00
2025-03-26 13:38:48 +01:00
void ViewportControl::update(Component::Camera&, float deltaTime) {
2022-11-17 16:47:42 +01:00
float cameraMove = deltaTime * 20;
2024-06-09 12:20:04 +02:00
if (keys[KeyCode::KEY_LEFT_SHIFT]) {
2022-11-17 16:47:42 +01:00
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);
2024-06-09 12:20:04 +02:00
if (keys[KeyCode::KEY_W]) {
2022-11-17 16:47:42 +01:00
moveVector += forward * cameraMove;
}
2024-06-09 12:20:04 +02:00
if (keys[KeyCode::KEY_S]) {
2022-11-17 16:47:42 +01:00
moveVector += forward * -cameraMove;
}
2024-06-09 12:20:04 +02:00
if (keys[KeyCode::KEY_A]) {
2022-11-17 16:47:42 +01:00
moveVector += side * cameraMove;
}
2024-06-09 12:20:04 +02:00
if (keys[KeyCode::KEY_D]) {
2022-11-17 16:47:42 +01:00
moveVector += side * -cameraMove;
}
2024-06-09 12:20:04 +02:00
if (keys[KeyCode::KEY_E]) {
2022-11-17 16:47:42 +01:00
moveVector += glm::vec3(0, cameraMove, 0);
2024-06-09 12:20:04 +02:00
}
if (keys[KeyCode::KEY_Q]) {
2022-11-17 16:47:42 +01:00
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
}
2024-06-09 12:20:04 +02:00
void ViewportControl::keyCallback(KeyCode key, InputAction action) { keys[static_cast<size_t>(key)] = action != InputAction::RELEASE; }
2022-11-17 16:47:42 +01:00
2024-06-09 12:20:04 +02:00
void ViewportControl::mouseMoveCallback(double xPos, double yPos) {
2022-11-17 16:47:42 +01:00
mouseX = static_cast<float>(xPos);
mouseY = static_cast<float>(yPos);
}
2024-06-09 12:20:04 +02:00
void ViewportControl::mouseButtonCallback(MouseButton button, InputAction action) {
if (button == MouseButton::MOUSE_BUTTON_1) {
2022-11-17 16:47:42 +01:00
mouse1 = action != InputAction::RELEASE;
}
2024-06-09 12:20:04 +02:00
if (button == MouseButton::MOUSE_BUTTON_2) {
2022-11-17 16:47:42 +01:00
mouse2 = action != InputAction::RELEASE;
}
}
2024-06-09 12:20:04 +02:00
void ViewportControl::viewportResize(URect dimensions) { aspectRatio = static_cast<float>(dimensions.size.x) / dimensions.size.y; }