added more camera movement

This commit is contained in:
2026-04-27 12:00:27 +02:00
parent d7efcff2c8
commit f5b5ac4d99
4 changed files with 69 additions and 11 deletions

51
include/FPS_Camera.hpp Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include "Camera.hpp"
class FPSCamera : public Camera {
protected:
float yaw; // rotation y-axis
float pitch; // rotating x-axis
glm::vec3 lookAt;
const float mouseSensitivity = 0.3f;
glm::vec3 up;
public:
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 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 update() override {
view = glm::lookAt(position, position+lookAt, up);
viewProj = projection * view;
}
void moveFront(float amount) {
translate(lookAt * amount);
update();
}
void moveSideways(float amount) {
translate(glm::normalize(glm::cross(lookAt, up)) * amount);
update();
}
};