Пример #1
0
        /// <summary>
        /// Test a ray (in model space) for intersection with individual bones.
        /// </summary>
        /// <param name="ray"></param>
        /// <returns></returns>
        public IEnumerable<KeyValuePair<string, float>> Intersections(Ray3 ray)
        {
            return _model
                .Model
                .SkinningData
                .Bounds
                .Select((b, i) =>
                {
                    Matrix4x4 transform;
                    Matrix4x4.Invert(_worldTransforms[i], out transform);

                    var start = Vector3.Transform(ray.Position, transform);             //Transform ray into bone space
                    var direction = Vector3.TransformNormal(ray.Direction, transform);

                    float? depth = b.Intersects(new Ray3(start, direction));             //Intersect new ray in bone space
                    var name = _model.Model.SkinningData.Names[i];

                    return new KeyValuePair<string, float?>(name, depth);

                })
                .Where(a => a.Value.HasValue)                                           //Only pass values which intersect
            // ReSharper disable PossibleInvalidOperationException
                .Select(a => new KeyValuePair<string, float>(a.Key, a.Value.Value))     //Select float (now we know it's not null)
            // ReSharper restore PossibleInvalidOperationException
                .OrderBy(a => a.Value)                                                  //Order by distance along ray
                .ToArray();
        }
Пример #2
0
        public void AssertThat_RayAlmostStartingOnPlane_Intersects_WithPositivePlaneDistance()
        {
            Plane p = new Plane(new Vector3(0, 1, 0), 5);
            Ray3 r = new Ray3(new Vector3(0, -4.999999f, 0), new Vector3(0, 1, 0));

            var i = r.Intersects(p);

            Assert.AreEqual(0, i);
        }
Пример #3
0
        public void AssertThat_DownwardRayIntersectsPlane_ReturnsCorrectValue_WithPositivePlaneDistance()
        {
            Plane p = new Plane(new Vector3(0, 1, 0), 5);
            Ray3 r = new Ray3(new Vector3(0, 10, 0), new Vector3(0, -1, 0));

            var i = r.Intersects(p);

            Assert.AreEqual(15, i);
        }
Пример #4
0
        public void AssertThat_ParallelRayDoesNotIntersect_WithPositivePlaneDistance()
        {
            Plane p = new Plane(new Vector3(0, 1, 0), 5);
            Ray3 r = new Ray3(new Vector3(0, 10, 0), new Vector3(1, 0, 0));

            var i = r.Intersects(p);

            Assert.IsNull(i);
        }
Пример #5
0
 /// <summary>
 /// Checks whether the current BoundingBox intersects a Ray.
 /// </summary>
 /// <param name="ray">The Ray to check for intersection with.</param><param name="result">[OutAttribute] Distance at which the ray intersects the BoundingBox, or null if there is no intersection.</param>
 public void Intersects(ref Ray3 ray, out float? result)
 {
     result = ray.Intersects(this);
 }
Пример #6
0
 public float? Intersects(Ray3 ray)
 {
     float? result;
     Intersects(ref ray, out result);
     return result;
 }
Пример #7
0
 /// <summary>
 /// Checks whether the current BoundingSphere intersects a Ray.
 /// </summary>
 /// <param name="ray">The Ray to check for intersection with.</param><param name="result">[OutAttribute] Distance at which the ray intersects the BoundingSphere or null if there is no intersection.</param>
 public void Intersects(ref Ray3 ray, out float?result)
 {
     ray.Intersects(ref this, out result);
 }
Пример #8
0
 /// <summary>
 /// Checks whether the current BoundingSphere intersects with a specified Ray.
 /// </summary>
 /// <param name="ray">The Ray to check for intersection with the current BoundingSphere.</param>
 public float?Intersects(Ray3 ray)
 {
     return(ray.Intersects(this));
 }
Пример #9
0
 /// <summary>
 /// Determines whether the specified Ray is equal to the current Ray.
 /// </summary>
 /// <param name="other">The Ray to compare with the current Ray.</param>
 public bool Equals(Ray3 other)
 {
     return(Position.Equals(other.Position) && Direction.Equals(other.Direction));
 }
Пример #10
0
 /// <summary>
 /// Checks whether the current BoundingBox intersects a Ray.
 /// </summary>
 /// <param name="ray">The Ray to check for intersection with.</param><param name="result">[OutAttribute] Distance at which the ray intersects the BoundingBox, or null if there is no intersection.</param>
 public void Intersects(ref Ray3 ray, out float?result)
 {
     result = ray.Intersects(this);
 }
Пример #11
0
 public float?Intersects(Ray3 ray)
 {
     Intersects(ref ray, out var result);
     return(result);
 }
Пример #12
0
        public void AssertThat_RayClosestPoint_IsOnLine()
        {
            var ray = new Ray3(new Vector3(0, 1, 0), new Vector3(0, 10, 0));
            var point = new Vector3(5, 5, 5);

            var closest = ray.ClosestPoint(point);
            Assert.AreEqual(new Vector3(0, 5, 0), closest);
        }
Пример #13
0
 /// <summary>
 /// Determines whether the specified Ray is equal to the current Ray.
 /// </summary>
 /// <param name="other">The Ray to compare with the current Ray.</param>
 public bool Equals(Ray3 other)
 {
     return Position.Equals(other.Position) && Direction.Equals(other.Direction);
 }
Пример #14
0
        public void AssertThat_UpwardRayIntersectsPlane_ReturnsCorrectValue()
        {
            Plane p = new Plane(new Vector3(0, 1, 0), 0);
            Ray3 r = new Ray3(new Vector3(0, -10, 0), new Vector3(0, 1, 0));

            var i = r.Intersects(p);

            Assert.AreEqual(10, i);
        }
Пример #15
0
        public void AssertThat_RayStartingOnPlane_Intersects_WithNegativePlaneDistance()
        {
            Plane p = new Plane(new Vector3(0, 1, 0), -5);
            Ray3 r = new Ray3(new Vector3(0, 5, 0), new Vector3(0, -1, 0));

            var i = r.Intersects(p);

            Assert.AreEqual(0, i);
        }
Пример #16
0
        public void AssertThat_RayPointingAwayDoesNotIntersect_WithNegativePlaneDistance()
        {
            Plane p = new Plane(new Vector3(0, 1, 0), -5);
            Ray3 r = new Ray3(new Vector3(0, -10, 0), new Vector3(0, -1, 0));

            var i = r.Intersects(p);

            Assert.IsNull(i);
        }
 /// <summary>
 /// Checks whether the current BoundingSphere intersects a Ray.
 /// </summary>
 /// <param name="ray">The Ray to check for intersection with.</param><param name="result">[OutAttribute] Distance at which the ray intersects the BoundingSphere or null if there is no intersection.</param>
 public void Intersects(ref Ray3 ray, out float? result)
 {
     ray.Intersects(ref this, out result);
 }
 /// <summary>
 /// Checks whether the current BoundingSphere intersects with a specified Ray.
 /// </summary>
 /// <param name="ray">The Ray to check for intersection with the current BoundingSphere.</param>
 public float? Intersects(Ray3 ray)
 {
     return ray.Intersects(this);
 }