I have unit Vector of acceleration in local space of object. Now I want to calculate Cardinal Direction from (North, East, South, West).
So Far I tried to:
FQuat QRot = LocalAcceleration.ToOrientationQuat();
FRotator Rot = FRotator(QRot);
float Angle = Rot.Yaw;
float Angle2 = (FMath::RoundToInt(Angle) + 360) % 360;
(Another version was calulcating atan2).
Then:
if (FMath::IsWithin(IntAngle, 0, 46)
&& FMath::IsWithin(IntAngle, 314, 0))
{
NewDir = EFourCardinalDirection::N;
}
if (FMath::IsWithin(IntAngle, 134, 228))
{
NewDir = EFourCardinalDirection::S;
}
if (FMath::IsWithin(IntAngle, 46, 136))
{
NewDir = EFourCardinalDirection::E;
}
if (FMath::IsWithin(IntAngle, 229, 313))
{
NewDir = EFourCardinalDirection::W;
}
I also tried to calculate eighth directions and then just assign the four based on the previous eight.
Neither way provided stable results. There are some jumps between directions depending on object movement.