Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public TransitionState NegPolyHit(SpherePath path, Polygon hitPoly, bool stepUp)
        {
            var collisionNormal = path.LocalSpacePos.LocalToGlobalVec(hitPoly.Plane.Normal);

            path.SetNegPolyHit(stepUp, collisionNormal);

            return(TransitionState.OK);
        }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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;
                }
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
    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);
            }
        }
    }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
 public virtual void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path)
 {
     // override?
 }
Exemplo n.º 13
0
 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));
 }
Exemplo n.º 14
0
 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));
 }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 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);
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
 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);
         }
     }
 }
Exemplo n.º 19
0
 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);
      * }*/
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
 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);
 }
Exemplo n.º 22
0
 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);
 }
Exemplo n.º 23
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);
                    }
                }
            }
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
 public virtual void find_transit_cells(Position position, int numSphere, List <Sphere> sphere, CellArray cellArray, SpherePath path, uint instance)
 {
     // empty base
 }
Exemplo n.º 26
0
 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);
     }
 }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
 public static void find_cell_list(Position pos, int numCylSphere, CylSphere cylSphere, CellArray cellArray, SpherePath path)
 {
 }