From: Luke Lau Date: Mon, 15 Oct 2018 22:21:27 +0000 (+0100) Subject: Allow upside-down(ish) camera angles X-Git-Tag: cs7gv3-a3~30 X-Git-Url: https://git.lukelau.me/?p=opengl.git;a=commitdiff_plain;h=da829a43b9ab76ce8830bd83760e59f016787727 Allow upside-down(ish) camera angles --- diff --git a/main.cpp b/main.cpp index 0b53eee..4c9171a 100644 --- a/main.cpp +++ b/main.cpp @@ -149,6 +149,7 @@ void drawTeapot(TeapotProjection proj, bool rotate, float d, glm::vec3 lightPos, } 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; @@ -531,6 +532,12 @@ void motion(int x, int y) { 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) {