Exemplo n.º 1
0
        /// <summary>
        /// Check if polygon reference is valid.
        /// </summary>
        /// <param name="reference">Polygon reference</param>
        /// <returns>True if valid</returns>
        public bool IsValidPolyRef(PolyId reference)
        {
            if (reference == PolyId.Null)
            {
                return(false);
            }

            int salt, polyIndex, tileIndex;

            reference.Decode(polyBits, tileBits, saltBits, out polyIndex, out tileIndex, out salt);

            if (tileIndex >= maxTiles)
            {
                return(false);
            }

            if (tiles[tileIndex].Salt != salt || tiles[tileIndex].Header == null)
            {
                return(false);
            }

            if (polyIndex >= tiles[tileIndex].Header.PolyCount)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Only use this function if it is known that the provided polygon reference is valid.
        /// </summary>
        /// <param name="reference">Polygon reference</param>
        /// <param name="tile">Resulting tile</param>
        /// <param name="poly">Resulting poly</param>
        public void TryGetTileAndPolyByRefUnsafe(PolyId reference, out MeshTile tile, out Poly poly)
        {
            int salt, polyIndex, tileIndex;

            reference.Decode(polyBits, tileBits, saltBits, out polyIndex, out tileIndex, out salt);
            tile = tiles[tileIndex];
            poly = tiles[tileIndex].Polys[polyIndex];
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieve the endpoints of the offmesh connection at the specified polygon
        /// </summary>
        /// <param name="prevRef">The previous polygon reference</param>
        /// <param name="polyRef">The current polygon reference</param>
        /// <param name="startPos">The starting position</param>
        /// <param name="endPos">The ending position</param>
        /// <returns>True if endpoints found, false if not</returns>
        public bool GetOffMeshConnectionPolyEndPoints(PolyId prevRef, PolyId polyRef, ref Vector3 startPos, ref Vector3 endPos)
        {
            int salt = 0, indexTile = 0, indexPoly = 0;

            if (polyRef == PolyId.Null)
            {
                return(false);
            }

            //get current polygon
            polyRef.Decode(polyBits, tileBits, saltBits, out indexPoly, out indexTile, out salt);
            if (indexTile >= maxTiles)
            {
                return(false);
            }
            if (tiles[indexTile].Salt != salt || tiles[indexTile].Header == null)
            {
                return(false);
            }
            MeshTile tile = tiles[indexTile];

            if (indexPoly >= tile.Header.PolyCount)
            {
                return(false);
            }
            Poly poly = tile.Polys[indexPoly];

            if (poly.PolyType != PolygonType.OffMeshConnection)
            {
                return(false);
            }

            int idx0 = 0, idx1 = 1;

            //find the link that points to the first vertex
            for (int i = poly.FirstLink; i != Link.Null; i = tile.Links[i].Next)
            {
                if (tile.Links[i].Edge == 0)
                {
                    if (tile.Links[i].Reference != prevRef)
                    {
                        idx0 = 1;
                        idx1 = 0;
                    }

                    break;
                }
            }

            startPos = tile.Verts[poly.Verts[idx0]];
            endPos   = tile.Verts[poly.Verts[idx1]];

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieve the tile and poly based off of a polygon reference
        /// </summary>
        /// <param name="reference">Polygon reference</param>
        /// <param name="tile">Resulting tile</param>
        /// <param name="poly">Resulting poly</param>
        /// <returns>True if tile and poly successfully retrieved</returns>
        public bool TryGetTileAndPolyByRef(PolyId reference, out MeshTile tile, out Poly poly)
        {
            tile = null;
            poly = null;

            if (reference == PolyId.Null)
            {
                return(false);
            }

            //Get tile and poly indices
            int salt, polyIndex, tileIndex;

            reference.Decode(polyBits, tileBits, saltBits, out polyIndex, out tileIndex, out salt);

            //Make sure indices are valid
            if (tileIndex >= maxTiles)
            {
                return(false);
            }

            if (tiles[tileIndex].Salt != salt || tiles[tileIndex].Header == null)
            {
                return(false);
            }

            if (polyIndex >= tiles[tileIndex].Header.PolyCount)
            {
                return(false);
            }

            //Retrieve tile and poly
            tile = tiles[tileIndex];
            poly = tiles[tileIndex].Polys[polyIndex];
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieve the endpoints of the offmesh connection at the specified polygon
        /// </summary>
        /// <param name="prevRef">The previous polygon reference</param>
        /// <param name="polyRef">The current polygon reference</param>
        /// <param name="startPos">The starting position</param>
        /// <param name="endPos">The ending position</param>
        /// <returns>True if endpoints found, false if not</returns>
        public bool GetOffMeshConnectionPolyEndPoints(PolyId prevRef, PolyId polyRef, ref Vector3 startPos, ref Vector3 endPos)
        {
            int salt = 0, indexTile = 0, indexPoly = 0;

            if (polyRef == PolyId.Null)
                return false;

            //get current polygon
            polyRef.Decode(polyBits, tileBits, saltBits, out indexPoly, out indexTile, out salt);
            if (indexTile >= maxTiles)
                return false;
            if (tiles[indexTile].Salt != salt || tiles[indexTile].Header == null)
                return false;
            MeshTile tile = tiles[indexTile];
            if (indexPoly >= tile.Header.PolyCount)
                return false;
            Poly poly = tile.Polys[indexPoly];

            if (poly.PolyType != PolygonType.OffMeshConnection)
                return false;

            int idx0 = 0, idx1 = 1;

            //find the link that points to the first vertex
            for (int i = poly.FirstLink; i != Link.Null; i = tile.Links[i].Next)
            {
                if (tile.Links[i].Edge == 0)
                {
                    if (tile.Links[i].Reference != prevRef)
                    {
                        idx0 = 1;
                        idx1 = 0;
                    }

                    break;
                }
            }

            startPos = tile.Verts[poly.Verts[idx0]];
            endPos = tile.Verts[poly.Verts[idx1]];

            return true;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Only use this function if it is known that the provided polygon reference is valid.
 /// </summary>
 /// <param name="reference">Polygon reference</param>
 /// <param name="tile">Resulting tile</param>
 /// <param name="poly">Resulting poly</param>
 public void TryGetTileAndPolyByRefUnsafe(PolyId reference, out MeshTile tile, out Poly poly)
 {
     int salt, polyIndex, tileIndex;
     reference.Decode(polyBits, tileBits, saltBits, out polyIndex, out tileIndex, out salt);
     tile = tiles[tileIndex];
     poly = tiles[tileIndex].Polys[polyIndex];
 }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieve the tile and poly based off of a polygon reference
        /// </summary>
        /// <param name="reference">Polygon reference</param>
        /// <param name="tile">Resulting tile</param>
        /// <param name="poly">Resulting poly</param>
        /// <returns>True if tile and poly successfully retrieved</returns>
        public bool TryGetTileAndPolyByRef(PolyId reference, out MeshTile tile, out Poly poly)
        {
            tile = null;
            poly = null;

            if (reference == PolyId.Null)
                return false;

            //Get tile and poly indices
            int salt, polyIndex, tileIndex;
            reference.Decode(polyBits, tileBits, saltBits, out polyIndex, out tileIndex, out salt);

            //Make sure indices are valid
            if (tileIndex >= maxTiles)
                return false;

            if (tiles[tileIndex].Salt != salt || tiles[tileIndex].Header == null)
                return false;

            if (polyIndex >= tiles[tileIndex].Header.PolyCount)
                return false;

            //Retrieve tile and poly
            tile = tiles[tileIndex];
            poly = tiles[tileIndex].Polys[polyIndex];
            return true;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Check if polygon reference is valid.
        /// </summary>
        /// <param name="reference">Polygon reference</param>
        /// <returns>True if valid</returns>
        public bool IsValidPolyRef(PolyId reference)
        {
            if (reference == PolyId.Null)
                return false;

            int salt, polyIndex, tileIndex;
            reference.Decode(polyBits, tileBits, saltBits, out polyIndex, out tileIndex, out salt);

            if (tileIndex >= maxTiles)
                return false;

            if (tiles[tileIndex].Salt != salt || tiles[tileIndex].Header == null)
                return false;

            if (polyIndex >= tiles[tileIndex].Header.PolyCount)
                return false;

            return true;
        }