예제 #1
0
        public static TileNode Quantize(Vector3 position, TileGraph tg)
        {
            float    best_dist = 1000f;
            TileNode best_node = null;

            foreach (TileNode tn in tg.Nodes)
            {
                float dist = Mathf.Abs(Vector3.Distance(Localize(tn), position));

                if (dist < best_dist)
                {
                    best_node = tn;
                    best_dist = dist;
                }
            }
            return(best_node);
        }
예제 #2
0
        // A potential shortcut method which only looks at adjacent nodes to some previous node for quantization
        public static TileNode QuantizeWithPreviousNode(Vector3 position, TileGraph tg, TileNode last_node)
        {
            float       best_dist = 1000f;
            TileNode    best_node = null;
            List <Edge> adj_edges = tg.GetAdjacentEdges(last_node) as List <Edge>;

            foreach (Edge adj_edge in adj_edges)
            {
                TileNode other_node = adj_edge.GetNeighbor(last_node);
                float    dist       = Mathf.Abs(Vector3.Distance(Localize(other_node), position));
                if (dist < best_dist)
                {
                    best_node = other_node;
                }
            }
            return(best_node);
        }