BEPUphysics.CollisionShapes.ConvexShapes.SphereShape.RayTest C# (CSharp) Метод

RayTest() публичный Метод

Gets the intersection between the sphere and the ray.
public RayTest ( Microsoft.Xna.Framework.Ray &ray, BEPUphysics.MathExtensions.RigidTransform &transform, float maximumLength, RayHit &hit ) : bool
ray Microsoft.Xna.Framework.Ray Ray to test against the sphere.
transform BEPUphysics.MathExtensions.RigidTransform Transform applied to the convex for the test.
maximumLength float Maximum distance to travel in units of the ray direction's length.
hit RayHit Ray hit data, if any.
Результат bool
        public override bool RayTest(ref Ray ray, ref RigidTransform transform, float maximumLength, out RayHit hit)
        {
            return Toolbox.RayCastSphere(ref ray, ref transform.Position, collisionMargin, maximumLength, out hit);
            //Vector3 normalizedDirection;
            //float length = ray.Direction.Length();
            //Vector3.Divide(ref ray.Direction, length, out normalizedDirection);
            //maximumLength *= length;
            //hit = new RayHit();
            //Vector3 m;
            //Vector3.Subtract(ref ray.Position, ref transform.Position, out m);
            //float b = Vector3.Dot(m, normalizedDirection);
            //float c = m.LengthSquared() - collisionMargin * collisionMargin;

            //if (c > 0 && b > 0)
            //    return false;
            //float discriminant = b * b - c;
            //if (discriminant < 0)
            //    return false;

            //hit.T = -b - (float)Math.Sqrt(discriminant);
            //if (hit.T < 0)
            //    hit.T = 0;
            //if (hit.T > maximumLength)
            //    return false;
            //Vector3.Multiply(ref normalizedDirection, hit.T, out hit.Location);
            //Vector3.Add(ref hit.Location, ref ray.Position, out hit.Location);
            //Vector3.Subtract(ref hit.Location, ref transform.Position, out hit.Normal);
            //hit.Normal.Normalize();
            //return true;
        }