TerrainDisplay.Collision.Intersection.IntersectRaySphere C# (CSharp) Method

IntersectRaySphere() public static method

public static IntersectRaySphere ( System.Vector3 p, System.Vector3 d, BoundingSphere s, float &t, System.Vector3 &q ) : bool
p System.Vector3
d System.Vector3
s BoundingSphere
t float
q System.Vector3
return bool
        public static bool IntersectRaySphere(Vector3 p, Vector3 d, BoundingSphere s, ref float t, ref Vector3 q)
        {
            var vector = p - s.Center;
            var num = Vector3.Dot(vector, d);
            var num2 = Vector3.Dot(vector, vector) - (s.Radius * s.Radius);
            if ((num2 > 0f) && (num > 0f))
            {
                return false;
            }
            var num3 = (num * num) - num2;
            if (num3 < 0f)
            {
                return false;
            }
            t = -num - ((float)Math.Sqrt(num3));
            if (t < 0f)
            {
                t = 0f;
            }
            q = p + (t * d);
            return true;
        }