feat: add camera movement boundaries #1
@ -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)
|
void keyboard(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
float angleSpeed = 10.f;
|
float angleSpeed = 10.f;
|
||||||
float moveSpeed = 0.1f;
|
float moveSpeed = 0.1f;
|
||||||
|
glm::vec3 nextPosition;
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case 'z': cursorDiff.z -= angleSpeed; break;
|
case 'z': cursorDiff.z -= angleSpeed; break;
|
||||||
case 'x': cursorDiff.z += angleSpeed; break;
|
case 'x': cursorDiff.z += angleSpeed; break;
|
||||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
case 'w':
|
||||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
nextPosition = cameraPos + (cameraDir * moveSpeed);
|
||||||
case 'd': cameraPos += cameraSide * moveSpeed; break;
|
if (isInBoundaries(nextPosition)) {
|
||||||
case 'a': cameraPos -= cameraSide * moveSpeed; break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user