Ejemplo n.º 1
0
 /*
  * placeNodeInQueue method will look at a node to see if its polygon is free and if so it will add the polygon being held
  *      to a AIPolygonQueue
  * Parameter:	(AIBinaryTreeNode)nodeToPlace is the node that needs its polygon check to see if its free
  * Return:	none
  */
 void placeNodeInQueue(AIBinaryTreeNode nodeToPlace, AIPolygonQueue tempQueue)
 {
     if (nodeToPlace.isFree() == true)
     {
         tempQueue.enqueue(nodeToPlace.getPolygon());
     }
 }
Ejemplo n.º 2
0
    /*
     *	makeNewArray method will maek a new array of Polygons from the old array of Polygon and the new
     *			AIPolygonQueue holding the polygons that were resently split
     *	Parameter:	(int)placeToAddNewPolygons is the place that the old polygon was at before it was split
     *							(AIPolygonQueue)tempQueue is the AIPolygonQueue holding the new polygons
     *	Return:	none
     */
    AIPolygon[] makeNewArray(int placeToAddNewPolygons, AIPolygonQueue tempQueue, float agentRadius, AIPolygon[] arraySomething)
    {
        AIPolygon[] newArray;
        int         placeToAdd;

        if (arraySomething != null)
        {
            newArray   = new AIPolygon[arraySomething.Length + tempQueue.getSize()]; //new arry of polygons
            placeToAdd = 0;
            for (int count = 0; count < arraySomething.Length; count++)              //add polygons from the old array until the position of the polygon that has been split
            {
                if (polygonArray[count] != null)
                {
                    newArray[placeToAdd] = new AIPolygon(arraySomething [count].getVertices(), placeToAdd);
                    placeToAdd++;
                }
            }
            for (int count = tempQueue.getSize() - 1; count >= 0; count--)              //add polygons that is in tempQueue
            {
                newArray [placeToAdd] = new AIPolygon(tempQueue.getPolygonAtIndex(count).getVertices(), placeToAdd);
                placeToAdd++;
            }
            return(newArray);
        }
        newArray   = new AIPolygon[tempQueue.getSize()];
        placeToAdd = 0;
        for (int count = tempQueue.getSize() - 1; count >= 0; count--)           //add polygons that is in tempQueue
        {
            newArray [placeToAdd] = new AIPolygon(getVerties(tempQueue.getPolygonAtIndex(count).getVertices()), placeToAdd);
            placeToAdd++;
        }
        return(newArray);
    }
Ejemplo n.º 3
0
    /*
     * getFreeNodes method will call a postOrder traversal of the tree created to get all the Free Polygons of the tree
     * Parameters: none
     * Return:	none
     */
    public AIPolygonQueue getFreeNodes()
    {
        AIPolygonQueue tempQueue = new AIPolygonQueue();

        postOrderTraversal(rootNode, tempQueue);
        return(tempQueue);
    }
Ejemplo n.º 4
0
 /*
  * postOrderTraversal method will recursivly traverse the Binary Space Partition tree and enqueue any Free polygons
  *      it finds into the AIPolygonQueue in a postOrder order
  * Parameter:	(AIBinaryTreeNode)nodeToCheck is the current node that needs to be checked and then added into the Queue
  * Reurn:	none
  */
 void postOrderTraversal(AIBinaryTreeNode nodeToCheck, AIPolygonQueue tempQueue)
 {
     if (nodeToCheck != null)
     {
         postOrderTraversal(nodeToCheck.leftNode, tempQueue);  //recursive call on the LeftNode child
         postOrderTraversal(nodeToCheck.rightNode, tempQueue); //recursivecall on the RightNode child
         placeNodeInQueue(nodeToCheck, tempQueue);             //check to see if the polygon is free and if so add it to the Queue
     }
 }
Ejemplo n.º 5
0
    /*
     * splitPolygons method will split the polygons that was collected to be split
     * Parameter:	(AIPolygon[]) splitingPolygons is an array containing the polygons that need to be split
     *              (AIObject) objectsToSplitWith is the object that the polygons will be split by
     */
    AIPolygon[] splitPolygons(AIPolygon[] splitingPolygons, AIObjects objectToSplitWith)
    {
        AIPolygon[] tempArray = null;
        for (int count = 0; count < splitingPolygons.Length; count++)
        {
            AIPolygonQueue tempQueue = splitingPolygons [count].splitThisPolygon(objectToSplitWith);
            if (tempQueue != null)
            {
                tempArray = makeNewArray(count, tempQueue, AINavigationMeshAgent.agentDiameter, tempArray);
            }
        }
        int counter = 0;

        if (tempArray == null)
        {
            return(tempArray);
        }
        for (int count = 0; count < tempArray.Length; count++)
        {
            if (tempArray[count] != null)
            {
                counter++;
            }
        }
        AIPolygon[] temp2Array = new AIPolygon[counter];
        for (int count = 0, tempCount = 0; count < tempArray.Length; count++)
        {
            if (tempArray[count] != null)
            {
                temp2Array[tempCount] = new AIPolygon(tempArray[count].getVertices(), tempCount);
                tempCount++;
            }
        }

        return(temp2Array);
    }
Ejemplo n.º 6
0
 /*
  *	AIPolygonHolder is the constructor for this class. It will set up the AIPolygon array, number
  *			of polygons being held, and the mergedQueue to the initial state
  *	Parameter:	(int)numberOfPolygons is the number of polygons that this object will initially hold
  *	Return:	None
  */
 public AIPolygonHolder(int numberOfPolygons)
 {
     polygonArray = new AIPolygon[numberOfPolygons];
     polygonsHeld = 0;
     mergeQueue   = new AIPolygonQueue();
 }
Ejemplo n.º 7
0
 /*
  * AIBinarySpaceTree method is the constructor for this class. It will set up all the variables to their initial state.
  * Parameters:	(GameObject)objectToAdd will be the object that the polygons are going to be split with
  *              (Vector3[,])arrayOfEdgesToAdd  will be the array of edges with no Y coordinate change for objectToAdd
  *              (AIPolygon)polygonToAdd is the starting polygon that will be the in the rootNode of the tree
  *              (AIPolygonQueue)polygonQueueToAdd is the reference to the Queue that the free polygons will be added to
  * Return:	none
  */
 public AIBinarySpaceTree(GameObject objectToAdd, Vector3[,] arrayOfEdgesToAdd, Vector3[] arrayOfEdgeVerticesAdd, AIPolygon polygonToAdd, AIPolygonQueue polygonQueueToAdd)
 {
     rootNode           = new AIBinaryTreeNode(polygonToAdd);
     arrayOfEdges       = arrayOfEdgesToAdd;
     edgeVertices       = getArrayOfEdgeVertices();
     indexForEdges      = 0;
     indexCount         = 0;
     usedEdgesForObject = new bool[arrayOfEdges.Length / 2];
     for (int count = 0; count < usedEdgesForObject.Length; count++)
     {
         usedEdgesForObject [count] = false;
     }
 }