istereo
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/vmath/ray.h Thu Sep 08 08:30:42 2011 +0300 1.3 @@ -0,0 +1,55 @@ 1.4 +#ifndef VMATH_RAY_H_ 1.5 +#define VMATH_RAY_H_ 1.6 + 1.7 +#include "matrix.h" 1.8 +#include "vector.h" 1.9 + 1.10 +typedef struct { 1.11 + vec3_t origin, dir; 1.12 +} ray_t; 1.13 + 1.14 +#ifdef __cplusplus 1.15 +extern "C" { 1.16 +#endif /* __cplusplus */ 1.17 + 1.18 +static inline ray_t ray_cons(vec3_t origin, vec3_t dir); 1.19 +ray_t ray_transform(ray_t r, mat4_t m); 1.20 + 1.21 +#ifdef __cplusplus 1.22 +} /* __cplusplus */ 1.23 + 1.24 +#include <stack> 1.25 + 1.26 +class Ray { 1.27 +private: 1.28 + std::stack<scalar_t> ior_stack; 1.29 + 1.30 +public: 1.31 + /* enviornmental index of refraction, normally 1.0 */ 1.32 + static scalar_t env_ior; 1.33 + 1.34 + Vector3 origin, dir; 1.35 + scalar_t energy; 1.36 + int iter; 1.37 + scalar_t ior; 1.38 + long time; 1.39 + 1.40 + Ray(); 1.41 + Ray(const Vector3 &origin, const Vector3 &dir); 1.42 + 1.43 + void transform(const Matrix4x4 &xform); 1.44 + Ray transformed(const Matrix4x4 &xform) const; 1.45 + 1.46 + void enter(scalar_t new_ior); 1.47 + void leave(); 1.48 + 1.49 + scalar_t calc_ior(bool entering, scalar_t mat_ior = 1.0) const; 1.50 +}; 1.51 + 1.52 +inline Ray reflect_ray(const Ray &inray, const Vector3 &norm); 1.53 +inline Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t ior, bool entering, scalar_t ray_mag = -1.0); 1.54 +#endif /* __cplusplus */ 1.55 + 1.56 +#include "ray.inl" 1.57 + 1.58 +#endif /* VMATH_RAY_H_ */