vrshoot
annotate 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 |
rev | line source |
---|---|
nuclear@0 | 1 #include "ray.h" |
nuclear@0 | 2 #include "vector.h" |
nuclear@0 | 3 |
nuclear@0 | 4 scalar_t Ray::env_ior = 1.0; |
nuclear@0 | 5 |
nuclear@0 | 6 Ray::Ray() |
nuclear@0 | 7 { |
nuclear@0 | 8 ior = env_ior; |
nuclear@0 | 9 energy = 1.0; |
nuclear@0 | 10 time = 0; |
nuclear@0 | 11 iter = 0; |
nuclear@0 | 12 } |
nuclear@0 | 13 |
nuclear@0 | 14 Ray::Ray(const Vector3 &origin, const Vector3 &dir) |
nuclear@0 | 15 { |
nuclear@0 | 16 this->origin = origin; |
nuclear@0 | 17 this->dir = dir; |
nuclear@0 | 18 ior = env_ior; |
nuclear@0 | 19 energy = 1.0; |
nuclear@0 | 20 time = 0; |
nuclear@0 | 21 iter = 0; |
nuclear@0 | 22 } |
nuclear@0 | 23 |
nuclear@0 | 24 void Ray::transform(const Matrix4x4 &xform) |
nuclear@0 | 25 { |
nuclear@0 | 26 Matrix4x4 upper = xform; |
nuclear@0 | 27 upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0; |
nuclear@0 | 28 upper[3][3] = 1.0; |
nuclear@0 | 29 |
nuclear@0 | 30 dir.transform(upper); |
nuclear@0 | 31 origin.transform(xform); |
nuclear@0 | 32 } |
nuclear@0 | 33 |
nuclear@0 | 34 Ray Ray::transformed(const Matrix4x4 &xform) const |
nuclear@0 | 35 { |
nuclear@0 | 36 Ray foo = *this; |
nuclear@0 | 37 foo.transform(xform); |
nuclear@0 | 38 return foo; |
nuclear@0 | 39 } |
nuclear@0 | 40 |
nuclear@0 | 41 void Ray::enter(scalar_t new_ior) |
nuclear@0 | 42 { |
nuclear@0 | 43 ior = new_ior; |
nuclear@0 | 44 } |
nuclear@0 | 45 |
nuclear@0 | 46 void Ray::leave() |
nuclear@0 | 47 { |
nuclear@0 | 48 } |
nuclear@0 | 49 |
nuclear@0 | 50 scalar_t Ray::calc_ior(bool entering, scalar_t mat_ior) const |
nuclear@0 | 51 { |
nuclear@0 | 52 scalar_t from_ior = this->ior; |
nuclear@0 | 53 |
nuclear@0 | 54 if(entering) { |
nuclear@0 | 55 return from_ior / mat_ior; |
nuclear@0 | 56 } |
nuclear@0 | 57 |
nuclear@0 | 58 Ray tmp = *this; |
nuclear@0 | 59 tmp.leave(); |
nuclear@0 | 60 return from_ior / tmp.ior; |
nuclear@0 | 61 } |