Browse Source

Round to the nearest integer when computing missile coordinates

pull/5581/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
ce413ec4a6
  1. 9
      Source/engine/displacement.hpp

9
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<DeltaT> screenToMissile() const
{
return -screenToWorld();
static_assert(std::is_signed<DeltaT>::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<DeltaT> screenToLight() const

Loading…
Cancel
Save