Math-like problem with circles and coords
In a map in my game, I've got a X and Y location, so do other players. I'm trying to draw this on a little radar.
In the first pic (click the link below) you can see the red dot (you) and the blue dot is the other player and the arrow is where you're looking at (ingame). The other player is left in front of you as you can see.
In the second pic you look to the left, on your screen you will see the other player right infront of you, but on the radar nothing has changed.
In the third pic you can see what should've happened. All dots need to 'move' on that imaginary circle, just the ammount of degrees you have turned around - just in the opposite direction so if you look to the left, the dots will need to move to the right (on that imaginary circle)...hard to explain - At least thats my interpretation of how it should be done.
Link to explanatory image ->http://img495.imageshack.us/img495/254/radar4wc.png
I'm guessing I need to 'draw' a circle with a radius of half the distance between the two players, and move the dot a negative ammount of degrees on that circle, depending on the ammount of degrees I look around. So if I look 90 degrees to the left, all the dots on the radar will need to move -90 degrees 'on' that circle (which will be the hardest part to do...).
Any ideas how this last bit can be done?
Thanks in advance.
Ps - Sorry for the hard explanation...
Ok first let me cut you explination in to some finite statements.
1) We are talking about this radar only showing your relative look to the position of other players. So we are talking about only the degrees having any variance. This meaning we are looking at unit based relations.
2) I will be assuming you already have the angle at which your player is looking.
So becouse of statement one, we can use a normalized aproach when factoring in the players relative position, ie use the slope.
So first find the slope of the player being used to the player on radar by simply using their (x,y). Now this gives us the difference of x and of y, meaning we now have the x and y on a Unit Circle.
So we need to find the angle to that line. So we take the
tan^-1(m), m being the slope. So what dose this give us? This gives us the angle of where the player is on the radar as if we where looking straight to the right, remember 0 starts on the right of the radian circle.
But we are not looking directly left all the time. This is where the known angle comes in. Take the angle we just found and subtract the angle we are looking. The result will be the the true angle of where the player on the radar is to where we are looking.
But you want that arrow to always point up so now, having this relative angle between the two, you just add
(((90*(quadrant)) - angle player is looking)-(90 *(quadrant-1)) to the angle of the player the on the radar.
So remember kiddies Math is cool So stay in school.
Except that is not how you draw it.
For circular radars.
1. Use SetViewport()
2. Use alpha blending to mask out the unwanted portions of the quad.
3. Draw to viewport.
Or you can use SetRenderTarget() and draw to offscreen surface and then copy surface to SetViewport() area.
Last edited by VirtualAce; 12-12-2005 at 01:28 PM.