dbf-halloween2015

view libs/vmath/ray.inl @ 4:4316c0c879e9

fixed RUN script for macosx
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 06:18:18 +0200
parents
children
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
23 static inline ray_t ray_cons(vec3_t origin, vec3_t dir)
24 {
25 ray_t r;
26 r.origin = origin;
27 r.dir = dir;
28 return r;
29 }
31 #ifdef __cplusplus
32 }
34 inline Ray reflect_ray(const Ray &inray, const Vector3 &norm)
35 {
36 Ray ray = inray;
37 ray.iter--;
38 ray.dir = ray.dir.reflection(norm);
39 return ray;
40 }
42 inline Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t mat_ior, bool entering, scalar_t ray_mag)
43 {
44 Ray ray = inray;
45 ray.iter--;
47 scalar_t ior = ray.calc_ior(entering, mat_ior);
49 if(entering) {
50 ray.enter(mat_ior);
51 } else {
52 ray.leave();
53 }
55 if(ray_mag < 0.0) {
56 ray_mag = ray.dir.length();
57 }
58 ray.dir = (ray.dir / ray_mag).refraction(norm, ior) * ray_mag;
60 /* check TIR */
61 if(dot_product(ray.dir, norm) > 0.0) {
62 if(entering) {
63 ray.leave();
64 } else {
65 ray.enter(mat_ior);
66 }
67 }
68 return ray;
69 }
70 #endif /* __cplusplus */