added floating camera

This commit is contained in:
2026-04-27 15:11:18 +02:00
parent 687ecb7f74
commit cde7490211
4 changed files with 37 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
#include "camera/Floating_Camera.hpp"
FloatingCamera::FloatingCamera(float fov, float width, float height) : FPSCamera(fov, width, height) {
}
void FloatingCamera::moveUp(float amount) {
translate(up * amount);
}

View File

@@ -7,9 +7,8 @@
#include "defines.hpp"
#include "Shader.hpp"
#define STB_IMAGE_IMPLEMENTATION
#include "camera/Camera.hpp"
#include "stb_image.hpp"
#include "camera/FPS_Camera.hpp"
#include "camera/Floating_Camera.hpp"
#include "glm/glm.hpp"
#include "glm/ext/matrix_transform.hpp"
#include "glm/gtc/matrix_transform.hpp"
@@ -172,7 +171,7 @@ int main() {
auto model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(1.2f));
FPSCamera camera(90.0f, 800.0f, 600.0f);
FloatingCamera camera(90.0f, 800.0f, 600.0f);
camera.translate(glm::vec3(0.0f, 0.0f, 5.0f));
camera.update();
@@ -193,6 +192,8 @@ int main() {
bool btnS;
bool btnA;
bool btnD;
bool btnSpace;
bool btnShift;
while (running) {
while (SDL_PollEvent(&e)) {
@@ -204,6 +205,8 @@ int main() {
case SDLK_S: btnS = true; break;
case SDLK_A: btnA = true; break;
case SDLK_D: btnD = true; break;
case SDLK_SPACE: btnSpace = true; break;
case SDLK_LSHIFT: btnShift = true; break;
default: break;
}
} else if (e.type == SDL_EVENT_KEY_UP) {
@@ -212,6 +215,8 @@ int main() {
case SDLK_S: btnS = false; break;
case SDLK_A: btnA = false; break;
case SDLK_D: btnD = false; break;
case SDLK_SPACE: btnSpace = false; break;
case SDLK_LSHIFT: btnShift = false; break;
default: break;
}
} else if (e.type == SDL_EVENT_MOUSE_MOTION) {
@@ -235,6 +240,12 @@ int main() {
if (btnD) {
camera.moveSideways(delta * cameraSpeed);
}
if (btnSpace) {
camera.moveUp(delta * cameraSpeed);
}
if (btnShift) {
camera.moveUp(- delta * cameraSpeed);
}
camera.update();