Exemple #1
0
 /// <summary>
 /// Creates a new PickResult.
 /// </summary>
 /// <param name="ray">Ray used in the test</param>
 /// <param name="target">Target object</param>
 /// <param name="primIntersection">The primitive intersection record.</param>
 public PickResult(Ray ray, IPickable target, PrimitiveIntersectionRecord primIntersection)
 {
     _ray         = ray;
     _target      = target;
     _boundRecord = null;
     _primRecord  = primIntersection;
 }
Exemple #2
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);
        }