added project structure

This commit is contained in:
2026-04-27 14:00:03 +02:00
parent f5b5ac4d99
commit 687ecb7f74
14 changed files with 203 additions and 167 deletions

21
src/camera/Camera.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "camera/Camera.hpp"
Camera::Camera(float fov, float width, float height) {
projection = glm::perspective(fov/2.0f, width/height, 0.1f, 1000.f);
view = glm::mat4(1.0f);
position = glm::vec3(0.0f);
update();
}
glm::mat4 Camera::getViewProj() {
return viewProj;
}
void Camera::update() {
viewProj = projection * view;
}
void Camera::translate(glm::vec3 v) {
position += v;
view = glm::translate(view, v*-1.0f);
}

38
src/camera/FPS_Camera.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include "camera/FPS_Camera.hpp"
FPSCamera::FPSCamera(float fov, float width, float height) : Camera(fov, width, height) {
up = glm::vec3(0.0f, 1.0f, 0.0f);
yaw = -90.0f;
pitch = 0.0f;
onMouseMoved(0.0f, 0.0f);
}
void FPSCamera::onMouseMoved(float xRel, float yRel) {
yaw += xRel * mouseSensitivity;
pitch -= yRel * mouseSensitivity;
if (pitch > 89.0f) pitch = 89.0f;
else if (pitch < -89.0f) pitch = -89.0f;
glm::vec3 front;
front.x = cos(glm::radians(pitch)) * cos(glm::radians(yaw));
front.y = sin(glm::radians(pitch));
front.z = cos(glm::radians(pitch)) * sin(glm::radians(yaw));
lookAt = glm::normalize(front);
update();
}
void FPSCamera::update() {
view = glm::lookAt(position, position+lookAt, up);
viewProj = projection * view;
}
void FPSCamera::moveFront(float amount) {
translate(glm::normalize(glm::vec3(1.0f, 0.0f, 1.0f) * lookAt) * amount);
update();
}
void FPSCamera::moveSideways(float amount) {
translate(glm::normalize(glm::cross(lookAt, up)) * amount);
update();
}