コード例 #1
0
ファイル: PathGenerator.cs プロジェクト: query-wow/CypherCore
        ulong GetPolyByLocation(float[] point, ref float distance)
        {
            // first we check the current path
            // if the current path doesn't contain the current poly,
            // we need to use the expensive navMesh.findNearestPoly
            ulong polyRef = GetPathPolyByPosition(_pathPolyRefs, _polyLength, point, ref distance);

            if (polyRef != 0)
            {
                return(polyRef);
            }

            // we don't have it in our old path
            // try to get it by findNearestPoly()
            // first try with low search box
            float[] extents      = { 3.0f, 5.0f, 3.0f }; // bounds of poly search area
            float[] closestPoint = { 0.0f, 0.0f, 0.0f };
            if (Detour.dtStatusSucceed(_navMeshQuery.findNearestPoly(point, extents, _filter, ref polyRef, ref closestPoint)) && polyRef != 0)
            {
                distance = Detour.dtVdist(closestPoint, point);
                return(polyRef);
            }

            // still nothing ..
            // try with bigger search box
            // Note that the extent should not overlap more than 128 polygons in the navmesh (see dtNavMeshQuery.findNearestPoly)
            extents[1] = 50.0f;
            if (Detour.dtStatusSucceed(_navMeshQuery.findNearestPoly(point, extents, _filter, ref polyRef, ref closestPoint)) && polyRef != 0)
            {
                distance = Detour.dtVdist(closestPoint, point);
                return(polyRef);
            }

            return(0);
        }