dbf-halloween2015
diff libs/vmath/ray.cc @ 1:c3f5c32cb210
barfed all the libraries in the source tree to make porting easier
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 00:36:56 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/vmath/ray.cc Sun Nov 01 00:36:56 2015 +0200 1.3 @@ -0,0 +1,69 @@ 1.4 +#include "ray.h" 1.5 +#include "vector.h" 1.6 + 1.7 +scalar_t Ray::env_ior = 1.0; 1.8 + 1.9 +Ray::Ray() 1.10 +{ 1.11 + ior = env_ior; 1.12 + energy = 1.0; 1.13 + time = 0; 1.14 + iter = 0; 1.15 +} 1.16 + 1.17 +Ray::Ray(const Vector3 &origin, const Vector3 &dir) 1.18 +{ 1.19 + this->origin = origin; 1.20 + this->dir = dir; 1.21 + ior = env_ior; 1.22 + energy = 1.0; 1.23 + time = 0; 1.24 + iter = 0; 1.25 +} 1.26 + 1.27 +#undef CORRECT_RAY_XFORM 1.28 + 1.29 +void Ray::transform(const Matrix4x4 &xform) 1.30 +{ 1.31 +#ifndef CORRECT_RAY_XFORM 1.32 + Matrix4x4 upper = xform; 1.33 + upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0; 1.34 + upper[3][3] = 1.0; 1.35 + 1.36 + dir.transform(upper); 1.37 + origin.transform(xform); 1.38 +#else 1.39 + Vector3 end = (origin + dir).transformed(xform); 1.40 + origin.transform(xform); 1.41 + dir = end - origin; 1.42 +#endif 1.43 +} 1.44 + 1.45 +Ray Ray::transformed(const Matrix4x4 &xform) const 1.46 +{ 1.47 + Ray foo = *this; 1.48 + foo.transform(xform); 1.49 + return foo; 1.50 +} 1.51 + 1.52 +void Ray::enter(scalar_t new_ior) 1.53 +{ 1.54 + ior = new_ior; 1.55 +} 1.56 + 1.57 +void Ray::leave() 1.58 +{ 1.59 +} 1.60 + 1.61 +scalar_t Ray::calc_ior(bool entering, scalar_t mat_ior) const 1.62 +{ 1.63 + scalar_t from_ior = this->ior; 1.64 + 1.65 + if(entering) { 1.66 + return from_ior / mat_ior; 1.67 + } 1.68 + 1.69 + Ray tmp = *this; 1.70 + tmp.leave(); 1.71 + return from_ior / tmp.ior; 1.72 +}