src/scene.cc
branchpyrit
changeset 42 fbdeb3e04543
parent 40 929aad02c5f2
child 44 3763b26244f0
equal deleted inserted replaced
41:c1080cb5bd6d 42:fbdeb3e04543
    93 }
    93 }
    94 
    94 
    95 bool Sphere::intersect(const Ray &ray, Float &dist) const
    95 bool Sphere::intersect(const Ray &ray, Float &dist) const
    96 {
    96 {
    97 	Vector3 V = ray.o - center;
    97 	Vector3 V = ray.o - center;
    98 	register Float d = -dot(V, ray.dir);
    98 	register Float d = dot(V, ray.dir);
    99 	register Float Det = d * d - (dot(V,V) - sqr_radius);
    99 	register Float Det = d * d - (dot(V,V) - sqr_radius);
   100 	if (Det > 0) {
   100 	if (Det > 0) {
   101 		d -= sqrtf(Det);
   101 		d = -d - sqrtf(Det);
   102 		if (d > 0 && d < dist)
   102 		if (d > 0 && d < dist)
   103 		{
   103 		{
   104 			dist = d;
   104 			dist = d;
   105 			return true;
   105 			return true;
   106 		}
   106 		}