Esempio n. 1
0
 public OperatorTree(OTNode node)
 {
     this.node = node;
       this.right = null;
       this.left = null;
       this.depth = 1;
       this.parent = null;
       this.size = 1;
 }
Esempio n. 2
0
    /*
     *  Function: Octree
     *  constructor
     */
    public Octree(Bounds rootBounds, Vector3 volMin)
    {
        rootNode        = new OTNode(rootBounds);
        rootNode.octant = Octant.ROOT;

        minVol     = volMin;
        freeLeaves = new List <OTNode>();
        fullLeaves = new List <OTNode>();
        treeDepth  = 0;
    }
Esempio n. 3
0
 /*
  *  Function: GetLocationInClosedList
  *  gets the location of node on the closed list
  *
  *  Parameters:
  *      node - current node being inspected by A*
  *
  *  Returns:
  *      the index of the location of node on the closed list
  */
 float GetLocationInClosedList(OTNode node)
 {
     for (int i = 0; i < closed.Count; i++)
     {
         if (closed[i].node.Equals(node))
         {
             return(i);
         }
     }
     return(-1);
 }
Esempio n. 4
0
    /*
     *  Function: GetLocationInOpenList
     *  gets the location of node on the open list
     *
     *  Parameters:
     *      node - current node being inspected by A*
     *
     *  Returns:
     *      the index of the location of node on the open list
     */
    float GetLocationInOpenList(OTNode node)
    {
        for (int i = 0; i < open.Count; i++)
        {
            if (open[i].node.Equals(node))
            {
                return(i);
            }
        }

        return(-1);
    }
Esempio n. 5
0
 /*
  *  Function: Build
  *  1st part of the recursive algorithm:
  *  If node contains geometry then pass node to BuildNewNodes( ); otherwise, the node is marked as free
  *
  *  Parameters:
  *      node - node to build from
  */
 private void Build(OTNode node)
 {
     if (ContainsGeometry(node.otbounds))
     {
         BuildNewNodes(node);
     }
     else
     {
         //this node is free
         node.free = true;
         freeLeaves.Add(node);
     }
 }
Esempio n. 6
0
 /*
  *  Function: FindNeighbors
  *  2nd part of neighbors recursive search algorithm:
  *
  *  recursively checks for neighbors
  *
  *  Parameters:
  *      node - first node to compare against
  *      target - second node to compare the first node to
  */
 private void FindNeighbors(OTNode node, OTNode target)
 {
     if (target.otchildren.Count != 0)
     {
         foreach (OTNode targetChild in target.otchildren)
         {
             if (AreNeighbors(node.otbounds, targetChild.otbounds))
             {
                 node.otneighbors.Add(targetChild);
             }
             FindNeighbors(node, targetChild);
         }
     }
 }
Esempio n. 7
0
    /*
     *  Function: BeginSearchForNeighbors
     *  1st part of neighbors recursive search algorithm:
     *
     *  Begin search on an unsearched node
     *
     *  Parameters:
     *      node - node to search for neighbors
     */
    private void BeginSearchForNeighbors(OTNode node)
    {
        if (node.depth >= treeDepth)
        {
            return;
        }

        if (node.otchildren.Count != 0)
        {
            foreach (OTNode child in node.otchildren)
            {
                FindNeighbors(child, rootNode);
                BeginSearchForNeighbors(child);
            }
        }
    }
Esempio n. 8
0
    /*
     *  Function: HasPath
     *  Generates a path from the agent to the target via an A* search on the target
     *
     *  Returns:
     *      true if there is a path; false if there is no path
     */
    private bool HasPath()
    {
        if (path.Count > 0 && path[path.Count - 1].Contains(target.position))
        {
            return(true);
        }

        //generate new path to target
        //get the desired octree in scene
        GameObject[] octreeGOs = GameObject.FindGameObjectsWithTag("Octree");
        foreach (GameObject tree in octreeGOs)
        {
            if (tree.name.Equals(octreeName))
            {
                octree = tree.GetComponent <OctreeSetup>().octree;
                break;
            }
        }

        if (octree == null)
        {
            Debug.LogError("Octree does not exist");
            return(false);
        }

        //get start and goal nodes
        OTNode goalNode  = octree.TransformToNode(target.position);
        OTNode startNode = octree.TransformToNode(Agent.transform.position);

        astar.SetStart(startNode);
        astar.SetGoal(goalNode);

        //see if there is a path between start and goal
        if (astar.AStarSearch())
        {
            path = astar.GetPath();
            Debug.Log("Path has been generated!");
            Debug.Log("Path length: " + path.Count);
            return(true);
        }

        Debug.Log("NO PATH GENERATED!!!");
        path.Clear();
        return(false);
    }
Esempio n. 9
0
    /*
     *  Function: TransformToNode
     *  gets the leaf node that contains the point
     *
     *  Parameters:
     *      point - point to transform
     *
     *  Returns:
     *      leaf node that contains the point
     *
     */
    public OTNode TransformToNode(Vector3 point)
    {
        OTNode temp = rootNode;

        while (temp.otchildren.Count != 0)
        {
            foreach (OTNode child in temp.otchildren)
            {
                if (child.otbounds.Contains(point))
                {
                    temp = child;
                    break;
                }
            }
        }

        return(temp);
    }
Esempio n. 10
0
 public OperatorTree(OperatorTree tree)
 {
     if (tree.Node != null)
     this.node = tree.node.Clone();
       else
     this.node = null;
       if (tree.Right != null)
       {
     this.right = tree.right.Clone();
     this.right.parent = this;
       }
       else
     this.right = null;
       if (tree.Left != null)
       {
     this.left = tree.left.Clone();
     this.left.parent = this;
       }
       else
     this.left = null;
       this.parent = null;
       this.depth = tree.depth;
       this.size = tree.size;
 }
Esempio n. 11
0
 public OperatorTree(OTNode node)
 {
     this.node = node;
       this.right = null;
       this.left = null;
 }
Esempio n. 12
0
    /*
     *  Function: BuildNewNodes
     *  2nd part of the recursive algorithm:
     *  If the volume of node's children is allowed, then create node's children
     *  otherwise, node is a leaf containing geometry
     *
     *  Parameters:
     *      node - node to build from
     */
    private void BuildNewNodes(OTNode node)
    {
        Vector3 newsize = new Vector3(node.otbounds.size.x / 2.0f, node.otbounds.size.y / 2.0f, node.otbounds.size.z / 2.0f);

        if (VolumeAllowed(newsize))
        {
            int curDepth = node.depth + 1;      //the current depth
            if (curDepth > treeDepth)
            {
                treeDepth = curDepth;
            }

            OTNode new000 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x - node.otbounds.size.x / 4.0f), (node.otbounds.center.y - node.otbounds.size.y / 4.0f), (node.otbounds.center.z + node.otbounds.size.z / 4.0f)), newsize));
            new000.octant = Octant.OCT000;
            node.otchildren.Add(new000);
            new000.otparent = node;
            new000.depth    = curDepth;
            Build(new000);

            OTNode new010 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x + node.otbounds.size.x / 4.0f), (node.otbounds.center.y - node.otbounds.size.y / 4.0f), (node.otbounds.center.z + node.otbounds.size.z / 4.0f)), newsize));
            new010.octant = Octant.OCT010;
            node.otchildren.Add(new010);
            new010.otparent = node;
            new010.depth    = curDepth;
            Build(new010);

            OTNode new001 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x - node.otbounds.size.x / 4.0f), (node.otbounds.center.y + node.otbounds.size.y / 4.0f), (node.otbounds.center.z + node.otbounds.size.z / 4.0f)), newsize));
            new001.octant = Octant.OCT001;
            node.otchildren.Add(new001);
            new001.otparent = node;
            new001.depth    = curDepth;
            Build(new001);

            OTNode new011 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x + node.otbounds.size.x / 4.0f), (node.otbounds.center.y + node.otbounds.size.y / 4.0f), (node.otbounds.center.z + node.otbounds.size.z / 4.0f)), newsize));
            new011.octant = Octant.OCT011;
            node.otchildren.Add(new011);
            new011.otparent = node;
            new011.depth    = curDepth;
            Build(new011);

            OTNode new100 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x - node.otbounds.size.x / 4.0f), (node.otbounds.center.y - node.otbounds.size.y / 4.0f), (node.otbounds.center.z - node.otbounds.size.z / 4.0f)), newsize));
            new100.octant = Octant.OCT100;
            node.otchildren.Add(new100);
            new100.otparent = node;
            new100.depth    = curDepth;
            Build(new100);

            OTNode new110 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x + node.otbounds.size.x / 4.0f), (node.otbounds.center.y - node.otbounds.size.y / 4.0f), (node.otbounds.center.z - node.otbounds.size.z / 4.0f)), newsize));
            new110.octant = Octant.OCT110;
            node.otchildren.Add(new110);
            new110.otparent = node;
            new110.depth    = curDepth;
            Build(new110);

            OTNode new101 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x - node.otbounds.size.x / 4.0f), (node.otbounds.center.y + node.otbounds.size.y / 4.0f), (node.otbounds.center.z - node.otbounds.size.z / 4.0f)), newsize));
            new101.octant = Octant.OCT101;
            node.otchildren.Add(new101);
            new101.otparent = node;
            new101.depth    = curDepth;
            Build(new101);

            OTNode new111 = new OTNode(new Bounds(new Vector3((node.otbounds.center.x + node.otbounds.size.x / 4.0f), (node.otbounds.center.y + node.otbounds.size.y / 4.0f), (node.otbounds.center.z - node.otbounds.size.z / 4.0f)), newsize));
            new111.octant = Octant.OCT111;
            node.otchildren.Add(new111);
            new111.otparent = node;
            new111.depth    = curDepth;
            Build(new111);
        }
        else
        {
            //this node is full
            fullLeaves.Add(node);
        }
    }
Esempio n. 13
0
 /*
  *  Function: SetGoal
  *  Sets the goal node
  *
  *  Parameters:
  *      goal - the goal node
  */
 public void SetGoal(OTNode goal)
 {
     this.goal = goal;
 }
Esempio n. 14
0
 /*
  *  Function: SetStart
  *  Sets the start node
  *
  *  Parameters:
  *      start - the start node
  */
 public void SetStart(OTNode start)
 {
     this.start = start;
 }