From dc628f3fc8bb37e999cd4df63f90cfb0f7965952 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 13 Feb 2015 15:46:00 +0100 Subject: [PATCH] added debug Camear (keys L and K to switch) --- camera.cc | 10 ++++++++++ camera.hh | 4 +++- graphics.cc | 3 ++- level.cc | 7 ++++++- level.hh | 2 +- main.cc | 7 +++++-- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/camera.cc b/camera.cc index c9430e5..fc2e1a6 100644 --- a/camera.cc +++ b/camera.cc @@ -3,6 +3,7 @@ Camera::Camera(glm::vec2 rotation, float distance) { this->rotation = rotation; this->distance = distance; + this->setIsPhysicsCamera(true); } Camera::Camera() { @@ -31,6 +32,15 @@ void Camera::setRotation(glm::vec2 rotation) { updatePosition(); } + +bool Camera::getIsPhysicsCamera() +{ + return usePhysicsCamera; +} +void Camera::setIsPhysicsCamera(bool val) +{ + usePhysicsCamera = val; +} void Camera::updateRotation(glm::vec2 rotation) { this->rotation += rotation; if((this->rotation.x + rotation.x) >= 1.57f) { diff --git a/camera.hh b/camera.hh index 71b6b86..e0bea51 100644 --- a/camera.hh +++ b/camera.hh @@ -19,7 +19,8 @@ class Camera { glm::vec3 getPosition(); void setDirection(glm::vec3 dir); glm::vec3 getDirection(); - + bool getIsPhysicsCamera(); + void setIsPhysicsCamera(bool val); private: void updatePosition(); float distance; @@ -27,6 +28,7 @@ class Camera { glm::vec3 vector; glm::vec3 position; glm::vec3 direction; + bool usePhysicsCamera; }; #endif diff --git a/graphics.cc b/graphics.cc index d51ecb6..29f7434 100644 --- a/graphics.cc +++ b/graphics.cc @@ -213,7 +213,8 @@ void Graphics::resize(glm::uvec2 windowSize) { glm::mat4 Graphics::buildViewMatrix(Level* level) { //construct lookAt (cameraPosition = cameraCenter + cameraVector) - return glm::lookAt(level->getCamera()->getPosition(), level->getCamera()->getPosition() + level->getCamera()->getDirection(), glm::vec3(0.0f, 1.0f, 0.0f)); + if(level->getCamera()->getIsPhysicsCamera()) + return glm::lookAt(level->getCamera()->getPosition(), level->getCamera()->getPosition() + level->getCamera()->getDirection(), glm::vec3(0.0f, 1.0f, 0.0f)); return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f)); diff --git a/level.cc b/level.cc index bafb957..79148da 100644 --- a/level.cc +++ b/level.cc @@ -54,7 +54,7 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, } } -void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed) { +void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPressed, bool sPressed, bool dPressed,bool kPressed, bool lPressed) { // Ignore first two mouse updates, because they are incorrect // DON'T try to move this functionallity elsewhere static int i = 0; @@ -82,6 +82,11 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre physics.rollRight(camera.getVector(),strength); } + if(kPressed) + camera.setIsPhysicsCamera(true); + if(lPressed) + camera.setIsPhysicsCamera(false); + physics.takeUpdateStep(runTime); cameraCenter->setPosition(physics.getPos(0)); diff --git a/level.hh b/level.hh index 69b3412..5b43467 100644 --- a/level.hh +++ b/level.hh @@ -24,7 +24,7 @@ class Level { Level(); ~Level(); void load(); - void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed); + void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed, bool kPressed, bool lPressed); void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, glm::mat4* viewProjectionMatrix, std::vector* shadowVPs=0); glm::vec3 getAmbientLight(); diff --git a/main.cc b/main.cc index 2cfb0a5..08ddf72 100644 --- a/main.cc +++ b/main.cc @@ -161,16 +161,19 @@ int main( int argc, char *argv[] ) int stateA = glfwGetKey(window, GLFW_KEY_A); int stateS = glfwGetKey(window, GLFW_KEY_S); int stateD = glfwGetKey(window, GLFW_KEY_D); + int stateK = glfwGetKey(window, GLFW_KEY_K); + int stateL = glfwGetKey(window, GLFW_KEY_L); + double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos); glfwSetCursorPos(window, app.getGraphics()->getWindowSize().x/2, app.getGraphics()->getWindowSize().y/2); app.getLevel()->update(now - lastUpdate, glm::vec2((float)ypos-app.getGraphics()->getWindowSize().y/2, (float)xpos-app.getGraphics()->getWindowSize().x/2), - stateW == GLFW_PRESS,stateA == GLFW_PRESS,stateS == GLFW_PRESS,stateD == GLFW_PRESS); + stateW == GLFW_PRESS,stateA == GLFW_PRESS,stateS == GLFW_PRESS,stateD == GLFW_PRESS,stateK == GLFW_PRESS,stateL == GLFW_PRESS); } else { - app.getLevel()->update(now - lastUpdate, glm::vec2(0.0f, 0.0f), false, false, false, false); + app.getLevel()->update(now - lastUpdate, glm::vec2(0.0f, 0.0f), false, false, false, false,false,false); if (app.isLocked()) { app.ignoredOneMouseUpdate(); }