istereo

annotate libs/vmath/ray.inl @ 29:fb4c9641059f

added more forgotten files
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 08:31:15 +0300
parents
children ff055bff6a15
rev   line source
nuclear@29 1 #ifdef __cplusplus
nuclear@29 2 extern "C" {
nuclear@29 3 #endif /* __cplusplus */
nuclear@29 4
nuclear@29 5 static inline ray_t ray_cons(vec3_t origin, vec3_t dir)
nuclear@29 6 {
nuclear@29 7 ray_t r;
nuclear@29 8 r.origin = origin;
nuclear@29 9 r.dir = dir;
nuclear@29 10 return r;
nuclear@29 11 }
nuclear@29 12
nuclear@29 13 #ifdef __cplusplus
nuclear@29 14 }
nuclear@29 15
nuclear@29 16 inline Ray reflect_ray(const Ray &inray, const Vector3 &norm)
nuclear@29 17 {
nuclear@29 18 Ray ray = inray;
nuclear@29 19 ray.iter--;
nuclear@29 20 ray.dir = ray.dir.reflection(norm);
nuclear@29 21 return ray;
nuclear@29 22 }
nuclear@29 23
nuclear@29 24 inline Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t mat_ior, bool entering, scalar_t ray_mag)
nuclear@29 25 {
nuclear@29 26 Ray ray = inray;
nuclear@29 27 ray.iter--;
nuclear@29 28
nuclear@29 29 scalar_t ior = ray.calc_ior(entering, mat_ior);
nuclear@29 30
nuclear@29 31 if(entering) {
nuclear@29 32 ray.enter(mat_ior);
nuclear@29 33 } else {
nuclear@29 34 ray.leave();
nuclear@29 35 }
nuclear@29 36
nuclear@29 37 if(ray_mag < 0.0) {
nuclear@29 38 ray_mag = ray.dir.length();
nuclear@29 39 }
nuclear@29 40 ray.dir = (ray.dir / ray_mag).refraction(norm, ior) * ray_mag;
nuclear@29 41
nuclear@29 42 /* check TIR */
nuclear@29 43 if(dot_product(ray.dir, norm) > 0.0) {
nuclear@29 44 if(entering) {
nuclear@29 45 ray.leave();
nuclear@29 46 } else {
nuclear@29 47 ray.enter(mat_ior);
nuclear@29 48 }
nuclear@29 49 }
nuclear@29 50 return ray;
nuclear@29 51 }
nuclear@29 52 #endif /* __cplusplus */