public virtual bool hits_walkable(SpherePath path, Sphere validPos, Vector3 up) { if (!Sphere.Intersects(validPos)) { return(false); } var dist = Vector3.Dot(SplittingPlane.Normal, validPos.Center) + SplittingPlane.D; var reach = validPos.Radius - PhysicsGlobals.EPSILON; if (dist >= reach) { return(PosNode.hits_walkable(path, validPos, up)); } if (dist <= -reach) { return(NegNode.hits_walkable(path, validPos, up)); } if (PosNode.hits_walkable(path, validPos, up)) { return(true); } if (NegNode.hits_walkable(path, validPos, up)) { return(true); } return(false); }
public bool adjust_sphere_to_plane(SpherePath path, Sphere validPos, Vector3 movement) { var dpPos = Vector3.Dot(Plane.Normal, validPos.Center); var dpMove = Vector3.Dot(Plane.Normal, movement); var distSq = 0.0f; if (dpMove <= PhysicsGlobals.EPSILON) { if (dpMove >= -PhysicsGlobals.EPSILON) { return(false); } distSq = dpPos - validPos.Radius; } else { distSq = -validPos.Radius - dpPos; } var dist = distSq / dpMove; var interp = (1.0f - dist) * path.WalkInterp; if (interp >= path.WalkInterp || interp < -0.5f) { return(false); } validPos.Center -= movement * dist; path.WalkInterp = interp; return(true); }
public TransitionState NegPolyHit(SpherePath path, Polygon hitPoly, bool stepUp) { var collisionNormal = path.LocalSpacePos.LocalToGlobalVec(hitPoly.Plane.Normal); path.SetNegPolyHit(stepUp, collisionNormal); return(TransitionState.OK); }
public TransitionState placement_insert_inner(Sphere validPos, SpherePath path, int i) { if (i == 0) { var adjust = validPos.Center - path.LocalSpaceSphere[0].Center; var offset = path.LocalSpacePos.LocalToGlobalVec(adjust); path.AddOffsetToCheckPos(offset); return(TransitionState.Adjusted); } return(TransitionState.OK); }
public bool walkable_hits_sphere(SpherePath path, Sphere sphere, Vector3 up) { if (Vector3.Dot(up, Plane.Normal) <= path.WalkableAllowance) { return(false); } Vector3 contactPoint = Vector3.Zero; var hit = polygon_hits_sphere_precise(sphere, ref contactPoint); if (hit != polygon_hits_sphere(sphere, ref contactPoint)) { polygon_hits_sphere_precise(sphere, ref contactPoint); polygon_hits_sphere(sphere, ref contactPoint); } return(hit); }
public override void find_walkable(SpherePath path, Sphere validPos, ref Polygon hitPoly, Vector3 movement, Vector3 up, ref bool changed) { if (NumPolys == 0 || !Sphere.Intersects(validPos)) { return; } foreach (var polygon in Polygons) { if (polygon.walkable_hits_sphere(path, validPos, up) && polygon.adjust_sphere_to_plane(path, validPos, movement)) { changed = true; hitPoly = polygon; } } }
public override bool hits_walkable(SpherePath path, Sphere validPos, Vector3 up) { if (NumPolys == 0 || !Sphere.Intersects(validPos)) { return(false); } foreach (var polygon in Polygons) { if (polygon.walkable_hits_sphere(path, validPos, up) && polygon.check_small_walkable(validPos, up)) { return(true); } } return(false); }
void Awake() { myCamera = gameObject.GetComponent <Camera>(); myPath = new SpherePath(verticalSteps, horizontalSteps, distance, minZangle, maxZangle); myPath.generatePath(); objectType = new Dictionary <string, int>(); focusTags = new List <string>(); foreach (string t in UnityEditorInternal.InternalEditorUtility.tags) { if (t.Contains(focusTagRadical) && GameObject.FindWithTag(t) != null) { focusTags.Add(t); // active objects with wanted tag Debug.Log(t); } } }
public virtual void find_walkable(SpherePath path, Sphere validPos, ref Polygon polygon, Vector3 movement, Vector3 up, ref bool changed) { if (!Sphere.Intersects(validPos)) { return; } var dist = Vector3.Dot(SplittingPlane.Normal, validPos.Center) + SplittingPlane.D; var reach = validPos.Radius - PhysicsGlobals.EPSILON; if (dist >= reach) { PosNode.find_walkable(path, validPos, ref polygon, movement, up, ref changed); return; } if (dist <= -reach) { NegNode.find_walkable(path, validPos, ref polygon, movement, up, ref changed); return; } PosNode.find_walkable(path, validPos, ref polygon, movement, up, ref changed); NegNode.find_walkable(path, validPos, ref polygon, movement, up, ref changed); }
public override void find_transit_cells(Position position, int numSphere, List <Sphere> spheres, CellArray cellArray, SpherePath path) { var checkOutside = false; foreach (var portal in Portals) { var portalPoly = CellStructure.Polygons[portal.PolygonId]; if (portal.OtherCellId == ushort.MaxValue) { foreach (var sphere in spheres) { var rad = sphere.Radius + PhysicsGlobals.EPSILON; var center = Pos.Frame.GlobalToLocal(sphere.Center); var dist = Vector3.Dot(center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (dist > -rad && dist < rad) { checkOutside = true; break; } } } else { var otherCell = GetVisible(portal.OtherCellId); if (otherCell != null) { foreach (var sphere in spheres) { var center = otherCell.Pos.Frame.GlobalToLocal(sphere.Center); var _sphere = new Sphere(center, sphere.Radius); var boundingType = otherCell.CellStructure.sphere_intersects_cell(_sphere); if (boundingType != BoundingType.Outside) { cellArray.add_cell(otherCell.ID, otherCell); break; } } } else { foreach (var sphere in spheres) { var center = Pos.Frame.GlobalToLocal(sphere.Center); var _sphere = new Sphere(center, sphere.Radius + PhysicsGlobals.EPSILON); var portalSide = portal.PortalSide; var dist = Vector3.Dot(_sphere.Center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (dist > -_sphere.Radius && portalSide || dist < _sphere.Radius && !portalSide) { cellArray.add_cell(portal.OtherCellId, null); break; } } } } } if (checkOutside) { LandCell.add_all_outside_cells(position, numSphere, spheres, cellArray); } }
public void check_building_transit(ushort portalId, Position pos, int numSphere, List <Sphere> spheres, CellArray cellArray, SpherePath path) { //if (portalId == 0) return; if (portalId == ushort.MaxValue) { return; } foreach (var sphere in spheres) { var globSphere = new Sphere(Pos.Frame.GlobalToLocal(sphere.Center), sphere.Radius); if (CellStructure.sphere_intersects_cell(globSphere) == BoundingType.Outside) { continue; } if (path != null) { path.HitsInteriorCell = true; } cellArray.add_cell(ID, this); } }
public virtual void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { // override? }
public static ObjCell find_cell_list(Position position, int numSphere, Sphere sphere, CellArray cellArray, ObjCell currCell, SpherePath path) { return(find_cell_list(position, numSphere, new List <Sphere>() { sphere }, cellArray, currCell, path)); }
public static ObjCell find_cell_list(CellArray cellArray, ObjCell checkCell, SpherePath path) { return(find_cell_list(path.CheckPos, path.NumSphere, path.GlobalSphere, cellArray, checkCell, path)); }
public static void find_cell_list(Position position, Sphere sphere, CellArray cellArray, SpherePath path) { var globalSphere = new Sphere(); globalSphere.Center = position.LocalToGlobal(sphere.Center); globalSphere.Radius = sphere.Radius; find_cell_list(position, 1, globalSphere, cellArray, null, path); }
public override void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { add_all_outside_cells(position, numSphere, sphere, cellArray); base.find_transit_cells(position, numSphere, sphere, cellArray, path); }
public static ObjCell find_cell_list(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, ObjCell currCell, SpherePath path) { cellArray.NumCells = 0; cellArray.AddedOutside = false; var cell = GetVisible(position.ObjCellID); if ((position.ObjCellID & 0xFFFF) >= 0x100) { if (path != null) { path.HitsInteriorCell = true; } cellArray.add_cell(position.ObjCellID, cell); } else { LandCell.add_all_outside_cells(position, numSphere, sphere, cellArray); } if (cell != null && numSphere != 0) { foreach (var otherCell in cellArray.Cells) { if (otherCell != null) { otherCell.find_transit_cells(position, numSphere, sphere, cellArray, path); } } if (currCell != null) { foreach (var otherCell in cellArray.Cells) { var blockOffset = LandDefs.GetBlockOffset(position.ObjCellID, otherCell.ID); var localPoint = sphere[0].Center - blockOffset; if (otherCell.point_in_cell(localPoint) && (otherCell.ID & 0xFFFF) >= 0x100) { if (path != null) { path.HitsInteriorCell = true; } return(otherCell); } } } } if (!cellArray.LoadCells && (position.ObjCellID & 0xFFFF) >= 0x100) { foreach (var otherCell in cellArray.Cells) { if (cell.ID != otherCell.ID) { continue; } var found = false; foreach (var stab in cell.StabList) { if (otherCell.ID == stab) { found = true; break; } } if (!found) { cellArray.remove_cell(otherCell); } } } return(null); }
public void find_building_transit_cells(Position pos, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { foreach (var portal in Portals) { var otherCell = portal.GetOtherCell(CurCell.ID); if (otherCell != null) { otherCell.check_building_transit(portal.OtherPortalId, pos, numSphere, sphere, cellArray, path); } } }
public void find_building_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { /*foreach (var portal in Portals) * { * var otherCell = portal.GetOtherCell(); * if (otherCell != null) * otherCell.check_building_transit(portal.OtherPortalID, numSphere, sphere, cellArray, path); * }*/ }
public TransitionState check_walkable(SpherePath path, Sphere checkPos, float scale) { var validPos = new Sphere(checkPos); return(RootNode.hits_walkable(path, validPos, path.LocalSpaceZ) ? TransitionState.Collided : TransitionState.OK); }
public static void find_cell_list(Position position, int numSphere, Sphere sphere, CellArray cellArray, ref ObjCell currCell, SpherePath path) { find_cell_list(position, numSphere, new List <Sphere>() { sphere }, cellArray, ref currCell, path); }
public static void find_cell_list(CellArray cellArray, ref ObjCell checkCell, SpherePath path) { find_cell_list(path.CheckPos, path.NumSphere, path.GlobalSphere, cellArray, ref checkCell, path); }
public static void find_cell_list(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, ref ObjCell currCell, SpherePath path) { cellArray.NumCells = 0; cellArray.AddedOutside = false; var visibleCell = GetVisible(position.ObjCellID); if ((position.ObjCellID & 0xFFFF) >= 0x100) { if (path != null) { path.HitsInteriorCell = true; } cellArray.add_cell(position.ObjCellID, visibleCell); } else { LandCell.add_all_outside_cells(position, numSphere, sphere, cellArray); } if (visibleCell != null && numSphere != 0) { for (var i = 0; i < cellArray.Cells.Count; i++) { var cell = cellArray.Cells.Values.ElementAt(i); if (cell == null) { continue; } cell.find_transit_cells(position, numSphere, sphere, cellArray, path); } //var checkCells = cellArray.Cells.Values.ToList(); //foreach (var cell in checkCells) //cell.find_transit_cells(position, numSphere, sphere, cellArray, path); if (currCell != null) { currCell = null; foreach (var cell in cellArray.Cells.Values) { if (cell == null) { continue; } var blockOffset = LandDefs.GetBlockOffset(position.ObjCellID, cell.ID); var localPoint = sphere[0].Center - blockOffset; if (cell.point_in_cell(localPoint)) { currCell = cell; if ((cell.ID & 0xFFFF) >= 0x100) { if (path != null) { path.HitsInteriorCell = true; } return; // break? } } } } } if (!cellArray.LoadCells && (position.ObjCellID & 0xFFFF) >= 0x100) { var cells = cellArray.Cells.Values.ToList(); foreach (var cell in cells) { if (cell == null) { continue; } if (visibleCell.ID == cell.ID) { continue; } var found = false; foreach (var stab in ((EnvCell)visibleCell).VisibleCells.Values) { if (stab == null) { continue; } if (cell.ID == stab.ID) { found = true; break; } } if (!found) { cellArray.remove_cell(cell); } } } }
public static void find_cell_list(Position position, int numCylSphere, List <CylSphere> cylSphere, CellArray cellArray, SpherePath path) { if (numCylSphere > 10) { numCylSphere = 10; } var spheres = new List <Sphere>(); for (var i = 0; i < numCylSphere; i++) { var sphere = new Sphere(); sphere.Center = position.LocalToGlobal(cylSphere[i].LowPoint); sphere.Radius = cylSphere[i].Radius; spheres.Add(sphere); } find_cell_list(position, numCylSphere, spheres, cellArray, null, path); }
public virtual void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path, uint instance) { // empty base }
public override void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path) { if (Building != null) { Building.find_building_transit_cells(position, numSphere, sphere, cellArray, path); } }
public static void find_cell_list(Position position, Sphere sphere, CellArray cellArray, SpherePath path, uint instance) { var globalSphere = new Sphere(); globalSphere.Center = position.LocalToGlobal(sphere.Center); globalSphere.Radius = sphere.Radius; ObjCell empty = null; find_cell_list(position, 1, globalSphere, cellArray, ref empty, path, instance); }
public static void find_cell_list(Position pos, int numCylSphere, CylSphere cylSphere, CellArray cellArray, SpherePath path) { }