Ejemplo n.º 1
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="minTimeToCollision"></param>
        /// <returns></returns>
        public override Vector3 CollisionAvoidance(VehicleActor vehicle, float minTimeToCollision)
        {
            // minimum distance to obstacle before avoidance is required
            float minDistanceToCollision = minTimeToCollision * vehicle.Velocity;
            float minDistanceToCenter    = minDistanceToCollision + Radius;

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

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

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

            // 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.Length() < totalRadius;
            bool nearby     = forwardComponent < minDistanceToCenter;
            bool inFront    = forwardComponent > 0;

            // if all three conditions are met, steer away from sphere center
            return(inCylinder && nearby && inFront ? offForwardOffset * -1 : Vector3.Zero);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check if a a specific vehicle has hit an obstacle, and return the point of collision. Returns Vector3.Zero if no collision detected.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <returns></returns>
        public override Vector3 HasCollided(VehicleActor vehicle)
        {
            // contact distance: sum of radii of obstacle and vehicle
            float totalRadius = Radius + vehicle.BoundingSphereRadius;

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

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

            // 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.Length() < totalRadius;

            // if inCylinder, return point of impact, else return zero
            return(inCylinder ? offForwardOffset : Vector3.Zero);
        }
Ejemplo n.º 3
0
 public abstract Vector3 HasCollided(VehicleActor vehicle);
Ejemplo n.º 4
0
 public abstract Vector3 CollisionAvoidance(VehicleActor vehicle, float minTimeToCollision);
Ejemplo n.º 5
0
 /// <summary>
 /// Check if a a specific vehicle has hit this obstacle, and return the point of collision. Returns Vector3.Zero if no collision detected.
 /// </summary>
 /// <param name="vehicle"></param>
 /// <returns></returns>
 public override Vector3 HasCollided(VehicleActor vehicle)
 {
     return(Vector3.Zero);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Checks for intersection of the given cube obstacle with a
 /// volume of "likely future vehicle positions": a cube 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 cube.
 /// </summary>
 /// <param name="vehicle"></param>
 /// <param name="minTimeToCollision"></param>
 /// <returns></returns>
 public override Vector3 CollisionAvoidance(VehicleActor vehicle, float minTimeToCollision)
 {
     return(Vector3.Zero);
 }