Example #1
0
        // ----------------------------------------------------------------------------
        // Path Following behaviors



        public Vector3 steerToStayOnPath(float predictionTime, Pathway path)
        {
            // predict our future position
            Vector3 futurePosition = predictFuturePosition(predictionTime);

            // find the point on the path nearest the predicted future position
            //Vector3 tangent;
            //float outside;

            mapReturnStruct tStruct = new mapReturnStruct();

            Vector3 onPath = path.mapPointToPath(futurePosition, tStruct);

            if (tStruct.outside < 0)
            {
                // our predicted future position was in the path,
                // return zero steering.
                return(Vector3.Zero);
            }
            else
            {
                // our predicted future position was outside the path, need to
                // steer towards it.  Use onPath projection of futurePosition
                // as seek target
                annotatePathFollowing(futurePosition, onPath, onPath, tStruct.outside);
                return(steerForSeek(onPath));
            }
        }
Example #2
0
        public Vector3 steerToFollowPath(int direction, float predictionTime, Pathway path)
        {
            // our goal will be offset from our path distance by this amount
            float pathDistanceOffset = direction * predictionTime * speed();

            // predict our future position
            Vector3 futurePosition = predictFuturePosition(predictionTime);

            // measure distance along path of our current and predicted positions
            float nowPathDistance =
                path.mapPointToPathDistance(Position);
            float futurePathDistance =
                path.mapPointToPathDistance(futurePosition);

            // are we facing in the correction direction?
            bool rightway = ((pathDistanceOffset > 0) ?
                             (nowPathDistance < futurePathDistance) :
                             (nowPathDistance > futurePathDistance));

            // find the point on the path nearest the predicted future position
            // XXX need to improve calling sequence, maybe change to return a
            // XXX special path-defined object which includes two Vector3s and a
            // XXX bool (onPath,tangent (ignored), withinPath)
            // Vector3 tangent;
            //float outside;
            mapReturnStruct tStruct = new mapReturnStruct();
            Vector3         onPath  = path.mapPointToPath(futurePosition, tStruct);

            // no steering is required if (a) our future position is inside
            // the path tube and (b) we are facing in the correct direction
            if ((tStruct.outside < 0) && rightway)
            {
                // all is well, return zero steering
                return(Vector3.Zero);
            }
            else
            {
                // otherwise we need to steer towards a target point obtained
                // by adding pathDistanceOffset to our current path position

                float   targetPathDistance = nowPathDistance + pathDistanceOffset;
                Vector3 target             = path.mapPathDistanceToPoint(targetPathDistance);

                annotatePathFollowing(futurePosition, onPath, target, tStruct.outside);

                // return steering to seek target on path
                return(steerForSeek(target));
            }
        }
        // ----------------------------------------------------------------------------
        // Path Following behaviors
        public Vector3 steerToStayOnPath(float predictionTime, Pathway path)
        {
            // predict our future position
             Vector3 futurePosition = predictFuturePosition (predictionTime);

            // find the point on the path nearest the predicted future position
            //Vector3 tangent;
            //float outside;

            mapReturnStruct tStruct = new mapReturnStruct();

            Vector3 onPath = path.mapPointToPath(futurePosition, tStruct);

            if (tStruct.outside < 0)
            {
                // our predicted future position was in the path,
                // return zero steering.
                return Vector3.ZERO;
            }
            else
            {
                // our predicted future position was outside the path, need to
                // steer towards it.  Use onPath projection of futurePosition
                // as seek target
                annotatePathFollowing (futurePosition, onPath, onPath,tStruct.outside);
                return steerForSeek (onPath);
            }
        }
        public Vector3 steerToFollowPath(int direction, float predictionTime, Pathway path)
        {
            // our goal will be offset from our path distance by this amount
             float pathDistanceOffset = direction * predictionTime * speed();

            // predict our future position
             Vector3 futurePosition = predictFuturePosition (predictionTime);

            // measure distance along path of our current and predicted positions
             float nowPathDistance =
                path.mapPointToPathDistance (Position);
             float futurePathDistance =
                path.mapPointToPathDistance (futurePosition);

            // are we facing in the correction direction?
             bool rightway = ((pathDistanceOffset > 0) ?
                                   (nowPathDistance < futurePathDistance) :
                                   (nowPathDistance > futurePathDistance));

            // find the point on the path nearest the predicted future position
            // XXX need to improve calling sequence, maybe change to return a
            // XXX special path-defined object which includes two Vector3s and a
            // XXX bool (onPath,tangent (ignored), withinPath)
               // Vector3 tangent;
            //float outside;
             mapReturnStruct tStruct = new mapReturnStruct();
             Vector3 onPath = path.mapPointToPath(futurePosition, tStruct);

            // no steering is required if (a) our future position is inside
            // the path tube and (b) we are facing in the correct direction
             if ((tStruct.outside < 0) && rightway)
            {
                // all is well, return zero steering
                return Vector3.ZERO;
            }
            else
            {
                // otherwise we need to steer towards a target point obtained
                // by adding pathDistanceOffset to our current path position

                float targetPathDistance = nowPathDistance + pathDistanceOffset;
                Vector3 target = path.mapPathDistanceToPoint (targetPathDistance);

                annotatePathFollowing(futurePosition, onPath, target, tStruct.outside);

                // return steering to seek target on path
                return steerForSeek (target);
            }
        }