goat3d

view libs/vmath/ray.inl @ 29:3d669155709d

- switched the unix build to use the internal vmath/anim as well - fixed a memory corruption issue which was caused by including the system-wide installed version of the anim.h header file - started the ass2goat assimp->goat3d converter
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Sep 2013 21:53:03 +0300
parents 4deb0b12fe14
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 VMATH_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 VMATH_INLINE Ray reflect_ray(const Ray &inray, const Vector3 &norm)
35 {
36 Ray ray = inray;
37 ray.dir = ray.dir.reflection(norm);
38 return ray;
39 }
41 VMATH_INLINE Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t from_ior, scalar_t to_ior)
42 {
43 Ray ray = inray;
44 ray.dir = ray.dir.refraction(norm, from_ior, to_ior);
46 /* check TIR */
47 if(dot_product(ray.dir, norm) > 0.0) {
48 return reflect_ray(inray, norm);
49 }
50 return ray;
51 }
52 #endif /* __cplusplus */