So I have a simple program where there is an arrow and it moves towards the mouse. I calculate the angle between the current 'player' position and where it should go.
heading = std::atan2(yTarget - yPos, xTarget - xPos) * RAD2DEGREE;
The sprite's rotation is then set to be equal to the heading later in the same function:
playerSprite.SetRotation(heading);
However, it faces opposite up and down movement of the mouse. If I move the mouse up, it rotates to face down. If I move the mouse down, it rotates to face up. It works correctly left to right; if you are directly left or right of the arrow, then the arrow will face the mouse as it should.
I logged the numbers and it appears that when directly above the player position, atan2 is return -90 degrees, which then in the rotation function of the sprite gets converted to 270.
However, also odd is that if I multiply heading by -1 in the SetRotation function argument, it works completely fine even though the log shows completely different numbers for heading and orientation. For example:
Heading = 44.113
Sprite Rotation = 315.887
But the player sprite, an arrow, is pointing directly at the mouse button the entire time.
I simply don't understand what is going on and would love someone to explain what I'm missing.