From ce413ec4a6ddf1528ccd655bb900c0952123e1e7 Mon Sep 17 00:00:00 2001 From: staphen Date: Tue, 6 Dec 2022 22:53:38 -0500 Subject: [PATCH] Round to the nearest integer when computing missile coordinates --- Source/engine/displacement.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/engine/displacement.hpp b/Source/engine/displacement.hpp index c30bf4c9c..4d1bef384 100644 --- a/Source/engine/displacement.hpp +++ b/Source/engine/displacement.hpp @@ -155,11 +155,16 @@ struct DisplacementOf { /** * @brief Missiles flip the axes for some reason -_- - * @return negated world displacement, for use with missile movement routines. + * @return negated and rounded world displacement, for use with missile movement routines. */ constexpr DisplacementOf screenToMissile() const { - return -screenToWorld(); + static_assert(std::is_signed::value, "DeltaT must be signed for transformations involving a rotation"); + DeltaT xNumerator = 2 * deltaY + deltaX; + DeltaT yNumerator = 2 * deltaY - deltaX; + DeltaT xOffset = (xNumerator >= 0) ? 32 : -32; + DeltaT yOffset = (yNumerator >= 0) ? 32 : -32; + return { (xNumerator + xOffset) / 64, (yNumerator + yOffset) / 64 }; } constexpr DisplacementOf screenToLight() const