Example #1
0
        public static ObjCell GetVisible(int cellID)
        {
            if (cellID == 0)
            {
                return(null);
            }

            if ((cellID & 0xFFFF) >= 0x100)
            {
                return(EnvCell.GetVisible(cellID));
            }
            else
            {
                return(LandCell.Get(cellID));
            }
        }
Example #2
0
        public static ObjCell Get(uint cellID)
        {
            if (cellID == 0)
            {
                return(null);
            }

            var objCell = new ObjCell(cellID);

            if (cellID >= 0x100)
            {
                return(DBObj.GetEnvCell(cellID));
            }

            return(LandCell.Get(cellID));
        }
Example #3
0
        public static ObjCell Get(uint cellID)
        {
            if (cellID == 0)
            {
                return(null);
            }

            var objCell = new ObjCell(cellID);

            if (cellID >= 0x100)
            {
                return((EnvCell)DBObj.Get(new QualifiedDataID(3, cellID)));
            }
            else
            {
                return(LandCell.Get(cellID));
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        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);
        }
Example #7
0
        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);
                    }
                }
            }
        }