Angle quadrants

Monkey Forums/Monkey Programming/Angle quadrants

grovey(Posted 2013) [#1]
Hi all

I am wondering what considerations I need to make when utilizing player and enemy angles.

Since screen coords are in the fourth quadrant, it is confusing me when thinking about movement in the first quadrant.
 2 | 1
-------
 3 | 4

I have a function that takes an angle and returns a vector i.e. For 0 degrees the vector faces right, 90 is down, etc...

vector.x = cos(angle)
vector.y = sin(angle)

Do you guys transform the quadrant? If so how?

Or do you just base all your movement in the 4th quadrant? What makes it even more confusing is image rotation in Monkey.

I am just hoping to hear your thoughts and solutions.

Thanks


AdamRedwoods(Posted 2013) [#2]
...is this what you mean?
Atan2(x,y) 0-90, 90-180, 180-270, 270-360
or
Atan2r(x,y) for 0 to 2*PI.


grovey(Posted 2013) [#3]
hmmm, I am not sure how to explain

When utlizing

x = cos(angle)
y = sin(angle)

an angle of 90 will result in the facing vector facing down (4th quadrant)
and angle of 180 will result in the facing vector facing left (3rd quadrant)

When using atan2(x,y) on the same vectors above it returns 0 and -90 respectively. I realize I can change the signs of the vectors or swap them to place it in another quadrant i.e. atan2(y,x) will place resulting angles in the same quadrants specified above.

I am just not sure what others do to make sure their angles are consistent in their games.

I hope I am making sense, I am just struggling to keep consistency throughout my applications.

Here is are posts talking about rotating images which yields different results too.
http://www.monkeycoder.co.nz/Community/posts.php?topic=4319#46139
http://www.monkeycoder.co.nz/Community/posts.php?topic=356#2614


grovey(Posted 2013) [#4]
-Atan2(y,x) yields clockwise movement

as well as

vector.x = sin(angle)
vector.y = cos(angle)

Is this correct?

This is just new to me as I normally use cos(angle) for x component and sin(angle) for y component.

Even with the above noted, they still exhibit different angles, I am so confused.


Markus(Posted 2013) [#5]
i would use a quadrant list
and a method IsInside(x,y)
left,top
x>=x1 and y<=y1
right,bottom
x>=x2 and y<=y2

a simulated step move
x = cos(angle)+gridwidth
y = sin(angle)+gridheight


John Galt(Posted 2013) [#6]
Part of the confusion here is that monkey's Atan2 function is a bit weird in its variable definition. Just imagine the first parameter is y rather than x, and it's just like any other language.

From there on out, do what you like as long as it's consistent.


grovey(Posted 2013) [#7]
Thanks for the replies guys, I will make sure all my angles are consistent.


zoqfotpik(Posted 2013) [#8]
Encapsulate it all in a way that works for you and forget about it.

I agree with you that this sort of thing can be a real headscratcher, surprisingly so.