I have a question about Processing, which uses code similar to C++. I hope I came to the right place to ask this question.
I was making a 2d game and I need a picture to face where the mouse is pointing. So for example the picture is the top down view of a man's head and his head should rotate depending on where the mouse is located (i.e. his eyes face the mouse).
I tried using tan to calculate the angle, but I got a weird result.
Here is my code (NOTE: only top right quarter of the screen can calculate the angle):
I can give an idea for how I might start this problem. The lengths of a right angle triangle are described by the relation c^2 = a^2 + b^2
You first need a reference point (in terms of mouse coordinates) for your picture. Then, with your cursor coordinates you can make a simple subtraction to find the distance between the two. Then (for example), you can use a point along the x-axis from the 'picture's position to form a right angle. Then it is another simple subtraction to determine the length of another side. From there it should be trivial to find the angle you desire.