Finding a point on a line is not the answer. He doesn't want to know if the mouse is ON the line, he wants to know if it's passed over it.
To do that, first, calcualte the normal of the line:
http://www.blitzbasic.com/codearcs/codearcs.php?code=450
Then, using Nx and Ny for A and B do this:
For an arbitary point (px,py), the distance to the line is:
distance = A*px + B*py + D
Astute readers will notice that this is a hacked up version of the plane equation, which is how I derived all this stuff, by pretending the line was the intersection of a 3D plane intersecting 2D space and canceling out all the Z stuff with 0's.
Anyhow, now that you know the distance, know that the distance here is either positive, or negative. Which it is depends on which side of the line you specified you are on.
You can then use this to dtermine that the mouse cursor moved from one side of a line to the other during a frame, and thus that the mouse crossed the line.
Also, this is probably not important for you, but I forget which way the line normal will point. I forget whether the normal, and thus the positive side of the line, points to the left or right if you are at point 1 on the line looking at point 2. I think it's to the left. If someone wants to figure that out and tell me then I'll update the code archives to reflect that.
To do that, first, calcualte the normal of the line:
http://www.blitzbasic.com/codearcs/codearcs.php?code=450
Then, using Nx and Ny for A and B do this:
For an arbitary point (px,py), the distance to the line is:
distance = A*px + B*py + D
Astute readers will notice that this is a hacked up version of the plane equation, which is how I derived all this stuff, by pretending the line was the intersection of a 3D plane intersecting 2D space and canceling out all the Z stuff with 0's.
Anyhow, now that you know the distance, know that the distance here is either positive, or negative. Which it is depends on which side of the line you specified you are on.
You can then use this to dtermine that the mouse cursor moved from one side of a line to the other during a frame, and thus that the mouse crossed the line.
Also, this is probably not important for you, but I forget which way the line normal will point. I forget whether the normal, and thus the positive side of the line, points to the left or right if you are at point 1 on the line looking at point 2. I think it's to the left. If someone wants to figure that out and tell me then I'll update the code archives to reflect that.