Exemplo n.º 1
0
        public void RemoveObjFromNavMesh(PhysicObj obj)
        {
            obj.getPosNode().neighbors.Remove(obj.getPosNode());
            RemoveNodeFromNavMesh(GetNavMesh(obj), obj.getPosNode());

            objNavMeshMapping.Remove(obj);
            PathDict.Remove(obj);
        }
Exemplo n.º 2
0
        public List <PathFinderNode> pathRequest(PhysicObj startObj, PhysicObj endObj)
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            startObj.getPosNode().neighbors.Remove(endObj.getPosNode());
            endObj.getPosNode().neighbors.Remove(startObj.getPosNode());

            RemoveNodeFromNavMesh(GetNavMesh(startObj), startObj.getPosNode());
            RemoveNodeFromNavMesh(GetNavMesh(startObj), endObj.getPosNode());

            AddNodeToNavMesh(GetNavMesh(startObj), startObj.getPosNode());
            AddNodeToNavMesh(GetNavMesh(startObj), endObj.getPosNode());

            if (PathProcessor.isWayClearToNode(startObj, endObj.getPosNode()))
            {
                //startObj.getPosNode().neighbors.Add(endObj.getPosNode());
                //endObj.getPosNode().neighbors.Add(startObj.getPosNode());
                return(new List <PathFinderNode>()
                {
                    startObj.getPosNode(), endObj.getPosNode()
                });
                //GetNavMesh(startObj).graph.AddEdge(new Edge<PathFinderNode>(startObj.getPosNode(), endObj.getPosNode()));
            }

            //startObj.getPosNode().reset();
            //endObj.getPosNode().reset();
            //navMeshes.ForEach(nav => nav.Nodes.ForEach(node => node.reset()));

            //var resultPath = pathProc.runDjikstra(startObj.getPosNode(), endObj.getPosNode());
            //var res = GetNavMesh(startObj).graph.ShortestPathsDijkstra(GetNavMesh(startObj).verticesDistance, startObj.getPosNode());
            if (GetNavMesh(startObj).graph.ContainsVertex(startObj.getPosNode()))
            {
                stopwatch.Start();
                var res = GetNavMesh(startObj).graph.ShortestPathsDijkstra(GetNavMesh(startObj).verticesDistance, startObj.getPosNode());

                IEnumerable <Edge <PathFinderNode> > path;
                if (res(endObj.getPosNode(), out path))
                {
                    var list  = path.ToList();
                    var list2 = new List <PathFinderNode>();// { startObj.getPosNode() };

                    foreach (var edge in list)
                    {
                        //if (list2[list2.Count - 1] == edge.Source)
                        //list2.Add(edge.Target);
                        //else
                        list2.Add(edge.Source);
                    }

                    stopwatch.Stop();
                    //Console.WriteLine(stopwatch.ElapsedMilliseconds);
                    return(list2);
                }
            }

            //if (resultPath != null)
            //{
            //    PathDict[startObj] = resultPath;
            //    return resultPath;
            //}
            return(null);
        }
Exemplo n.º 3
0
 public void UpdateTriangleForObj(PhysicObj obj)
 {
     AddNodeToNavMesh(GetNavMesh(obj), obj.getPosNode());
 }