示例#1
0
        // ----------------------------------------------------------------------------
        // avoidance of "close neighbors" -- used only by steerToAvoidNeighbors
        //
        // XXX	Does a hard steer away from any other agent who comes withing a
        // XXX	critical distance.	Ideally this should be replaced with a call
        // XXX	to steerForSeparation.
        public Vector3 steerToAvoidCloseNeighbors(float minSeparationDistance, ArrayList others)
        {
            // for each of the other vehicles...
            Vector3 result = Vector3.zero;

            for (int i = 0; i < others.Count; i++)
            {
                SteeringVehicle other = (SteeringVehicle)others[i];
                if (other != this)
                {
                    float   sumOfRadii        = Radius + other.Radius;
                    float   minCenterToCenter = minSeparationDistance + sumOfRadii;
                    Vector3 offset            = other.Position - Position;
                    float   currentDistance   = offset.magnitude;

                    if (currentDistance < minCenterToCenter)
                    {
                        result = OpenSteerUtility.perpendicularComponent(-offset, Forward);

                                                #if ANNOTATE_AVOIDNEIGHBORS
                        annotateAvoidCloseNeighbor(other, result);
                                                #endif
                    }
                }
            }
            return(result);;
        }
示例#2
0
 // constructor
 public tokenType(SteeringVehicle parentObject, BruteForceProximityDatabase pd)
 {
     // store pointer to our associated database and the object this
     // token represents, and store this token on the database's vector
     bfpd          = pd;
     tParentObject = parentObject;
     bfpd.group.Add(this);
 }
示例#3
0
        public override SteeringVehicle getNearestVehicle(Vector3 position, float radius)
        {
            lqClientProxy   tProxy   = lq.lqFindNearestNeighborWithinRadius(position.x, position.y, position.z, radius, null);
            SteeringVehicle tVehicle = null;

            if (tProxy != null)
            {
                tVehicle = (SteeringVehicle)tProxy.clientObject;
            }
            return(tVehicle);
        }
示例#4
0
        public override SteeringVehicle getNearestVehicle(Vector3 position, float radius)
        {
            lqClientProxy   lqClientProxy = this.lq.lqFindNearestNeighborWithinRadius(position.x, position.y, position.z, radius, null);
            SteeringVehicle result        = null;

            if (lqClientProxy != null)
            {
                result = (SteeringVehicle)lqClientProxy.clientObject;
            }
            return(result);
        }
        public Vector3 steerToAvoidCloseNeighbors(float minSeparationDistance, ArrayList others)
        {
            Vector3 vector = Vector3.get_zero();

            for (int i = 0; i < others.get_Count(); i++)
            {
                SteeringVehicle steeringVehicle = (SteeringVehicle)others.get_Item(i);
                if (steeringVehicle != this)
                {
                    float   num       = base.Radius + steeringVehicle.Radius;
                    float   num2      = minSeparationDistance + num;
                    Vector3 vector2   = steeringVehicle.Position - base.Position;
                    float   magnitude = vector2.get_magnitude();
                    if (magnitude < num2)
                    {
                        vector = OpenSteerUtility.perpendicularComponent(-vector2, base.Forward);
                        this.annotateAvoidCloseNeighbor(steeringVehicle, vector);
                    }
                }
            }
            return(vector);
        }
示例#6
0
 public override AbstractTokenForProximityDatabase allocateToken(SteeringVehicle parentObject)
 {
     return(new LQProximityDatabase.tokenType(parentObject, this));
 }
示例#7
0
 // called when steerToAvoidCloseNeighbors decides steering is required
 // (default action is to do nothing, layered classes can overload it)
 public virtual void annotateAvoidCloseNeighbor(SteeringVehicle otherVehicle, Vector3 component)
 {
     Debug.DrawLine(Position, otherVehicle.Position, Color.red);
     Debug.DrawRay(Position, component * 3, Color.yellow);
 }
示例#8
0
 // allocate a token to represent a given client object in this database
 //public override tokenType allocateToken (Object parentObject)
 public override AbstractTokenForProximityDatabase allocateToken(SteeringVehicle parentObject)
 {
     tokenType tToken=new tokenType (parentObject, this);
     return (AbstractTokenForProximityDatabase)tToken;
 }
示例#9
0
		// called when steerToAvoidCloseNeighbors decides steering is required
		// (default action is to do nothing, layered classes can overload it)
		public virtual void annotateAvoidCloseNeighbor(SteeringVehicle otherVehicle, Vector3 component)
		{
			Debug.DrawLine(Position, otherVehicle.Position, Color.red);
			Debug.DrawRay (Position, component*3, Color.yellow);
		}
示例#10
0
 // constructor
 public tokenType(SteeringVehicle parentObject, BruteForceProximityDatabase pd)
 {
     // store pointer to our associated database and the object this
     // token represents, and store this token on the database's vector
     bfpd = pd;
     tParentObject = parentObject;
     bfpd.group.Add(this);
 }
示例#11
0
 // type for the "tokens" manipulated by this spatial database
 //typedef AbstractTokenForProximityDatabase<ContentType> tokenType;
 // allocate a token to represent a given client object in this database
 public virtual AbstractTokenForProximityDatabase allocateToken(SteeringVehicle parentObject) { return new AbstractTokenForProximityDatabase(); }
示例#12
0
        // XXX 4-23-03: Temporary work around (see comment above)
        //
        // Checks for intersection of the given spherical obstacle with a
        // volume of "likely future vehicle positions": a cylinder along the
        // current path, extending minTimeToCollision seconds along the
        // forward axis from current position.
        //
        // If they intersect, a collision is imminent and this function returns
        // a steering force pointing laterally away from the obstacle's center.
        //
        // Returns a zero vector if the obstacle is outside the cylinder
        //
        // xxx couldn't this be made more compact using localizePosition?
        public override Vector3 steerToAvoid(SteeringVehicle v, float minTimeToCollision)
        {
            // minimum distance to obstacle before avoidance is required
            float minDistanceToCollision = minTimeToCollision * v.Speed;
            float minDistanceToCenter = minDistanceToCollision + radius;

            // contact distance: sum of radii of obstacle and vehicle
             float totalRadius = radius + v.Radius;

            // obstacle center relative to vehicle position
             Vector3 localOffset = center - v.Position;

            // distance along vehicle's forward axis to obstacle's center
             float forwardComponent = Vector3.Dot(localOffset, v.Forward);
             Vector3 forwardOffset = forwardComponent * v.Forward;

            // offset from forward axis to obstacle's center
             Vector3 offForwardOffset = localOffset - forwardOffset;

            // test to see if sphere overlaps with obstacle-free corridor
             bool inCylinder = offForwardOffset.magnitude < totalRadius;
             bool nearby = forwardComponent < minDistanceToCenter;
             bool inFront = forwardComponent > 0;

            // if all three conditions are met, steer away from sphere center
            if (inCylinder && nearby && inFront)
            {
                return offForwardOffset * -1;
            }
            else
            {
                return Vector3.zero;
            }
        }
示例#13
0
		public virtual Vector3 steerToAvoid(SteeringVehicle v, float minTimeToCollision)
		{
			return Vector3.zero;
		}
 public virtual void annotateAvoidCloseNeighbor(SteeringVehicle otherVehicle, Vector3 component)
 {
     Debug.DrawLine(base.Position, otherVehicle.Position, Color.get_red());
     Debug.DrawRay(base.Position, component * 3f, Color.get_yellow());
 }
 public virtual AbstractTokenForProximityDatabase allocateToken(SteeringVehicle parentObject)
 {
     return(new AbstractTokenForProximityDatabase());
 }
示例#16
0
        // allocate a token to represent a given client object in this database
        //public override tokenType allocateToken (Object parentObject)
        public override AbstractTokenForProximityDatabase allocateToken(SteeringVehicle parentObject)
        {
            tokenType tToken = new tokenType(parentObject, this);

            return((AbstractTokenForProximityDatabase)tToken);
        }
示例#17
0
 public virtual Vector3 steerToAvoid(SteeringVehicle v, float minTimeToCollision)
 {
     return(Vector3.zero);
 }
示例#18
0
 public tokenType(SteeringVehicle parentObject, BruteForceProximityDatabase pd)
 {
     this.bfpd          = pd;
     this.tParentObject = parentObject;
     this.bfpd.group.Add(this);
 }