3dphotoshoot

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/ray.cc	Sun May 31 00:40:26 2015 +0300
     1.3 @@ -0,0 +1,78 @@
     1.4 +/*
     1.5 +libvmath - a vector math library
     1.6 +Copyright (C) 2004-2015 John Tsiombikas <nuclear@member.fsf.org>
     1.7 +
     1.8 +This program is free software: you can redistribute it and/or modify
     1.9 +it under the terms of the GNU Lesser General Public License as published
    1.10 +by the Free Software Foundation, either version 3 of the License, or
    1.11 +(at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU Lesser General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU Lesser General Public License
    1.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 +*/
    1.21 +#include "ray.h"
    1.22 +#include "vector.h"
    1.23 +
    1.24 +scalar_t Ray::env_ior = 1.0;
    1.25 +
    1.26 +Ray::Ray()
    1.27 +{
    1.28 +	ior = env_ior;
    1.29 +	energy = 1.0;
    1.30 +	time = 0;
    1.31 +	iter = 0;
    1.32 +}
    1.33 +
    1.34 +Ray::Ray(const Vector3 &origin, const Vector3 &dir)
    1.35 +{
    1.36 +	this->origin = origin;
    1.37 +	this->dir = dir;
    1.38 +	ior = env_ior;
    1.39 +	energy = 1.0;
    1.40 +	time = 0;
    1.41 +	iter = 0;
    1.42 +}
    1.43 +
    1.44 +void Ray::transform(const Matrix4x4 &xform)
    1.45 +{
    1.46 +	Matrix4x4 upper = xform;
    1.47 +	upper[0][3] = upper[1][3] = upper[2][3] = upper[3][0] = upper[3][1] = upper[3][2] = 0.0;
    1.48 +	upper[3][3] = 1.0;
    1.49 +
    1.50 +	dir.transform(upper);
    1.51 +	origin.transform(xform);
    1.52 +}
    1.53 +
    1.54 +Ray Ray::transformed(const Matrix4x4 &xform) const
    1.55 +{
    1.56 +	Ray foo = *this;
    1.57 +	foo.transform(xform);
    1.58 +	return foo;
    1.59 +}
    1.60 +
    1.61 +void Ray::enter(scalar_t new_ior)
    1.62 +{
    1.63 +	ior = new_ior;
    1.64 +}
    1.65 +
    1.66 +void Ray::leave()
    1.67 +{
    1.68 +}
    1.69 +
    1.70 +scalar_t Ray::calc_ior(bool entering, scalar_t mat_ior) const
    1.71 +{
    1.72 +	scalar_t from_ior = this->ior;
    1.73 +
    1.74 +	if(entering) {
    1.75 +		return from_ior / mat_ior;
    1.76 +	}
    1.77 +
    1.78 +	Ray tmp = *this;
    1.79 +	tmp.leave();
    1.80 +	return from_ior / tmp.ior;
    1.81 +}