erebus
diff liberebus/src/geomobj.cc @ 8:e2d9bf168a41
semi-works ...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 24 May 2014 06:12:57 +0300 |
parents | 93894c232d65 |
children | d2b6cee8ea5c |
line diff
1.1 --- a/liberebus/src/geomobj.cc Sat May 24 02:27:08 2014 +0300 1.2 +++ b/liberebus/src/geomobj.cc Sat May 24 06:12:57 2014 +0300 1.3 @@ -18,6 +18,22 @@ 1.4 return false; 1.5 } 1.6 1.7 +Vector3 GeomObject::calc_normal(const RayHit &hit) const 1.8 +{ 1.9 + // when you look at singularities, the singularities always look back at you :) 1.10 + return -(hit.world_ray.dir).normalized(); 1.11 +} 1.12 + 1.13 +Vector3 GeomObject::calc_tangent(const RayHit &hit) const 1.14 +{ 1.15 + return Vector3(1, 0, 0); // whatever... 1.16 +} 1.17 + 1.18 +Vector2 GeomObject::calc_texcoords(const RayHit &hit) const 1.19 +{ 1.20 + return Vector2(); 1.21 +} 1.22 + 1.23 // --- class Sphere --- 1.24 1.25 bool Sphere::intersect(const Ray &ray, RayHit *hit) const 1.26 @@ -47,6 +63,40 @@ 1.27 return true; 1.28 } 1.29 1.30 +Vector3 Sphere::calc_normal(const RayHit &hit) const 1.31 +{ 1.32 + Vector3 pt = hit.world_ray.origin + hit.world_ray.dir * hit.dist; 1.33 + return pt.normalized(); 1.34 +} 1.35 + 1.36 +static inline Vector3 sphvec(float u, float v) 1.37 +{ 1.38 + float theta = u * M_PI * 2.0; 1.39 + float phi = v * M_PI; 1.40 + 1.41 + return Vector3(sin(theta) * sin(phi), cos(phi), cos(theta) * sin(phi)); 1.42 +} 1.43 + 1.44 +Vector3 Sphere::calc_tangent(const RayHit &hit) const 1.45 +{ 1.46 + Vector2 uv = calc_texcoords(hit); 1.47 + Vector3 pnext = sphvec(uv.x + 0.05, 0.5); 1.48 + Vector3 pprev = sphvec(uv.y - 0.05, 0.5); 1.49 + return (pnext - pprev).normalized(); 1.50 +} 1.51 + 1.52 +Vector2 Sphere::calc_texcoords(const RayHit &hit) const 1.53 +{ 1.54 + Vector3 pt = hit.world_ray.origin + hit.world_ray.dir * hit.dist; 1.55 + pt.normalize(); 1.56 + 1.57 + float theta = atan2(pt.z, pt.x); 1.58 + float phi = acos(pt.y); 1.59 + 1.60 + return Vector2(theta / M_PI + 0.5, phi / M_PI); 1.61 +} 1.62 + 1.63 + 1.64 // --- class Box --- 1.65 1.66 bool Box::intersect(const Ray &ray, RayHit *hit) const