Ejemplo n.º 1
0
        public override Vector3 mapPointToPath(Vector3 point, ref mapReturnStruct tStruct)
        {
            float   d;
            float   minDistance = float.MaxValue;// FLT_MAX;
            Vector3 onPath      = Vector3.zero;

            // loop over all segments, find the one nearest to the given point
            for (int i = 1; i < pointCount; i++)
            {
                segmentLength = lengths[i];
                segmentNormal = normals[i];
                d             = pointToSegmentDistance(point, points[i - 1], points[i]);
                if (d < minDistance)
                {
                    minDistance     = d;
                    onPath          = chosen;
                    tStruct.tangent = segmentNormal;
                }
            }

            // measure how far original point is outside the Pathway's "tube"
            tStruct.outside = (onPath - point).magnitude - radius;

            // return point on path
            return(onPath);
        }
Ejemplo n.º 2
0
        public bool isInsidePath(Vector3 point)
        {
            mapReturnStruct mapReturnStruct = default(mapReturnStruct);

            this.mapPointToPath(point, ref mapReturnStruct);
            return(mapReturnStruct.outside < 0f);
        }
Ejemplo n.º 3
0
        public float howFarOutsidePath(Vector3 point)
        {
            mapReturnStruct mapReturnStruct = default(mapReturnStruct);

            this.mapPointToPath(point, ref mapReturnStruct);
            return(mapReturnStruct.outside);
        }
Ejemplo n.º 4
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
            mapReturnStruct tStruct = new mapReturnStruct();

            Vector3 onPath = path.mapPointToPath(futurePosition, ref 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
                                #if ANNOTATE_PATH
                annotatePathFollowing(futurePosition, onPath, onPath, tStruct.outside);
                                #endif
                return(steerForSeek(onPath));
            }
        }
Ejemplo n.º 5
0
        // how far outside path tube is the given point?  (negative is inside)
        public float howFarOutsidePath(Vector3 point)
        {
            //float outside;
            //Vector3 tangent;
            mapReturnStruct tStruct = new mapReturnStruct();

            mapPointToPath(point, ref tStruct);
            return(tStruct.outside);
        }
Ejemplo n.º 6
0
        public Vector3 steerToStayOnPath(float predictionTime, Pathway path)
        {
            Vector3         vector          = this.predictFuturePosition(predictionTime);
            mapReturnStruct mapReturnStruct = default(mapReturnStruct);
            Vector3         vector2         = path.mapPointToPath(vector, ref mapReturnStruct);

            if (mapReturnStruct.outside < 0f)
            {
                return(Vector3.get_zero());
            }
            this.annotatePathFollowing(vector, vector2, vector2, mapReturnStruct.outside);
            return(this.steerForSeek(vector2));
        }
        public override Vector3 mapPointToPath(Vector3 point, ref mapReturnStruct tStruct)
        {
            float   num  = 3.40282347E+38f;
            Vector3 zero = Vector3.get_zero();

            for (int i = 1; i < this.pointCount; i++)
            {
                this.segmentLength = this.lengths[i];
                this.segmentNormal = this.normals[i];
                float num2 = this.pointToSegmentDistance(point, this.points[i - 1], this.points[i]);
                if (num2 < num)
                {
                    num             = num2;
                    zero            = this.chosen;
                    tStruct.tangent = this.segmentNormal;
                }
            }
            tStruct.outside = (zero - point).get_magnitude() - this.radius;
            return(zero);
        }
Ejemplo n.º 8
0
 public virtual Vector3 mapPointToPath(Vector3 point, ref mapReturnStruct tStruct)
 {
     return(Vector3.get_zero());
 }
Ejemplo n.º 9
0
        public override Vector3 mapPointToPath(Vector3 point, ref mapReturnStruct tStruct)
        {
            float d;
            float minDistance = float.MaxValue;// FLT_MAX;
            Vector3 onPath=Vector3.zero;

            // loop over all segments, find the one nearest to the given point
            for (int i = 1; i < pointCount; i++)
            {
                segmentLength = lengths[i];
                segmentNormal = normals[i];
                d = pointToSegmentDistance (point, points[i-1], points[i]);
                if (d < minDistance)
                {
                    minDistance = d;
                    onPath = chosen;
                    tStruct.tangent = segmentNormal;
                }
            }

            // measure how far original point is outside the Pathway's "tube"
            tStruct.outside = (onPath - point).magnitude - radius;

            // return point on path
            return onPath;
        }
Ejemplo n.º 10
0
 // Given an arbitrary point ("A"), returns the nearest point ("P") on
 // this path.  Also returns, via output arguments, the path tangent at
 // P and a measure of how far A is outside the Pathway's "tube".  Note
 // that a negative distance indicates A is inside the Pathway.
 public virtual Vector3 mapPointToPath(Vector3 point, ref mapReturnStruct tStruct)
 {
     return Vector3.zero;
 }
Ejemplo n.º 11
0
        // is the given point inside the path tube?
        public bool isInsidePath(Vector3 point)
        {
            //float outside;
            //Vector3 tangent;
            mapReturnStruct tStruct = new mapReturnStruct();

            mapPointToPath(point, ref tStruct);
            return tStruct.outside < 0;
        }
Ejemplo n.º 12
0
    /// <summary>
    /// Should the force be calculated?
    /// </summary>
    /// <returns>
    /// A <see cref="Vector3"/>
    /// </returns>
    protected override Vector3 CalculateForce()
    {
        if (_path == null)
            return Vector3.zero;

        // our goal will be offset from our path distance by this amount
        float pathDistanceOffset = (int)_direction * _predictionTime * Vehicle.Speed;

        // predict our future position
        Vector3 futurePosition = Vehicle.PredictFuturePosition(_predictionTime);

        // measure distance along path of our current and predicted positions
        float nowPathDistance = _path.mapPointToPathDistance (Vehicle.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)
        mapReturnStruct tStruct = new mapReturnStruct ();
        _path.mapPointToPath (futurePosition, ref 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);

            // return steering to seek target on path
            return Vehicle.GetSeekVector(target);
        }
    }
Ejemplo n.º 13
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
			mapReturnStruct tStruct = new mapReturnStruct();

			Vector3 onPath = path.mapPointToPath(futurePosition, ref 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
				#if ANNOTATE_PATH
				annotatePathFollowing (futurePosition, onPath, onPath,tStruct.outside);
				#endif
				return steerForSeek (onPath);
			}
		}
Ejemplo n.º 14
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)
			mapReturnStruct tStruct = new mapReturnStruct();
			Vector3 onPath = path.mapPointToPath(futurePosition, ref 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);

				#if ANNOTATE_PATH
				annotatePathFollowing(futurePosition, onPath, target, tStruct.outside);
				//Debug.DrawLine(Position, path.LastPoint, Color.green);
				#endif

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