Implement sprinting.

This commit is contained in:
2018-03-29 12:50:15 +02:00
parent 1c872c9969
commit 4f3099bc60

View File

@@ -31,8 +31,8 @@ static float getFPS()
void RenderingState::move(unsigned char key) void RenderingState::move(unsigned char key)
{ {
float speed = 0.5; float speed = 0.5f;
float dir[3]; std::array<float, 3> dir;
const auto yaw = deg2rad(state.angle[0]); const auto yaw = deg2rad(state.angle[0]);
const auto pitch = deg2rad(state.angle[1]); const auto pitch = deg2rad(state.angle[1]);
@@ -51,7 +51,11 @@ void RenderingState::move(unsigned char key)
speed *= -1; speed *= -1;
} }
for (auto i = 0; i < 3; ++i) { if (glutGetModifiers() & GLUT_ACTIVE_SHIFT) {
speed *= 2;
}
for (auto i = 0; i < dir.size(); ++i) {
pos[i] += speed * dir[i]; pos[i] += speed * dir[i];
} }
} }
@@ -66,6 +70,13 @@ void RenderingState::handleKey(unsigned char x)
move(x); move(x);
break; break;
case 'W':
case 'A':
case 'S':
case 'D':
move(static_cast<unsigned char>(std::tolower(x)));
break;
case 'q': case 'q':
exit(0); exit(0);