diff --git a/Source/engine/displacement.hpp b/Source/engine/displacement.hpp index 4ebf8da00..7229084ae 100644 --- a/Source/engine/displacement.hpp +++ b/Source/engine/displacement.hpp @@ -127,6 +127,7 @@ struct DisplacementOf { */ constexpr DisplacementOf worldToScreen() const { + static_assert(std::is_signed::value, "DeltaT must be signed for transformations involving a rotation"); return { (deltaY - deltaX) * 32, (deltaY + deltaX) * -16 }; } @@ -139,6 +140,7 @@ struct DisplacementOf { */ constexpr DisplacementOf screenToWorld() const { + static_assert(std::is_signed::value, "DeltaT must be signed for transformations involving a rotation"); return { (2 * deltaY + deltaX) / -64, (2 * deltaY - deltaX) / -64 }; } @@ -153,6 +155,7 @@ struct DisplacementOf { constexpr DisplacementOf screenToLight() const { + static_assert(std::is_signed::value, "DeltaT must be signed for transformations involving a rotation"); return { (2 * deltaY + deltaX) / 8, (2 * deltaY - deltaX) / 8 }; } @@ -163,12 +166,13 @@ struct DisplacementOf { */ [[nodiscard]] Displacement worldToNormalScreen() const { + static_assert(std::is_signed::value, "DeltaT must be signed for transformations involving a rotation"); // Most transformations between world and screen space take shortcuts when scaling to simplify the math. This // routine is typically used with missiles where we want a normal vector that can be multiplied with a target // velocity (given in pixels). We could normalize the vector first but then we'd need to scale it during // rotation from world to screen space. To save performing unnecessary divisions we rotate first without // correcting the scaling. This gives a vector in elevation projection aligned with screen space. - Displacement rotated { static_cast(deltaY) - static_cast(deltaX), -(static_cast(deltaY) + static_cast(deltaX)) }; + DisplacementOf rotated { deltaY - deltaX, -(deltaY + deltaX) }; // then normalize this vector Displacement rotatedAndNormalized = rotated.normalized(); // and finally scale the y axis to bring it to isometric projection