예제 #1
0
        /// <summary>
        /// Adds a ray and target to test an intersection. If the target is pickable,
        /// and an intersection exists, the records are added to the query.
        /// </summary>
        /// <param name="ray">Ray to test with</param>
        /// <param name="pickable">Target to test against</param>
        /// <returns>True if an intersection was found, false otherwise.</returns>
        public bool AddPick(Ray ray, IPickable pickable)
        {
            if (pickable == null)
            {
                return(false);
            }

            if (pickable.IsPickable)
            {
                BoundingVolume              bv         = pickable.WorldBounding;
                BoundingIntersectionRecord  bvRecord   = new BoundingIntersectionRecord();
                PrimitiveIntersectionRecord primRecord = new PrimitiveIntersectionRecord();
                if (bv != null)
                {
                    bv.IntersectsWhere(ref ray, out bvRecord);
                }
                else
                {
                    return(false);
                }

                if (bvRecord.IntersectionCount > 0 && _primitivePickingEnabled)
                {
                    primRecord = pickable.IntersectsPrimitivesWhere(ray);

                    if (primRecord.IntersectionCount > 0)
                    {
                        _results.Add(new PickResult(ray, pickable, bvRecord, primRecord));
                        _sorted = false;
                        return(true);
                    }
                }
                else if (bvRecord.IntersectionCount > 0)
                {
                    _results.Add(new PickResult(ray, pickable, bvRecord));
                    _sorted = false;
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Determines if the volume is contained within this bounding volume.
        /// </summary>
        /// <param name="volume">Bounding volume to test</param>
        /// <returns>Containment type</returns>
        public ContainmentType Contains(BoundingVolume volume)
        {
            if (volume == null)
            {
                return(ContainmentType.Outside);
            }

            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                return(Contains(volume as BoundingBox));

            case BoundingType.OBB:
                return(Contains(volume as OrientedBoundingBox));

            case BoundingType.Sphere:
                return(Contains(volume as BoundingSphere));
            }

            return(ContainmentType.Outside);
        }
예제 #3
0
        /// <summary>
        /// Tests if the volume intersects with this bounding volume.
        /// </summary>
        /// <param name="volume">Volume to test</param>
        /// <returns>True if they intersect</returns>
        public bool Intersects(BoundingVolume volume)
        {
            if (volume == null)
            {
                return(false);
            }

            switch (volume.BoundingType)
            {
            case Bounding.BoundingType.AABB:
                return(Intersects(volume as BoundingBox));

            case Bounding.BoundingType.Sphere:
                return(Intersects(volume as BoundingSphere));

            case Bounding.BoundingType.OBB:
                return(Intersects(volume as OrientedBoundingBox));
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Sets the bounding sphere to copy from the source volume or to contain it.
        /// </summary>
        /// <param name="volume">Source volume</param>
        public override void Set(BoundingVolume volume)
        {
            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox bb = volume as BoundingBox;
                m_center = bb.Center;
                m_radius = bb.Extents.Length();
                break;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                m_center = sphere.Center;
                m_radius = sphere.Radius;
                break;

            case BoundingType.OBB:
                //TODO
                break;
            }
        }
예제 #5
0
        /// <summary>
        /// Merges this bounding volume with a second one. The resulting
        /// bounding volume is returned as a new object and will contain the
        /// original volumes completely. The returned value will be of the
        /// same bounding type as the caller.
        /// </summary>
        /// <param name="volume">Volume to merge with</param>
        /// <returns>New volume that contains the original two</returns>
        public override BoundingVolume Merge(BoundingVolume volume)
        {
            if (volume == null)
            {
                return(this.Clone());
            }

            float   radius;
            Vector3 center;

            BoundingSphere result = new BoundingSphere();

            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox box = volume as BoundingBox;
                radius = box.Extents.Length();
                center = box.Center;
                MergeSphere(ref radius, ref center, result);
                break;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                radius = sphere.Radius;
                center = sphere.Center;
                MergeSphere(ref radius, ref center, result);
                break;

            case Bounding.BoundingType.OBB:
                OrientedBoundingBox obb = volume as OrientedBoundingBox;
                MergeOBB(obb, result);
                break;
            }

            return(result);
        }
예제 #6
0
 public override BoundingVolume Merge(BoundingVolume volume)
 {
     throw new System.NotImplementedException();
 }
예제 #7
0
 /// <summary>
 /// Sets this bounding volume to contain the specified volume or to copy from.
 /// </summary>
 /// <param name="volume">Volume to copy from</param>
 public abstract void Set(BoundingVolume volume);
예제 #8
0
 /// <summary>
 /// Merges this bounding volume with a second one. The resulting
 /// bounding volume is returned as a new object and will contain the
 /// original volumes completely. The returned value will be of the
 /// same bounding type as the caller.
 /// </summary>
 /// <param name="volume">Volume to merge with</param>
 /// <returns>New volume that contains the original two</returns>
 public abstract BoundingVolume Merge(BoundingVolume volume);
예제 #9
0
 /// <summary>
 /// Merges this bounding volume with a second one. The resulting bounding
 /// volume is stored locally and will contain the original volumes completely.
 /// </summary>
 /// <param name="volume">Volume to merge with</param>
 public abstract void MergeLocal(BoundingVolume volume);