Allow upside-down(ish) camera angles
authorLuke Lau <luke_lau@icloud.com>
Mon, 15 Oct 2018 22:21:27 +0000 (23:21 +0100)
committerLuke Lau <luke_lau@icloud.com>
Mon, 15 Oct 2018 22:21:27 +0000 (23:21 +0100)
main.cpp

index 0b53eee3aace592eb49e2a730b21f9c77c8c4faa..4c9171ab71a63c726e19996252e402b4e24949e1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -149,6 +149,7 @@ void drawTeapot(TeapotProjection proj, bool rotate, float d, glm::vec3 lightPos,
 }
 
 void display() {
 }
 
 void display() {
+       glClearColor(0.5, 0.5, 0.5, 1);
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f;
 
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f;
 
@@ -531,6 +532,12 @@ void motion(int x, int y) {
        front.y = sin(pitch);
        front.z = cos(pitch) * sin(yaw);
        camFront = glm::normalize(front);
        front.y = sin(pitch);
        front.z = cos(pitch) * sin(yaw);
        camFront = glm::normalize(front);
+
+       if (pitch < -1.57079632679 || pitch >= 1.57079632679) {
+               camUp = glm::vec3(0, -1, 0);
+       } else {
+               camUp = glm::vec3(0, 1, 0);
+       }
 }
 
 void mouse(int button, int state, int x, int y) {
 }
 
 void mouse(int button, int state, int x, int y) {