public virtual bool sphere_intersects_solid_poly(Sphere checkPos, float radius, ref bool centerSolid, ref Polygon hitPoly, bool centerCheck) { if (!Sphere.Intersects(checkPos)) { return(false); } var dist = Vector3.Dot(SplittingPlane.Normal, checkPos.Center) + SplittingPlane.D; var reach = radius - PhysicsGlobals.EPSILON; if (dist >= reach) { return(PosNode.sphere_intersects_solid_poly(checkPos, radius, ref centerSolid, ref hitPoly, centerCheck)); } if (dist <= -reach) { return(NegNode.sphere_intersects_solid_poly(checkPos, radius, ref centerSolid, ref hitPoly, centerCheck)); } if (dist <= 0.0f) { NegNode.sphere_intersects_solid_poly(checkPos, radius, ref centerSolid, ref hitPoly, centerCheck); if (hitPoly != null) { return(centerSolid); } return(PosNode.sphere_intersects_solid_poly(checkPos, radius, ref centerSolid, ref hitPoly, false)); } else { PosNode.sphere_intersects_solid_poly(checkPos, radius, ref centerSolid, ref hitPoly, centerCheck); if (hitPoly != null) { return(centerSolid); } return(NegNode.sphere_intersects_solid_poly(checkPos, radius, ref centerSolid, ref hitPoly, false)); } }
public TransitionState placement_insert(Transition transition) { var path = transition.SpherePath; var validPos = new Sphere(path.LocalSpaceSphere[0]); var rad = validPos.Radius; Sphere validPos_ = null; if (path.NumSphere > 1) { validPos_ = new Sphere(path.LocalSpaceSphere[1]); } var clearCell = true; if (path.BuildingCheck) { clearCell = !path.HitsInteriorCell; } Polygon hitPoly = null; var maxIterations = 20; // hardcoded for (var i = 0; i < maxIterations; i++) { var centerSolid = false; if (RootNode.sphere_intersects_solid_poly(validPos, rad, ref centerSolid, ref hitPoly, clearCell)) { if (hitPoly != null) { hitPoly.adjust_to_placement_poly(validPos, validPos_, rad, centerSolid, clearCell); continue; } } else { if (path.NumSphere >= 2) { if (RootNode.sphere_intersects_solid_poly(validPos_, rad, ref centerSolid, ref hitPoly, clearCell)) { if (hitPoly != null) { hitPoly.adjust_to_placement_poly(validPos_, validPos, rad, centerSolid, clearCell); continue; } } else { return(placement_insert_inner(validPos, path, i)); } } else { return(placement_insert_inner(validPos, path, i)); } } rad *= 2; } return(TransitionState.Collided); }