erebus
diff liberebus/src/geomobj.cc @ 17:e9da2916bc79
fixed the normal bug
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 26 May 2014 05:41:28 +0300 |
parents | d2b6cee8ea5c |
children | 09028848f276 |
line diff
1.1 --- a/liberebus/src/geomobj.cc Sun May 25 02:23:39 2014 +0300 1.2 +++ b/liberebus/src/geomobj.cc Mon May 26 05:41:28 2014 +0300 1.3 @@ -22,7 +22,7 @@ 1.4 Vector3 GeomObject::calc_normal(const RayHit &hit) const 1.5 { 1.6 // when you look at singularities, the singularities always look back at you :) 1.7 - return -(hit.world_ray.dir).normalized(); 1.8 + return -(hit.local_ray.dir).normalized(); 1.9 } 1.10 1.11 Vector3 GeomObject::calc_tangent(const RayHit &hit) const 1.12 @@ -45,16 +45,16 @@ 1.13 float c = dot_product(ray.origin, ray.origin) - 1.0; 1.14 1.15 float d = b * b - 4.0 * a * c; 1.16 - if(d < 1e-4) return false; 1.17 + if(d < 1e-6) return false; 1.18 1.19 float sqrt_d = sqrt(d); 1.20 float t0 = (-b + sqrt_d) / (2.0 * a); 1.21 float t1 = (-b - sqrt_d) / (2.0 * a); 1.22 1.23 - if(t0 < 1e-4) t0 = t1; 1.24 - if(t1 < 1e-4) t1 = t0; 1.25 + if(t0 < 1e-6) t0 = t1; 1.26 + if(t1 < 1e-6) t1 = t0; 1.27 float t = t0 < t1 ? t0 : t1; 1.28 - if(t < 1e-4) return false; 1.29 + if(t < 1e-6) return false; 1.30 1.31 if(hit) { 1.32 hit->dist = t; 1.33 @@ -66,7 +66,7 @@ 1.34 1.35 Vector3 Sphere::calc_normal(const RayHit &hit) const 1.36 { 1.37 - Vector3 pt = hit.world_ray.origin + hit.world_ray.dir * hit.dist; 1.38 + Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.39 return pt.normalized(); 1.40 } 1.41 1.42 @@ -88,7 +88,7 @@ 1.43 1.44 Vector2 Sphere::calc_texcoords(const RayHit &hit) const 1.45 { 1.46 - Vector3 pt = hit.world_ray.origin + hit.world_ray.dir * hit.dist; 1.47 + Vector3 pt = hit.local_ray.origin + hit.local_ray.dir * hit.dist; 1.48 pt.normalize(); 1.49 1.50 float theta = atan2(pt.z, pt.x);