On 07/07/2016 at 11:32, xxxxxxxx wrote:
After some testing. The LassoSelection class makes this dead simple and does all the work.
However. I'm getting some very strange results from the Test(x, y) function.
It's either a bug. Or I'm using it wrong?
//This code is used in the MouseInput() method of a tooldata plugin
//It draws a lasso selection in the editor window
LassoSelection *ls = LassoSelection::Alloc();
//If the entire polygon is surrounded it outputs 1...otherwise outputs zero
//Works as expected
CPolygon poly = obj->GetPolygonW(); //<---the target polygon
//Convert the poly's points into 2D screen space
Vector pa = bd->WS(poly.a);
Vector pb = bd->WS(poly.b);
Vector pc = bd->WS(poly.c);
Vector pd = bd->WS(poly.d);
//Test if the 2D a,b,c,d are inside the selection.The point c can be equal to d in case of a triangle
bool test = ls->TestPolygon(pa, pb, pc, pd);
//Test if (x, y) is inside the lasso selection
//Works...But getting strange numbers from it: 1,2,8,64,128,etc...
Vector point = obj->GetPointW()[poly.a]; //<---The target point in world space
Vector pointWS = bd->WS(point); //Convert the point into 2D screen space
LONG x = pointWS.x;
LONG y = pointWS.y;
Bool test2 = ls->Test(x, y);
GePrint(LongToString(test2)); //Working. But getting strange numbers?! 1,2,8,64,128,etc...
ls->Free(ls); //<--don't forget or you'll get memory leaks!!