vrshoot

view libs/vmath/ray.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +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 #ifndef VMATH_RAY_H_
20 #define VMATH_RAY_H_
22 #include "matrix.h"
23 #include "vector.h"
25 typedef struct {
26 vec3_t origin, dir;
27 } ray_t;
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
33 static inline ray_t ray_cons(vec3_t origin, vec3_t dir);
34 ray_t ray_transform(ray_t r, mat4_t m);
36 #ifdef __cplusplus
37 } /* __cplusplus */
39 class Ray {
40 public:
41 /* enviornmental index of refraction, normally 1.0 */
42 static scalar_t env_ior;
44 Vector3 origin, dir;
45 scalar_t energy;
46 int iter;
47 scalar_t ior;
48 long time;
50 Ray();
51 Ray(const Vector3 &origin, const Vector3 &dir);
53 void transform(const Matrix4x4 &xform);
54 Ray transformed(const Matrix4x4 &xform) const;
56 void enter(scalar_t new_ior);
57 void leave();
59 scalar_t calc_ior(bool entering, scalar_t mat_ior = 1.0) const;
60 };
62 inline Ray reflect_ray(const Ray &inray, const Vector3 &norm);
63 inline Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t ior, bool entering, scalar_t ray_mag = -1.0);
64 #endif /* __cplusplus */
66 #include "ray.inl"
68 #endif /* VMATH_RAY_H_ */