public Hit Hit(Ray ray)
{
var oc = ray.origin - center;
float a = Vector3.Dot(ray.direction, ray.direction);
float b = Vector3.Dot(oc, ray.direction);
float c = Vector3.Dot(oc, oc) - radius * radius;
float dis = b * b - a * c;
if (dis > 0)
{
float e = (float)Math.Sqrt(dis);
float t = (-b - e) / a;
if (t > 0.007f)
{
var point = ray.Point(t);
return(new Hit(t, point, (point - center).Unit()));
}
t = (-b + e) / a;
if (t > 0.007f)
{
var point = ray.Point(t);
return(new Hit(t, point, (point - center).Unit()));
}
return(default);