|
![](/i/fill.gif) |
> You pick a random point on one of the faces of the bounding box and shoot
> toward the oposite face. Using the smalest face will probably help.
Yeah, but then you might miss long skinny things aligned that way sometimes.
> You exit on the first non-zero normal.
Yeah, the old one was early exit too, the poorest performance is for non-
collisions since all the checks have to run.
> Advantage of using trace:
> Advantage: you no longer test points but lines. One test will check
> millons of points.
Yeah, after a few tests it feels a bit more accurate, this should
be able to find collisions with low volume that have a larger surface
area easier too. I'm not sure what the math for figuring out the
failure rate is for this method, theoretically there are an infinite
number of points on a line segment, I guess in practice you could
count them as being points 0.001 apart.
#macro collision(A B rez)
#local result = false;
#if (((min_extent(A).x > max_extent(B).x ) |
(min_extent(B).x > max_extent(A).x ) |
(min_extent(A).y > max_extent(B).y ) |
(min_extent(B).y > max_extent(A).y ) |
(min_extent(A).z > max_extent(B).z ) |
(min_extent(B).z > max_extent(A).z ))=false)
#local AB = intersection{object{A} object{B}};
#local Mn = min_extent(AB);
#local Mx = max_extent(AB);
#local S1 = seed(1);
#local cnt = 0;
#while ((result = false) & (cnt < rez))
#local Pt = VRand_In_Box(Mn, Mx, S1);
#local Norm = <0,0,0>;
#local Hit = trace(AB,<Pt.x,Mn.y-0.1,Pt.z>,y,Norm);
#if (vlength(Norm)!=0)
#local result = true;
#else
#local Hit = trace(AB,<Mn.x-0.1,Pt.y,Pt.z>,x,Norm);
#if (vlength(Norm)!=0)
#local result = true;
#else
#local Hit = trace(AB,<Pt.x,Pt.y,Mn.z-0.1,>,z,Norm);
#if (vlength(Norm)!=0)
#local result = true;
#end
#end
#end
#local cnt = cnt + 1;
#end
#end
(result)
#end
Post a reply to this message
|
![](/i/fill.gif) |