istereo

view libs/vmath/ray.h @ 28:c0ae8e668447

added vmath library
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 08:30:42 +0300
parents
children ff055bff6a15
line source
1 #ifndef VMATH_RAY_H_
2 #define VMATH_RAY_H_
4 #include "matrix.h"
5 #include "vector.h"
7 typedef struct {
8 vec3_t origin, dir;
9 } ray_t;
11 #ifdef __cplusplus
12 extern "C" {
13 #endif /* __cplusplus */
15 static inline ray_t ray_cons(vec3_t origin, vec3_t dir);
16 ray_t ray_transform(ray_t r, mat4_t m);
18 #ifdef __cplusplus
19 } /* __cplusplus */
21 #include <stack>
23 class Ray {
24 private:
25 std::stack<scalar_t> ior_stack;
27 public:
28 /* enviornmental index of refraction, normally 1.0 */
29 static scalar_t env_ior;
31 Vector3 origin, dir;
32 scalar_t energy;
33 int iter;
34 scalar_t ior;
35 long time;
37 Ray();
38 Ray(const Vector3 &origin, const Vector3 &dir);
40 void transform(const Matrix4x4 &xform);
41 Ray transformed(const Matrix4x4 &xform) const;
43 void enter(scalar_t new_ior);
44 void leave();
46 scalar_t calc_ior(bool entering, scalar_t mat_ior = 1.0) const;
47 };
49 inline Ray reflect_ray(const Ray &inray, const Vector3 &norm);
50 inline Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t ior, bool entering, scalar_t ray_mag = -1.0);
51 #endif /* __cplusplus */
53 #include "ray.inl"
55 #endif /* VMATH_RAY_H_ */