Stop x rotation at the top and at the bottom to prevent flipping.

This commit is contained in:
Faerbit 2014-11-14 22:55:29 +01:00
parent 29ee7268ad
commit 3625cd31d7
2 changed files with 20 additions and 4 deletions

View File

@ -30,5 +30,15 @@ void Camera::setRotation(glm::vec2 rotation) {
}
void Camera::updateRotation(glm::vec2 rotation) {
this->rotation += rotation;;
if((this->rotation.x + rotation.x) >= 1.57f) {
this->rotation.x = 1.57;
this->rotation.y += rotation.y;
}
else if ((this->rotation.x + rotation.x) <= -1.57f) {
this->rotation.x = -1.57f;
this->rotation.y += rotation.y;
}
else {
this-> rotation += rotation;
}
}

View File

@ -13,7 +13,7 @@ Level::~Level() {
void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
// currently hard coded should later read this stuff out of a file
this->camera = Camera(glm::vec2(0.8f, 0.0f), 3.0f);
this->camera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
// load the geometry of the stanford bunny and build a VAO:
Model model = Model("Bunny.obj", 0.25f);
// load a texture:
@ -51,13 +51,19 @@ void Level::render() {
for(unsigned int i = 0; i<objects.size(); i++) {
objects[i].render();
}
// this->terrain.render();
}
void Level::update(float runTime, glm::vec2 mouseDelta) {
// rotate bunny
//cameraCenter->setRotation(glm::vec3(0.0f, 1.0472f * runTime, 0.0f));
camera.updateRotation(mouseDelta/100.0f);
// Ignore first two mouse updates, because they are incorrect
static int i = 0;
if (i <2) {
i++;
}
else {
camera.updateRotation(mouseDelta/100.0f);
}
}
glm::vec3 Level::getAmbientLight() {