From 4aaf6c4cf6e17f011106487ba3108d857266e10c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Jan 2020 21:52:17 +0100 Subject: [PATCH] - check for angular overflow in pitch calculations. --- source/duke3d/src/player.cpp | 1 + source/exhumed/src/player.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 0956600f6..12887f4c3 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -5507,6 +5507,7 @@ RECHECK: } } + horizAngle = clamp(horizAngle, -255.f, 255.f); // keep the angle within ]-90°..90°[ pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))); if (pPlayer->return_to_center > 0 && !TEST_SYNC_KEY(playerBits, SK_LOOK_UP) && !TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN)) diff --git a/source/exhumed/src/player.cpp b/source/exhumed/src/player.cpp index bf6cd8552..3b6a4e0a5 100644 --- a/source/exhumed/src/player.cpp +++ b/source/exhumed/src/player.cpp @@ -282,6 +282,7 @@ void PlayerInterruptKeys() // so we convert horiz to 1024 angle units float horizAngle = atan2f(nVertPan[nLocalPlayer] - F16(92), F16(128)) * (512.f / fPI) + fix16_to_float(q16horz); + horizAngle = clamp(horizAngle, -255.f, 255.f); nVertPan[nLocalPlayer] = fix16_clamp(F16(92) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))), F16(0), F16(184)); }