From 3ad1eca1b7c0992ff5f64fce5d26a722ea6fe5dc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 25 Jan 2021 00:52:31 +0000 Subject: Basic key controls to move the camera around --- application/main.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'application') diff --git a/application/main.cpp b/application/main.cpp index 015f128..2f9ae36 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -67,7 +67,8 @@ public: world.create(); Shader shader; - Camera camera({0.0F, 0.0F, -5.0F}, 70.0F, (float)DISPLAY_WIDTH / (float)DISPLAY_HEIGHT, 0.1F, 100.0F); + Camera camera({-5.0F, 2.0F, -5.0F}, 70.0F, (float)DISPLAY_WIDTH / (float)DISPLAY_HEIGHT, 0.1F, 100.0F); + camera.RotateY(0.7854); shader.Bind(); shader.setView(camera.GetViewProjection()); @@ -79,8 +80,33 @@ public: while (isRunning) { while (SDL_PollEvent(&e)) { - if (e.type == SDL_QUIT) { - isRunning = false; + switch (e.type) { + case SDL_QUIT: + isRunning = false; + break; + case SDL_KEYDOWN: + switch (e.key.keysym.sym) { + case SDLK_KP_8: + camera.MoveForward(1); + break; + case SDLK_KP_2: + camera.MoveForward(-1); + break; + case SDLK_KP_4: + camera.MoveRight(1); + break; + case SDLK_KP_6: + camera.MoveRight(-1); + break; + case SDLK_KP_7: + camera.RotateY(0.04); + break; + case SDLK_KP_9: + camera.RotateY(-0.04); + break; + } + shader.setView(camera.GetViewProjection()); + break; } } -- cgit v1.2.3