Add cursos centering

This commit is contained in:
Mateusz Walas 2021-12-31 13:45:16 +01:00
parent 960a6ef21d
commit d5df497f92

View File

@ -167,6 +167,17 @@ void mouse(int x, int y)
} }
old_x = x; old_x = x;
old_y = y; 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() 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); 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; return result;
} }
@ -302,13 +313,13 @@ void renderScene()
glm::vec3 change2 = glm::vec3(0, 0, 0); glm::vec3 change2 = glm::vec3(0, 0, 0);
glm::vec3 change3 = glm::vec3(3, 0, 0); glm::vec3 change3 = glm::vec3(3, 0, 0);
glm::vec3 change4 = glm::vec3(0, 2, 1); 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) { if (time > -10) {
drawObjectTexture(fishContext, animationMatrix(time + 15, change1), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change1), textureFish);
drawObjectTexture(fishContext, animationMatrix(time + 15, change2), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change2), textureFish);
drawObjectTexture(fishContext, animationMatrix(time + 15, change3), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change3), textureFish);
drawObjectTexture(fishContext, animationMatrix(time + 15, change4), textureFish); drawObjectTexture(fishContext, animationMatrix(time + 15, change4), textureFish);
time -= 6; time -= 8;
} }
} }
drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine); drawObjectTexture(submarineContext, submarineModelMatrix, textureSubmarine);
@ -443,6 +454,9 @@ int main(int argc, char** argv)
glutDisplayFunc(renderScene); glutDisplayFunc(renderScene);
glutIdleFunc(idle); glutIdleFunc(idle);
glutSetCursor(GLUT_CURSOR_NONE);
glutMainLoop(); glutMainLoop();
shutdown(); shutdown();