Help with Math

Hi,

 

my idea is visualising but i’m stuck at a very simple math problem:

From the center (200,150) i want to spawn objects an move them direction mouseclick  until they hit the border of the screen.

I’m able to increment x, y correctly, what i’m not able to do is to let the object move in the correct direction the mouse was clicked.

 

Hope someone can help me :)

Comments

17. Dec 2011 · 14:34 UTC
i think you are looking for atan2(); google it!
17. Dec 2011 · 14:36 UTC
Very quick, some pseudo code.. Not sure if it helps or not.
17. Dec 2011 · 14:36 UTC
float dx = from.getX() – to.getX();

float dy = from.getY() – to.getY();

return (float) Math.toDegrees(Math.atan2(dy, dx)) – 90;
delpes
17. Dec 2011 · 15:19 UTC
I really don’t get my head around this. I think i’ve been awake for far too long now.