Example #1
0
        public List <Waypoint> GenerateWaypointsBetweenTwoPoints(Navmesh navmesh, Vector3 startPos, Vector3 endPos)
        {
            List <Waypoint> waypoints = new List <Waypoint>();

            NavmeshQuery query;
            var          status = NavmeshQuery.Create(navmesh, 1024, out query);

            if (!NavUtil.Failed(status))
            {
                org.critterai.Vector3 navStartPointVect;
                org.critterai.Vector3 navEndPointVect;
                var navStartPointStatus = query.GetNearestPoint(1, new org.critterai.Vector3(startPos.x, startPos.y, startPos.z), out navStartPointVect);
                var navEndPointStatus   = query.GetNearestPoint(1, new org.critterai.Vector3(startPos.x, startPos.y, startPos.z), out navEndPointVect);
                if (navStartPointStatus == NavStatus.Sucess && navEndPointStatus == NavStatus.Sucess)
                {
                    NavmeshPoint navStartPoint = new NavmeshPoint(1, new org.critterai.Vector3(startPos.x, startPos.y, startPos.z));
                    NavmeshPoint navEndPoint   = new NavmeshPoint(1, new org.critterai.Vector3(endPos.x, endPos.y, endPos.z));

                    uint[] path = new uint[1024];
                    int    pathCount;
                    status = query.FindPath(navStartPoint, navEndPoint, new NavmeshQueryFilter(), path, out pathCount);
                    if (!NavUtil.Failed(status))
                    {
                        const int MaxStraightPath = 4;
                        int       wpCount;
                        org.critterai.Vector3[] wpPoints = new org.critterai.Vector3[MaxStraightPath];
                        uint[] wpPath = new uint[MaxStraightPath];

                        WaypointFlag[] wpFlags = new WaypointFlag[MaxStraightPath];
                        status = query.GetStraightPath(navStartPoint.point, navEndPoint.point
                                                       , path, 0, pathCount, wpPoints, wpFlags, wpPath
                                                       , out wpCount);
                        if (!NavUtil.Failed(status) && wpCount > 0)
                        {
                            foreach (var wp in wpPoints)
                            {
                                Mogre.Vector3 wayPointPos = new Vector3(wp.x, wp.y, wp.z);
                                waypoints.Add(new Waypoint(wayPointPos, new Vector3()));
                            }
                        }
                    }
                }
            }

            return(waypoints);
        }
Example #2
0
        /// <summary>
        /// Returns the staight path from the start to the end point within the polygon corridor.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method peforms what is often called 'string pulling'.
        /// </para>
        /// <para>
        /// If the provided result buffers are too small for the entire result, they will 
        /// be filled as far as possible from the start point toward the end point.
        /// </para>
        /// <para>
        /// The start point is clamped to the first polygon in the path, and the end point 
        /// is clamped to the last. So the start  and end points should be within or very near the 
        /// first and last polygons respectively.  The pathStart and pathCount parameters can be 
        /// adjusted to restrict the usable portion of the the path to  meet this requirement. 
        /// (See the example below.)
        /// </para>
        /// <para>
        /// The returned polygon references represent the polygon that is entered at the 
        /// associated path point.  The reference associated with the end point will always be 
        /// zero.
        /// </para>
        /// <para>
        /// Example use case for adjusting the straight path during locomotion:
        /// </para>
        /// <para>
        /// Senario: The path consists of polygons A, B, C, D, with the start point in A and 
        /// the end point in D.
        /// </para>
        /// <para>
        /// The first call to the method will return straight waypoints for the entire path:
        /// </para>
        /// <code>
        /// query.GetStraightPath(startPoint, endPoint
        ///     , path
        ///     , 0, 4   // pathStart, pathCount
        ///     , straigthPath, null, null
        ///     , out straightCount);
        /// </code>
        /// <para>
        /// If the agent moves into polygon B and needs to recaclulate its straight path for 
        /// some reason, it can call the method as follows using the original path buffer:
        /// </para>
        /// <code>
        /// query.GetStraightPath(startPoint, endPoint
        ///     , path
        ///     , 1, 3   // pathStart, pathCount  &lt;- Note the changes here.
        ///     , straigthPath, null, null
        ///     , out straightCount);
        /// </code>
        /// </remarks>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <param name="path">
        /// The list of polygon references that represent the path corridor.
        /// </param>
        /// <param name="pathStart">
        /// The index within the path buffer of the polygon that contains the start point.
        /// </param>
        /// <param name="pathCount">
        /// The length of the path within the path buffer. (endPolyIndex - startPolyIndex)
        /// </param>
        /// <param name="resultPoints">
        /// Points describing the straight path. [(point) * straightPathCount].</param>
        /// <param name="resultFlags">
        /// Flags describing each point. [(flags) * striaghtPathCount] (Optional)</param>
        /// <param name="resultRefs">
        /// The reference of the polygon that is being entered at the point position.
        /// [(polyRef) * straightPathCount] (Optional)</param>
        /// <param name="resultCount">The number of points in the straight path.</param>
        /// <returns>The <see cref="NavStatus" /> flags for the query.</returns>
        public NavStatus GetStraightPath(Vector3 start, Vector3 end
            , uint[] path, int pathStart, int pathCount
            , Vector3[] resultPoints, WaypointFlag[] resultFlags, uint[] resultRefs
            , out int resultCount)
        {
            resultCount = 0;

            int maxPath = resultPoints.Length;

            maxPath = (resultFlags == null ? maxPath
                : Math.Min(resultFlags.Length, maxPath));

            maxPath = (resultRefs == null ? maxPath
                : Math.Min(resultRefs.Length, maxPath));

            if (maxPath < 1)
                return (NavStatus.Failure | NavStatus.InvalidParam);

            return NavmeshQueryEx.dtqFindStraightPath(root
                , ref start
                , ref end
                , path
                , pathStart
                , pathCount
                , resultPoints
                , resultFlags
                , resultRefs
                , ref resultCount
                , maxPath);
        }
 public Waypoint(string name, WaypointFlag flag)
 {
     Name = name;
     Flag = flag;
 }