Computer Science Canada Tracking mouse in abstract areas. |
Author: | Prognosis [ Fri Oct 27, 2006 1:31 pm ] |
Post subject: | Tracking mouse in abstract areas. |
How would you be able to see if your mouse was inside... saw a circle? Or a triangle? OR a random shape that was drawn on the screen. What i acctually want to know this for, is so I can determine which quarter of the screen your mouse is in. But you see, its like a quartisian plane, but only rotated on a 45 degree angle. To make 4 large triangles. How do I know which one my mouse is in? Please take note I already know how to track the mouse, i just dont know how do do this. |
Author: | Tony [ Fri Oct 27, 2006 2:08 pm ] |
Post subject: | |
How would you check if a point is inside a trianle? Well if you break it up into 3 triangles (formed from each edge of the triangle, and the point in question), and the sum of areas of the 3 triangles == original triangle (+/- tolerance for floating point errors) then the point is inside the triangle. |
Author: | Prognosis [ Fri Oct 27, 2006 2:40 pm ] |
Post subject: | |
nah tony, that wont exactly work (i dont think at least). This is because Im working with 4 triangles on the screen with the exact same area. and I dont really know how to define these triangles. Just picture a huge X on the screen See how the x made four triangles I need to know which triangle your mouse is in right now. |
Author: | Clayton [ Fri Oct 27, 2006 3:04 pm ] |
Post subject: | |
well you could come up with some sort of formula using trig, where you check to see if x is in bounds, then use some sort of trig derived formula to check between y bounds at the give x coordinate |
Author: | Tony [ Fri Oct 27, 2006 3:08 pm ] |
Post subject: | |
It might make more sense if you try to do it on paper first. Draw a trinagle, pick any arbitrary point, connect the dots. Prognosis wrote: and I dont really know how to define these triangles.
well the leftmost trinagle will be defined by 3 points: 0, 0 0, maxx maxx div 2, maxy div 2 Oh yeah, and you'd have to perform the check for all 4 triangles, one at a time |
Author: | Prognosis [ Fri Oct 27, 2006 3:13 pm ] | ||
Post subject: | |||
Ive already tried to use trig, and it kinda failed. Obviously there must be a way to do it, but i guess i dont know how yet :/
Sure this is close, but after 90 degrees it starts messing up. |
Author: | Clayton [ Fri Oct 27, 2006 3:49 pm ] |
Post subject: | |
ok, i have a working solution, however, im not going to give you the source, however, try to create the program to follow mine, focus on the goal, keep the extras (like the circles) out until you can get the quadrants down. |