3dphotoshoot
view libs/vmath/ray.cc @ 10:c71c477521ca
converting to GLES2 and C++
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 31 May 2015 00:40:26 +0300 |
parents | |
children |
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "ray.h"
19 #include "vector.h"
21 scalar_t Ray::env_ior = 1.0;
23 Ray::Ray()
24 {
25 ior = env_ior;
26 energy = 1.0;
27 time = 0;
28 iter = 0;
29 }
31 Ray::Ray(const Vector3 &origin, const Vector3 &dir)
32 {
33 this->origin = origin;
34 this->dir = dir;
35 ior = env_ior;
36 energy = 1.0;
37 time = 0;
38 iter = 0;
39 }
41 void Ray::transform(const Matrix4x4 &xform)
42 {
43 Matrix4x4 upper = xform;
44 upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
45 upper[3][3] = 1.0;
47 dir.transform(upper);
48 origin.transform(xform);
49 }
51 Ray Ray::transformed(const Matrix4x4 &xform) const
52 {
53 Ray foo = *this;
54 foo.transform(xform);
55 return foo;
56 }
58 void Ray::enter(scalar_t new_ior)
59 {
60 ior = new_ior;
61 }
63 void Ray::leave()
64 {
65 }
67 scalar_t Ray::calc_ior(bool entering, scalar_t mat_ior) const
68 {
69 scalar_t from_ior = this->ior;
71 if(entering) {
72 return from_ior / mat_ior;
73 }
75 Ray tmp = *this;
76 tmp.leave();
77 return from_ior / tmp.ior;
78 }