Пример #1
0
    public AIBinaryTreeNode rightNode; //reference to the rightNode child


    /*
     * AIBinaryTreeNode method is the constructor for this class. It will set up all the variables to their initial
     *      state
     * Parameter:	(AIPolygon)polygonToAdd is the polygon that this node will hold
     * Return:	none
     */
    public AIBinaryTreeNode(AIPolygon polygonToAdd)
    {
        polygonBeingHeld = polygonToAdd;
        free             = false;
        leftNode         = null;
        rightNode        = null;
    }
Пример #2
0
    /*
     * enqueue method will place a new node inside the Queue at the front
     * Parameters:	(AIPolygon)polygonToAdd is the polygon that needs to be added
     *                                                                                      to a node to add into the queue
     * Return:	None
     */
    public void enqueue(AIPolygon polygonToAdd)
    {
        AIPolygonNode newNode = new AIPolygonNode(polygonToAdd, front);

        front = newNode;
        size++;
    }
Пример #3
0
    /* addNode adds a node to this list in order according to its fTotalCost value
     * Parameter: (AIPolygon) polygonToAdd is the polygon that will be held by the node
     * (AIAgentAStarSearchNode) parentNodeToAdd is the parent of the node to be added
     * (float) gCostToAdd is the getGFromStartingNode value to be stored in the node to be added
     * Return: none
     */
    public void addNode(AIPolygon polygonToAdd, AIAgentAStarSearchNode parentNodeToAdd, float gCostToAdd)
    {
        AIAgentAStarSearchNode newSearchNode = new AIAgentAStarSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition);

        if (frontOfList == null)
        {
            newSearchNode.setNextNode(frontOfList);
            frontOfList = newSearchNode;
            numberOfNodesHeld++;
            return;
        }
        AIAgentAStarSearchNode tempFront = frontOfList;

        if (tempFront.compareTo(newSearchNode.getTotalCost()) > 0f)
        {
            newSearchNode.setNextNode(tempFront);
            frontOfList = newSearchNode;
            numberOfNodesHeld++;
            return;
        }

        AIAgentAStarSearchNode tempBack = tempFront.getNextNode();

        while (tempBack != null && tempBack.compareTo(newSearchNode.getTotalCost()) < 0f)
        {
            tempFront = tempBack;
            tempBack  = tempFront.getNextNode();
        }
        newSearchNode.setNextNode(tempFront.getNextNode());
        tempFront.setNextNode(newSearchNode);
        numberOfNodesHeld++;
    }
Пример #4
0
    /* updateNode updates the parent of a node and the gFromStartingNodeCost of a node
     * Parameter: (AIAgentAStarSearchNode) nodeToUpdate is the node to be updated
     * (AIAgentAStarSearchNode) newParentNode is the new parent of the node to be updated
     * (float) newCost is the new gFromStartingNodeCost of the node to be updated
     * Return: none
     */
    public void updateNode(AIAgentAStarSearchNode nodeToUpdate, AIAgentAStarSearchNode newParentNode, float newCost)
    {
        AIPolygon temp = nodeToUpdate.getPolygon();

        deleteNodeOfId(nodeToUpdate.getPolygon().getID());
        addNode(temp, newParentNode, newCost);
    }
Пример #5
0
    /*
     *	mergeWithNeighbors will attempt to to merge all the AIPolygons it can from its neighbor list
     *	Parameter:	(AIPolygon)polygonToMerge is the polygon that is going to attempt to merge with
     *											neighbors
     *	return: None
     */
    void mergeWithNeighbors(AIPolygon polygonToMerge)
    {
        if (polygonToMerge != null)
        {
            int[] neighborHolder = polygonToMerge.getNeighbors();              //array hold the indices for the neighbors of polygonToMerge
            for (int count = 0; count < neighborHolder.Length; count++)
            {
                if (polygonArray [neighborHolder [count]] != null)
                {
                    AIPolygon mergedPolygon = polygonArray [polygonToMerge.getID()].mergeRegular(polygonArray [neighborHolder [count]], polygonToMerge.getID()); // this will attempt to merge two polygons and create a new AIPolygon
                    if (mergedPolygon != null)                                                                                                                   //mergedPolygon will be null if the merge was not accepted
                    {
                        if (mergedPolygon.isPolygonConvex() == true)                                                                                             // this will check to see if the new AIPolygon is convex or not
                        {
                            mergeQueue.deleteNodeOfID(neighborHolder [count]);                                                                                   // delete the old polygon from the neighbor list
                            deleteNeighborAtIndex(polygonToMerge.getID());
                            deleteNeighborAtIndex(neighborHolder [count]);
                            polygonArray [polygonToMerge.getID()] = mergedPolygon;          // add new Polygon to the polygonArray

                            polygonArray [neighborHolder [count]] = null;                   // remove the last polygon that was merged
                            checkAndAddNeighborAtIndex(polygonToMerge.getID());             //finds the neighbors of the new Polygon
                            mergeQueue.enqueue(mergedPolygon);                              // adds the new Polygon to the mergedQueue
                            return;
                        }
                    }
                }
            }
        }
    }
Пример #6
0
    /* getNodeOnList returns node from list that contains a specified polygon
     * Parameter: (AIPolygon) polygonToCheck is the polygon being held by the node to be returned
     * Return: (AIAgentAStarSearchNode)
     *														node on list that is holding polygonToCheck
     */
    public AIAgentAStarSearchNode getNodeOnList(AIPolygon polygonToCheck)
    {
        AIAgentAStarSearchNode tempFront = frontOfList;

        if (tempFront == null)
        {
            return(null);
        }
        if (doesIDMatch(polygonToCheck.getID(), tempFront.getPolygon().getID()) == true)
        {
            return(tempFront);
        }
        AIAgentAStarSearchNode tempBack = tempFront.getNextNode();

        while ((tempBack != null) && (tempBack.getNextNode() != null) && (doesIDMatch(polygonToCheck.getID(), tempBack.getPolygon().getID()) == false))
        {
            tempFront = tempBack;
            tempBack  = tempFront.getNextNode();
        }
        if (tempBack == null)
        {
            return(null);
        }
        if (doesIDMatch(polygonToCheck.getID(), tempBack.getPolygon().getID()) == true)
        {
            return(tempBack);
        }
        return(null);
    }
Пример #7
0
    /*
     * doMethodsForSplitting method will call all the methods for splitting the the polygons with an object\
     * Parameter:	(AIObjects) objectToSplitWith is the object that the polygons need to be split by
     *              (ref int) polygonToSplitCount  is the number of polygons that need to be split
     */
    void doMethodsForSplitting(AIObjects objectToSplitWith, ref int polygonToSplitCount)
    {
        int[]       indicesWithObject = markPolygonsThatSplitWithObject(ref polygonToSplitCount, objectToSplitWith);
        AIPolygon[] splitingPolygons  = getPolygonsThatWillBeSplit(indicesWithObject, polygonToSplitCount);
        AIPolygon[] tempArray         = splitPolygons(splitingPolygons, objectToSplitWith);
        if (tempArray == null)
        {
            return;
        }
        AIPolygon[] newArray      = new AIPolygon[tempArray.Length + polygonArray.Length - polygonToSplitCount];
        int         newArrayCount = 0;

        for (int count = 0; count < polygonArray.Length; count++)
        {
            if (indicesWithObject[count] != 1)
            {
                newArray[newArrayCount] = new AIPolygon(polygonArray[count].getVertices(), newArrayCount);
                newArrayCount++;
            }
        }
        for (int count = 0; count < tempArray.Length; count++)
        {
            newArray[newArrayCount] = new AIPolygon(tempArray[count].getVertices(), newArrayCount);
            newArrayCount++;
        }
        setNewArray(newArray);
    }
Пример #8
0
    /* updateNode updates the parent of a node and the gFromStartingNodeCost of a node
     * Parameter:	(AIDynBiDirOpNode) nodeToUpdate is the node to be updated
     *              (AIDynBiDirOpNode) newParentNode is the new parent of the node to be updated
     *              (float) newCost is the new gFromStartingNodeCost of the node to be updated
     * Return: none
     */
    public void updateNode(AIDynBiDirOpNode nodeToUpdate, AIDynBiDirOpNode newParentNode, float newCost)
    {
        AIPolygon temp = nodeToUpdate.getPolygon();

        deleteNodeOfId(nodeToUpdate.getPolygon().getID());
        addNode(temp, newParentNode, newCost);
    }
Пример #9
0
    /*
     * copyAndSrink method will take a a array and take all the polygons that are not null and place them into a new array
     * Parameter:	(AIPolygon[[]) polygonArrayToCopy is the array that needs to be shrunk
     * Return:	none
     */
    public void copyAndSrink(AIPolygon[] polygonArrayToCopy)
    {
        int counter = 0;

        for (int count = 0; count < polygonArrayToCopy.Length; count++)
        {
            if (polygonArray[count] != null)
            {
                counter++;
            }
        }
        AIPolygon[] tempArray = new AIPolygon[counter];

        for (int count = 0, tempCounter = 0; count < polygonArrayToCopy.Length; count++)
        {
            if (polygonArrayToCopy [count] != null)
            {
                tempArray [tempCounter] = new AIPolygon(polygonArrayToCopy [count].getVertices(), tempCounter);
                tempCounter++;
            }
        }
        polygonArray = tempArray;
        checkHasAgent();
        checkHasGoal();
    }
Пример #10
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);
    }
Пример #11
0
    /*
     * addAfter will make a new polygon and add it right after the node being passed in
     * Parameter:	(AIPolygon)polygonToAdd is the polygon for the new node
     *              (AIFringeSearchNode)parentNode is the node that will be the parent of this node
     *              (float)gCostToAdd is the cost to get to this node
     * Return:	none
     */
    public void addAfter(AIPolygon polygonToAdd, AIFringeSearchNode nodeToAddAfter, float gCostToAdd)
    {
        AIFringeSearchNode tempNode = new AIFringeSearchNode(polygonToAdd, nodeToAddAfter, gCostToAdd, goalPosition);

        tempNode.setNextNode(nodeToAddAfter.getNextNode());
        nodeToAddAfter.setNextNode(tempNode);
        numberOfNodesHeld++;
    }
Пример #12
0
    /*
     * enqueue method will place a node in the front of the list
     * Parameter:	(AIPolygon)polygonToAdd is the polygon for the new node
     *              (AIFringeSearchNode)parentNode is the node that will be the parent of this node
     *              (float)gCostToAdd is the cost to get to this node
     * Return:	none
     */
    public void enqueue(AIPolygon polygonToAdd, AIFringeSearchNode parentNode, float gCostToAdd)
    {
        AIFringeSearchNode tempNode = new AIFringeSearchNode(polygonToAdd, parentNode, gCostToAdd, goalPosition);

        tempNode.setNextNode(frontOfList);
        frontOfList = tempNode;
        numberOfNodesHeld++;
    }
Пример #13
0
 /*
  *	setNewArray will take in an array of AIPolygon and the number of polygons added to that array and
  *			make a new array then set polygonArray to the new array
  *	Parameter:	(AIPolygon[])newArray is the array of polygons that needs to be added to a new array
  *							(int)numberOfPolygons is the number of polygons that is being held by the array that
  *									has been passed in
  */
 void setNewArray(AIPolygon[] newArrays)
 {
     AIPolygon[] tempArray = new AIPolygon[newArrays.Length];
     for (int count = 0; count < tempArray.Length; count++)
     {
         tempArray [count] = newArrays [count];
     }
     polygonArray = tempArray;
 }
Пример #14
0
 /* AIAgentAStarSearchNode method is a constructor for this class.
  * Parmeters: (AIPolygon) polygonToAdd is the polygon held by this node
  * (AIAgentAStarSearchNode) parentToAdd is the parent of this node
  * (float) gCostToAdd is the gFromStartingNode value for this node
  * (Vector3) goalPositionToAdd is the goalPosition for this instance
  */
 public AIAgentAStarSearchNode(AIPolygon polygonToAdd, AIAgentAStarSearchNode parentToAdd, float gCostToAdd, Vector3 goalPositionToAdd)
 {
     polygonBeingHeld  = polygonToAdd;
     parentNode        = parentToAdd;
     gFromStartingNode = gCostToAdd;
     nextNode          = null;
     goalPosition      = new Vector3(goalPositionToAdd.x, goalPositionToAdd.y, goalPositionToAdd.z);
     calculateCost(gFromStartingNode, goalPosition);
 }
Пример #15
0
    /* addNode adds a node to this list in order according to its fTotalCost value
     * Parameter: (AIPolygon) polygonToAdd is the polygon that will be held by the node
     * (AIAgentAStarSearchNode) parentNodeToAdd is the parent of the node to be added
     * (float) gCostToAdd is the getGFromStartingNode value to be stored in the node to be added
     * Return: none
     */
    public void addNode(AIPolygon polygonToAdd, AIAgentAStarSearchNode parentNodeToAdd, float gCostToAdd)
    {
        AIAgentAStarSearchNode newSearchNode = new AIAgentAStarSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition);

        inList [polygonToAdd.getID()]       = true;
        indicesArray [polygonToAdd.getID()] = numberOfNodesHeld;
        heap [numberOfNodesHeld]            = newSearchNode;
        shiftUp(numberOfNodesHeld);
        numberOfNodesHeld++;
    }
Пример #16
0
 /*
  * addPolygon will make a new polygon using a Vector3[] called vertices. It will add it to the array polygonArray
  *      and then it will check to see if any new neighbors can be made with this new polygon
  * Parameter:	(Vector3[])vertices is the vertices array that will be given to a new polygon object to be used
  *                  as its vertices
  * Return:	None
  */
 public void addPolygon(Vector3[] vertices)
 {
     Vector3[] temp = new Vector3[vertices.Length];
     for (int count = 0; count < vertices.Length; count++)
     {
         temp [count] = new Vector3(vertices [count].x, vertices [count].y, vertices [count].z); //copy the vertices points into a new Vector3
     }
     polygonArray [polygonsHeld] = new AIPolygon(temp, polygonsHeld);                            //make the new AIPolygon
     checkNeighbors();                                                                           //checks the Neighbors to see if a polygon needs to add this polygon as a neighbor
     polygonsHeld++;
 }
Пример #17
0
    int epsion = 4;     // used for the weight


    /* AIDynamicWeightedSearchNode method is a constructor for this class.
     * Parmeters:	(AIPolygon) polygonToAdd is the polygon held by this node
     *              (AIAgentAStarSearchNode) parentToAdd is the parent of this node
     *              (float) gCostToAdd is the gFromStartingNode value for this node
     *              (Vector3) goalPositionToAdd is the goalPosition for this instance
     *              (flaot)HToAdd is the H value from the starting node
     *              (int) nodesExpandedToAdd is how many nodes were expanded to get to this nod
     */
    public AIDynamicWeightedSearchNode(AIPolygon polygonToAdd, AIDynamicWeightedSearchNode parentToAdd, float gCostToAdd, Vector3 goalPositionToAdd, float HToAdd, int nodesExpandedToAdd)
    {
        polygonBeingHeld  = polygonToAdd;
        parentNode        = parentToAdd;
        gFromStartingNode = gCostToAdd;
        nextNode          = null;
        goalPosition      = new Vector3(goalPositionToAdd.x, goalPositionToAdd.y, goalPositionToAdd.z);
        N = HToAdd / AINavigationMeshAgent.polygonLengthMin;
        nodesExpandedForThis = nodesExpandedToAdd;
        calculateCost(gFromStartingNode, goalPosition);
    }
Пример #18
0
    /*
     * getFinalPathStartingWithNodes method will return a final path array that starts the the node
     *      containing the polygon being sent in
     * Parameter:	(AIPolygon) polygonToStartWith is the polygon that is in the node the caller wants the
     *                  final path array to start with
     * Return:		(AIPolygon[])
     *                  the final path array starting with the node containing the polygon being passed in
     */
    public AIPolygon[] getFinalPathStartingWithNode(AIPolygon polygonToStartWith)
    {
        AIAgentAStarSearchNode tempNode = closedList[polygonToStartWith.getID()];

        if (tempNode == null)
        {
            return(null);
        }
        finalSolutionStart = tempNode;
        return(getFinalPath());
    }
Пример #19
0
 /*
  * getPolygonsThatWillBeSplit method will gather all the polygons that are going to be split
  * Parameter:	(int[]) indicesWithObject is the array of indices that hold the polygons that need to be split
  *              (int) polygonToSplitCount is the number of polygons that are going to be split
  * Return:		(AIPolygon[])
  *                  an array of polygons that will be split
  */
 AIPolygon[] getPolygonsThatWillBeSplit(int[] indicesWithObject, int polygonToSplitCount)
 {
     AIPolygon[] splitingPolygons = new AIPolygon[polygonToSplitCount];
     for (int count = 0, count2 = 0; count < polygonArray.Length; count++)
     {
         if (indicesWithObject[count] == 1)
         {
             splitingPolygons[count2] = polygonArray[count];
             count2++;
         }
     }
     return(splitingPolygons);
 }
Пример #20
0
 /* The method isAllVerticesDifferent checks if all the vertices in the Vector3[] vericesToCheck array are
  * different
  * Parameters: Vector3[] verticesToCheck - array of vertices to be checked
  * Return: bool
  *							true if the vertices are all different, false otherwise
  */
 bool isAllVerticesDifferent(Vector3[] verticesToCheck)
 {
     for (int count1 = 0; count1 < verticesToCheck.Length; count1++)
     {
         for (int count2 = count1 + 1; count2 < verticesToCheck.Length; count2++)
         {
             if (AIPolygon.checkVertices(verticesToCheck [count1], verticesToCheck [count2]) == true)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #21
0
 /*
  * StartSearch method will start the fringe search. It will get the first polygon that the search starts in and then
  *      it will start the search
  * Parameter:	none
  * Return:	none
  */
 public void startSearch()
 {
     fringeList = new AIFringeSearchList(goalPosition);
     for (int count = 0; count < polygonArray.Length; count++)         // looks for the polygon with the agent GameObject inside it
     {
         if (polygonArray [count].getHasAgent() == true)
         {
             fringeList.enqueue(polygonArray [count], null, 0);          //adds the first polygon to the openList
             cache[count]    = fringeList.getNodeOnList(polygonArray[count]);
             startingPolygon = polygonArray[count];
             count           = polygonArray.Length;
         }
     }
     fringeSearch();             //does the AStar search
     printFinalSolution();       //prints the finalSolution for debugging
     addFinalSolutionPolygons(); //adds the finalsolution to the finalsolution array
 }
Пример #22
0
    /*
     * mergeTwoArray method will take two arrays and return a mergedArray of the polygons in them
     * Parameter:	(AIPolygon[])firstArray is the array that holds the polygons
     *              (AIPolygon[])SecondArray is the array that holds the second polygons
     * Return:		(AIPolygon[])
     *                  an array that contains all the polygons from both arrays
     */
    AIPolygon[] mergeTwoArrays(AIPolygon[] firstArray, AIPolygon[] secondArray)
    {
        AIPolygon[] tempArray = new AIPolygon[firstArray.Length + secondArray.Length];
        int         counter   = 0;

        for (int count = 0; count < firstArray.Length; count++)
        {
            tempArray [counter] = new AIPolygon(firstArray [count].getVertices(), counter);
            counter++;
        }
        for (int count = 0; count < secondArray.Length; count++)
        {
            tempArray [counter] = new AIPolygon(secondArray [count].getVertices(), counter);
            counter++;
        }
        return(tempArray);
    }
    /* addNode adds a node to this list in order according to its fTotalCost value
     * Parameter: (AIPolygon) polygonToAdd is the polygon that will be held by the node
     * (AIAgentAStarSearchNode) parentNodeToAdd is the parent of the node to be added
     * (float) gCostToAdd is the getGFromStartingNode value to be stored in the node to be added
     * Return: none
     */
    public void addNode(AIPolygon polygonToAdd, AIDynamicWeightedSearchNode parentNodeToAdd, float gCostToAdd)
    {
        AIDynamicWeightedSearchNode newSearchNode;

        if (numberOfNodesHeld == 0)
        {
            newSearchNode = new AIDynamicWeightedSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition, AIDynamicWeightedSearch.startingH, 1);
        }
        else
        {
            newSearchNode = new AIDynamicWeightedSearchNode(polygonToAdd, parentNodeToAdd, gCostToAdd, goalPosition, AIDynamicWeightedSearch.startingH, (parentNodeToAdd.getDoFN() + 1));
        }
        inList [polygonToAdd.getID()]       = true;
        indicesArray [polygonToAdd.getID()] = numberOfNodesHeld;
        heap [numberOfNodesHeld]            = newSearchNode;
        shiftUp(numberOfNodesHeld);
        numberOfNodesHeld++;
    }
Пример #24
0
    /* The method getArrayOfEdgeVertices constructs an array of edge vertices from the polygons
     * Return: Vector3[]
     *									 array of edge vertices
     */
    Vector3[] getArrayOfEdgeVertices()
    {
        Vector3[] tempArray = new Vector3[arrayOfEdges.Length / 2];
        tempArray[0] = new Vector3(arrayOfEdges[0, 0].x, arrayOfEdges[0, 0].y, arrayOfEdges[0, 0].z);
        tempArray[1] = new Vector3(arrayOfEdges[0, 1].x, arrayOfEdges[0, 1].y, arrayOfEdges[0, 1].z);
        bool flag = true;

        for (int count = 1, position = 2; count < tempArray.Length && position < tempArray.Length; count++)
        {
            for (int count2 = 0; count2 < position && position < tempArray.Length; count2++)
            {
                if (AIPolygon.checkVertices(tempArray [count2], arrayOfEdges [count, 0]) == true)
                {
                    flag = false;
                }
            }
            if (flag == true)
            {
                tempArray [position] = new Vector3(arrayOfEdges [count, 0].x, arrayOfEdges [count, 0].y, arrayOfEdges [count, 0].z);
                position++;
            }
            flag = true;
            for (int count2 = 0; count2 < position && position < tempArray.Length; count2++)
            {
                if (AIPolygon.checkVertices(tempArray [count2], arrayOfEdges [count, 1]) == true)
                {
                    flag = false;
                }
            }
            if (flag == true)
            {
                tempArray [position] = new Vector3(arrayOfEdges [count, 1].x, arrayOfEdges [count, 1].y, arrayOfEdges [count, 1].z);
                position++;
            }
            flag = false;
        }
        return(seperateEdgesIntoVectors(tempArray));
    }
Пример #25
0
    /*
     * loadNavigationMeshFromFile method will load all the data for the navigation mesh from the file
     * Paramters:	none
     * Return:	none
     */
    public void loadNavigationMeshFromFile()
    {
        startTime = Time.realtimeSinceStartup;
        string          filePath       = Application.loadedLevelName + "NavigationMesh.dat";
        Stream          TestFileStream = File.OpenRead(filePath);
        BinaryFormatter deserializer   = new BinaryFormatter();

        positionToStart = 0;
        AIPolygonHolderData dataholder = (AIPolygonHolderData)deserializer.Deserialize(TestFileStream);

        AIPolygon[] polygons = new AIPolygon[dataholder.polygonData.Length];
        for (int count = 0; count < dataholder.polygonData.Length; count++)
        {
            Vector3[] vertices      = new Vector3[dataholder.polygonData [count].vertices.Length / 3];
            int       id            = dataholder.polygonData [count].id;
            int[]     neighbors     = dataholder.polygonData [count].neighbors;
            int       neighborsHeld = dataholder.polygonData [count].neighborCount;
            bool      gotGoal       = dataholder.polygonData [count].gotGoal;
            bool      gotAgent      = dataholder.polygonData [count].gotAgent;
            int       agentID       = dataholder.polygonData[count].agentID;
            for (int count2 = 0; count2 < vertices.Length; count2++)
            {
                vertices [count2] = new Vector3(dataholder.polygonData [count].vertices [count2, 0], dataholder.polygonData [count].vertices [count2, 1], dataholder.polygonData [count].vertices [count2, 2]);
            }
            polygons [count] = new AIPolygon();
            polygons [count].setData(vertices, id, neighborsHeld, neighbors, gotGoal, gotAgent, agentID);
        }
        AINavigationMeshData.initialPolygonCount = getSurfacePolygonCount();
        AINavigationMeshData.obstacleCount       = staticObjects.Length;
        surfacePolygonHolders     = new AIPolygonHolder[1];
        surfacePolygonHolders [0] = new AIPolygonHolder();
        surfacePolygonHolders [0].setAll(polygons, polygons.Length);
        positionToStart = 0;
        AINavigationMeshData.timeTaken         = Time.realtimeSinceStartup - startTime;
        AINavigationMeshData.finalPolygonCount = getSurfacePolygonCount();
        TestFileStream.Close();
        writeNavigationMeshToFile();
    }
Пример #26
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);
    }
Пример #27
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;
     }
 }
Пример #28
0
 /* getNodeOnList returns node from list that contains a specified polygon
  * Parameter: (AIPolygon) polygonToCheck is the polygon being held by the node to be returned
  * Return: (AIAgentAStarSearchNode)
  *														node on list that is holding polygonToCheck
  */
 public AIDynBiDirOpNode getNodeOnList(AIPolygon polygonToCheck)
 {
     return(heap [indicesArray [polygonToCheck.getID()]]);
 }
Пример #29
0
 /* getNodeOnList returns node from list that contains a specified polygon
  * Parameter: (AIPolygon) polygonToCheck is the polygon being held by the node to be returned
  * Return: (AIAgentAStarSearchNode)
  *														node on list that is holding polygonToCheck
  */
 public AIAgentAStarSearchNode getNodeOnList(AIPolygon polygonToCheck)
 {
     return(heap [indicesArray [polygonToCheck.getID()]]);
 }
Пример #30
0
 /* isNodeOnList checks to see if node containing a certain polygon is on the list
  * Parameter: (AIPolygon) polygon whose id will be used to check if a certain node is on list
  * Return: (bool)
  *						true if a node is on the list that contains polygonToCheck
  *						false if no node on the list contains polygonToCheck
  */
 public bool isNodeOnList(AIPolygon polygonToCheck)
 {
     return(inList [polygonToCheck.getID()]);
 }