vrshoot

view libs/vmath/ray.cc @ 2:334d17aed7de

visual studio project files
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 18:36:38 +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 void Ray::transform(const Matrix4x4 &xform)
25 {
26 Matrix4x4 upper = xform;
27 upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
28 upper[3][3] = 1.0;
30 dir.transform(upper);
31 origin.transform(xform);
32 }
34 Ray Ray::transformed(const Matrix4x4 &xform) const
35 {
36 Ray foo = *this;
37 foo.transform(xform);
38 return foo;
39 }
41 void Ray::enter(scalar_t new_ior)
42 {
43 ior = new_ior;
44 }
46 void Ray::leave()
47 {
48 }
50 scalar_t Ray::calc_ior(bool entering, scalar_t mat_ior) const
51 {
52 scalar_t from_ior = this->ior;
54 if(entering) {
55 return from_ior / mat_ior;
56 }
58 Ray tmp = *this;
59 tmp.leave();
60 return from_ior / tmp.ior;
61 }