istereo

view libs/vmath/ray.inl @ 36:834503dcb486

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