From d5df497f923c0d27ee023b71e0647859e8c2b6d4 Mon Sep 17 00:00:00 2001 From: Mateusz Walas Date: Fri, 31 Dec 2021 13:45:16 +0100 Subject: [PATCH] Add cursos centering --- grafika_projekt/src/main.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/grafika_projekt/src/main.cpp b/grafika_projekt/src/main.cpp index c743dc6..dde6842 100644 --- a/grafika_projekt/src/main.cpp +++ b/grafika_projekt/src/main.cpp @@ -167,6 +167,17 @@ void mouse(int x, int y) } old_x = x; old_y = y; + + if (x < 100 || x > 800 - 100) { //you can use values other than 100 for the screen edges if you like, kind of seems to depend on your mouse sensitivity for what ends up working best + old_x = 800 / 2; //centers the last known position, this way there isn't an odd jump with your cam as it resets + old_y = 800 / 2; + glutWarpPointer(800 / 2, 800 / 2); //centers the cursor + } + else if (y < 100 || y > 800 - 100) { + old_x = 800 / 2; + old_y = 800 / 2; + glutWarpPointer(800 / 2, 800 / 2); + } } glm::mat4 createCameraMatrix() @@ -236,7 +247,7 @@ glm::mat4 animationMatrix(float time, glm::vec3 change) { auto animationRotation = glm::squad(keyRotation[index % rotationSize], keyRotation[(index + 1) % rotationSize], a1, a2, t); - glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(0.25f)) * glm::mat4_cast(animationRotation); + glm::mat4 result = glm::translate(pos) * glm::scale(glm::vec3(0.5f)) * glm::mat4_cast(animationRotation); return result; } @@ -302,13 +313,13 @@ void renderScene() glm::vec3 change2 = glm::vec3(0, 0, 0); glm::vec3 change3 = glm::vec3(3, 0, 0); glm::vec3 change4 = glm::vec3(0, 2, 1); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 4; i++) { if (time > -10) { drawObjectTexture(fishContext, animationMatrix(time + 15, change1), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change2), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change3), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change4), textureFish); - time -= 6; + time -= 8; } } drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine); @@ -443,6 +454,9 @@ int main(int argc, char** argv) glutDisplayFunc(renderScene); glutIdleFunc(idle); + glutSetCursor(GLUT_CURSOR_NONE); + + glutMainLoop(); shutdown();