Can anyone point me to an extension or a tutorial that explains how to detect if an object falls between 2 points. I want to determine if an active object is between a fixed point and the mouse cursor.
Thanks,
Mobichan
Printable View
Can anyone point me to an extension or a tutorial that explains how to detect if an object falls between 2 points. I want to determine if an active object is between a fixed point and the mouse cursor.
Thanks,
Mobichan
All I can say (I need to leave for something) is use the Pythagorean Theorem. That should give you a start...
Then detect if the point of the active is a point on that line? Slope intercept? Idk more when I get back?
a cheap way would be use a 1-pixel detector object and do something like:
Always
--> Detector - Set Distance (AV A): ceil(sqr((X("Point") - xmouse) pow 2 + (Y("Point") - ymouse) pow 2))
--> Detector - Set AngleTo (AV B): atan2(Y("Point") - ymouse, X("Point") - xmouse) [you may need to flip the subtraction order]
--> Start Loop: "ObjectCheck"; Distance("Detector")
On loop "ObjectCheck"
--> Detector - Set X: X("Point") + cos(AngleTo("Detector")) * loopindex("ObjectCheck")
--> Detector - Set Y: Y("Point") + sin(AngleTo("Detector")) * loopindex("ObjectCheck")
On loop "ObjectCheck"
+ "Detector" is overlapping "Object"
--> Stop loop: "ObjectCheck"
--> Object - [do whatever]
there's probably a better/easier way to do this but it should work regardless
Thanks for the suggestion. I'll give it a shot. But I would still be interested in the mathematical approach if anyone has the time to explain.
Ok I'm back for like 2 seconds. I'm no mathematician so I'm not sure if what I have in mind is possible.
I'm thinking you find the slope, and then plug in the numbers to see if they work. (Y("Object")=1/2 x("Object") + 2
But I'm not sure that would work...
the "problem" (which may be one or it may be the desired behavior) of just using the X and Y of the object alone is that it'll only be true if the object's hotspot is on the line; the method i posted will be true if any non-transparent pixel of the object is on the line (provided both the detector and the object are set to fine collisions)
so again, it depends on if you need the entire object or just the hotspot
I am actually setting up a circular menu constructed of icons (like a marking menu in Maya, if you are familiar with Maya). When you click and hold, the menu appears and you can drag the mouse cursor over the icons and release the mouse button to select that icon. I just wanted to make it so that you only had to drag the mouse in the direction of the icons and not have to be on a pixel of the icon when the button is released. So, I could use xyzzy's method. But I was just hoping to learn how to do it through math. :) A friend of mine suggested doing a line/sphere check or a line/line check. He sent me the math, but it is a little confusing how I would apply that in MMF.
Mobichan
All I got is:
Compare two general Values: Y("Object") = (Y("Fixed")-YMouse)/(X("Fixed")-XMouse)*X("Object")+(Y-(Y("Fixed")-YMouse)/(X("Fixed")-XMouse))
+ XMouse < X("Fixed")
+X("Object") < X("Fixed")
+ X("Object") > XMouse
Compare two general Values: Y("Object") = (Y("Fixed")-YMouse)/(X("Fixed")-XMouse)*X("Object")+(Y-(Y("Fixed")-YMouse)/(X("Fixed")-XMouse))
+ XMouse > X("Fixed")
+X("Object") > X("Fixed")
+ X("Object") < XMouse
That's just to see if there is something in between the two points. I'm sure there would be a way to get the entire box through this like xyzzy said, except you would get even the transparent ones anyway. I haven't tested it yet, but I'll see if it works.
xyzzy: I just realized that the atan2 formula you provided makes the angles that are calculated on a clockwise circle. Is there a way to detect the angles in a counterclockwise circle (like MMF does natively)?
Can anyone suggest a way to determine an angle between 2 points so that the coordinate system has 0 degrees at the left and goes counter clockwise (similar to the way the directions for active objects are)?
I can but not at the moment. Maybe later I'll get back to u on that
ADO (Advanced Direction Object)
Or you can use math. I think if you get 360 and subtract the degrees from it, it will give you the degrees in reverse.
Eg: you get 25 degrees = 360-25 = 335 degrees
Turns out that atan2(-y, x) works. If the result is a negative value, you add 360 to it. That gets a range of angles from 0 - 360 going counterclockwise with 0 degrees on the right/east side of the circle.
Thanks anywho. This thread has taut me loads. :D
Mobichan
Probably simpler with ADO but glad you figured it out! ;)
For some reason MMF2 rounds it so it doesn't :(Quote:
Originally Posted by RickyRombo