Example #1
0
        public void AddCircularObstacle(IObject obj)
        {
            BoundingSphere    bs = BoundingSphere.CreateFromBoundingBox(obj.PhysicObject.BoundingBox.Value);
            SphericalObstacle so = new SphericalObstacle(bs.Radius, obj.PhysicObject.Position);

            obstacles.Add(so);
        }
        // xxx experiment cwr 9-6-02
        protected void FindNextIntersectionWithSphere(SphericalObstacle obs, ref PathIntersection intersection)
        {
            // This routine is based on the Paul Bourke's derivation in:
            //   Intersection of a Line and a Sphere (or circle)
            //   http://www.swin.edu.au/astronomy/pbourke/geometry/sphereline/

            float   b, c, d, p, q, s;
            Vector3 lc;

            // initialize pathIntersection object
            intersection.intersect = false;
            intersection.obstacle  = obs;

            // find "local center" (lc) of sphere in boid's coordinate space
            lc = this.LocalizePosition(obs.Center);

            // computer line-sphere intersection parameters
            b = -2 * lc.Z;
            c = lc.X * lc.X + lc.Y * lc.Y + lc.Z * lc.Z -
                (obs.Radius + this.Radius) * (obs.Radius + this.Radius);
            d = (b * b) - (4 * c);

            // when the path does not intersect the sphere
            if (d < 0)
            {
                return;
            }

            // otherwise, the path intersects the sphere in two points with
            // parametric coordinates of "p" and "q".
            // (If "d" is zero the two points are coincident, the path is tangent)
            s = (float)Math.Sqrt(d);
            p = (-b + s) / 2;
            q = (-b - s) / 2;

            // both intersections are behind us, so no potential collisions
            if ((p < 0) && (q < 0))
            {
                return;
            }

            // at least one intersection is in front of us
            intersection.intersect = true;
            intersection.distance  =
                ((p > 0) && (q > 0)) ?
                // both intersections are in front of us, find nearest one
                ((p < q) ? p : q) :
                // otherwise only one intersections is in front, select it
                ((p > 0) ? p : q);
        }
Example #3
0
 public void AddCircularObstacle(IObject obj)
 {
     BoundingSphere bs = BoundingSphere.CreateFromBoundingBox(obj.PhysicObject.BoundingBox.Value);
     SphericalObstacle so = new SphericalObstacle(bs.Radius, obj.PhysicObject.Position);
     obstacles.Add(so);
 }
Example #4
0
 public void AddCircularObstacle(Vector3 center, float radius)
 {
     SphericalObstacle so = new SphericalObstacle(radius, center);
     obstacles.Add(so);
 }
Example #5
0
        public void AddCircularObstacle(Vector3 center, float radius)
        {
            SphericalObstacle so = new SphericalObstacle(radius, center);

            obstacles.Add(so);
        }