istereo

diff libs/vmath/ray.inl @ 29:fb4c9641059f

added more forgotten files
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 08:31:15 +0300
parents
children ff055bff6a15
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/ray.inl	Thu Sep 08 08:31:15 2011 +0300
     1.3 @@ -0,0 +1,52 @@
     1.4 +#ifdef __cplusplus
     1.5 +extern "C" {
     1.6 +#endif	/* __cplusplus */
     1.7 +
     1.8 +static inline ray_t ray_cons(vec3_t origin, vec3_t dir)
     1.9 +{
    1.10 +	ray_t r;
    1.11 +	r.origin = origin;
    1.12 +	r.dir = dir;
    1.13 +	return r;
    1.14 +}
    1.15 +
    1.16 +#ifdef __cplusplus
    1.17 +}
    1.18 +
    1.19 +inline Ray reflect_ray(const Ray &inray, const Vector3 &norm)
    1.20 +{
    1.21 +	Ray ray = inray;
    1.22 +	ray.iter--;
    1.23 +	ray.dir = ray.dir.reflection(norm);
    1.24 +	return ray;
    1.25 +}
    1.26 +
    1.27 +inline Ray refract_ray(const Ray &inray, const Vector3 &norm, scalar_t mat_ior, bool entering, scalar_t ray_mag)
    1.28 +{
    1.29 +	Ray ray = inray;
    1.30 +	ray.iter--;
    1.31 +
    1.32 +	scalar_t ior = ray.calc_ior(entering, mat_ior);
    1.33 +	
    1.34 +	if(entering) {
    1.35 +		ray.enter(mat_ior);
    1.36 +	} else {
    1.37 +		ray.leave();
    1.38 +	}
    1.39 +
    1.40 +	if(ray_mag < 0.0) {
    1.41 +		ray_mag = ray.dir.length();
    1.42 +	}
    1.43 +	ray.dir = (ray.dir / ray_mag).refraction(norm, ior) * ray_mag;
    1.44 +
    1.45 +	/* check TIR */
    1.46 +	if(dot_product(ray.dir, norm) > 0.0) {
    1.47 +		if(entering) {
    1.48 +			ray.leave();
    1.49 +		} else {
    1.50 +			ray.enter(mat_ior);
    1.51 +		}
    1.52 +	}
    1.53 +	return ray;
    1.54 +}
    1.55 +#endif	/* __cplusplus */