Merge pull request 'feat: add camera movement boundaries' (#1) from camera-movement into master

Reviewed-on: #1
This commit is contained in:
Mateusz Romański 2021-12-28 19:03:32 +01:00
commit b7bb40e0fa

View File

@ -83,19 +83,45 @@ float skyboxVertices[] = {
};
bool isInBoundaries(glm::vec3 nextPosition) {
float boundary = 19.5f;
return nextPosition.z > -boundary && nextPosition.z < boundary && nextPosition.y > -boundary && nextPosition.y < boundary && nextPosition.x < boundary && nextPosition.x > -boundary;
}
void keyboard(unsigned char key, int x, int y)
{
float angleSpeed = 10.f;
float moveSpeed = 0.1f;
glm::vec3 nextPosition;
switch (key)
{
case 'z': cursorDiff.z -= angleSpeed; break;
case 'x': cursorDiff.z += angleSpeed; break;
case 'w': cameraPos += cameraDir * moveSpeed; break;
case 's': cameraPos -= cameraDir * moveSpeed; break;
case 'd': cameraPos += cameraSide * moveSpeed; break;
case 'a': cameraPos -= cameraSide * moveSpeed; break;
case 'w':
nextPosition = cameraPos + (cameraDir * moveSpeed);
if (isInBoundaries(nextPosition)) {
cameraPos = nextPosition;
}
break;
case 's':
nextPosition = cameraPos - (cameraDir * moveSpeed);
if (isInBoundaries(nextPosition)) {
cameraPos = nextPosition;
}
break;
case 'd':
nextPosition = cameraPos + (cameraSide * moveSpeed);
if (isInBoundaries(nextPosition)) {
cameraPos = nextPosition;
}
break;
case 'a':
nextPosition = cameraPos - (cameraSide * moveSpeed);
if (isInBoundaries(nextPosition)) {
cameraPos = nextPosition;
}
break;
}
}