dbf-halloween2015

view 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 source
1 #include "ray.h"
2 #include "vector.h"
4 scalar_t Ray::env_ior = 1.0;
6 Ray::Ray()
7 {
8 ior = env_ior;
9 energy = 1.0;
10 time = 0;
11 iter = 0;
12 }
14 Ray::Ray(const Vector3 &origin, const Vector3 &dir)
15 {
16 this->origin = origin;
17 this->dir = dir;
18 ior = env_ior;
19 energy = 1.0;
20 time = 0;
21 iter = 0;
22 }
24 #undef CORRECT_RAY_XFORM
26 void Ray::transform(const Matrix4x4 &xform)
27 {
28 #ifndef CORRECT_RAY_XFORM
29 Matrix4x4 upper = xform;
30 upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
31 upper[3][3] = 1.0;
33 dir.transform(upper);
34 origin.transform(xform);
35 #else
36 Vector3 end = (origin + dir).transformed(xform);
37 origin.transform(xform);
38 dir = end - origin;
39 #endif
40 }
42 Ray Ray::transformed(const Matrix4x4 &xform) const
43 {
44 Ray foo = *this;
45 foo.transform(xform);
46 return foo;
47 }
49 void Ray::enter(scalar_t new_ior)
50 {
51 ior = new_ior;
52 }
54 void Ray::leave()
55 {
56 }
58 scalar_t Ray::calc_ior(bool entering, scalar_t mat_ior) const
59 {
60 scalar_t from_ior = this->ior;
62 if(entering) {
63 return from_ior / mat_ior;
64 }
66 Ray tmp = *this;
67 tmp.leave();
68 return from_ior / tmp.ior;
69 }