added debug Camear (keys L and K to switch)

This commit is contained in:
Jasper 2015-02-13 15:46:00 +01:00
parent 47fded52ce
commit dc628f3fc8
6 changed files with 27 additions and 6 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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));

View File

@ -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));

View File

@ -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<glm::mat4>* shadowVPs=0);
glm::vec3 getAmbientLight();

View File

@ -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();
}