public static void add_cell_block(int min_x, int min_y, int max_x, int max_y, CellArray cellArray, uint id) { for (var i = min_x; i <= max_x; i++) { for (var j = min_y; j <= max_y; j++) { if (i < 0 || j < 0 || i >= LandDefs.LandLength || j >= LandDefs.LandLength) { continue; } var ui = (uint)i; var uj = (uint)j; var cellID = (((uj >> 3) | 32 * (ui & 0xFFFFFFF8)) << 16) | ((uj & 7) + 8 * (ui & 7) + 1); // FIXME! if (id >> 16 != cellID >> 16) { continue; } var cell = LScape.get_landcell(cellID); cellArray.add_cell(cellID, cell); } } }
public static void add_outside_cell(CellArray cellArray, float _x, float _y) { var x = (uint)_x; var y = (uint)_y; if (x >= 0 && y >= 0 && x < 2040 && y < 2040) { var cellID = (((y >> 3) | 32 * (x & 0xFFFFFFF8)) << 16) | ((y & 7) + 8 * (x & 7) + 1); var landCell = Get(cellID); if (landCell != null) { cellArray.add_cell(cellID, landCell); } } }
public void check_building_transit(ushort portalId, Position pos, int numSphere, List <Sphere> spheres, CellArray cellArray, SpherePath path) { if (portalId == 0) { 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 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 override void find_transit_cells(int numParts, List <PhysicsPart> parts, CellArray cellArray) { var checkOutside = false; foreach (var portal in Portals) { var portalPoly = CellStructure.Polygons[portal.PolygonId]; foreach (var part in parts) { if (part == null) { continue; } var sphere = part.GfxObj.PhysicsSphere; if (sphere == null) { sphere = part.GfxObj.DrawingSphere; } if (sphere == null) { continue; } var center = Pos.LocalToLocal(part.Pos, sphere.Center); var rad = sphere.Radius + PhysicsGlobals.EPSILON; var dist = Vector3.Dot(center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (portal.PortalSide) { if (dist < -rad) { continue; } } else { if (dist > rad) { continue; } } var bbox = part.GetBoundingBox(); var box = new BBox(); box.LocalToLocal(bbox, part.Pos, Pos); var sidedness = portalPoly.Plane.intersect_box(box); if (sidedness == Sidedness.Positive && !portal.PortalSide || sidedness == Sidedness.Negative && portal.PortalSide) { continue; } if (portal.OtherCellId == ushort.MaxValue) { checkOutside = true; break; } // LoadCells var otherCell = GetVisible(portal.OtherCellId); if (otherCell == null) { cellArray.add_cell(portal.OtherCellId, null); break; } var cellBox = new BBox(); cellBox.LocalToLocal(bbox, Pos, otherCell.Pos); if (otherCell.CellStructure.box_intersects_cell(cellBox)) { cellArray.add_cell(otherCell.ID, otherCell); break; } } } if (checkOutside) { LandCell.add_all_outside_cells(numParts, parts, cellArray, ID); } }
public void check_building_transit(int portalId, int numParts, List <PhysicsPart> parts, CellArray cellArray) { //if (portalId == 0) return; if (portalId == ushort.MaxValue) { return; } var portal = Portals[portalId]; var portalPoly = CellStructure.Portals[portalId]; foreach (var part in parts) { if (part == null) { continue; } Sphere boundingSphere = null; if (part.GfxObj.PhysicsSphere != null) { boundingSphere = part.GfxObj.PhysicsSphere; } else { boundingSphere = part.GfxObj.DrawingSphere; } if (boundingSphere == null) { continue; } var center = Pos.LocalToLocal(part.Pos, boundingSphere.Center); var rad = boundingSphere.Radius + PhysicsGlobals.EPSILON; var diff = Vector3.Dot(center, portalPoly.Plane.Normal) + portalPoly.Plane.D; if (portal.PortalSide) { if (diff > rad) { continue; } } else { if (diff < -rad) { continue; } } var box = new BBox(); box.LocalToLocal(part.GetBoundingBox(), part.Pos, Pos); var intersect = portalPoly.Plane.intersect_box(box); if (intersect == Sidedness.Crossing || intersect == Sidedness.Positive && portal.PortalSide || intersect == Sidedness.Negative && !portal.PortalSide) { if (!CellStructure.box_intersects_cell(box)) { continue; } cellArray.add_cell(ID, this); find_transit_cells(numParts, parts, cellArray); return; } } }
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 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); } } } }