A simple pathtracer program, capable of producing renderings of simple bodies. The program computes global illumination, by intersecting scene objects, such as luminaries and solid bodies, with idealised surface properies.
#ifndef RAYTRACER_VEC3_HPP
#define RAYTRACER_VEC3_HPP
#include <stdlib.h>
#include <math.h>
namespace raytracer
{
class vec3 {
public:
vec3(): x(0.0f), y(0.0f), z(0.0f){}
vec3(const double x, const double y, const double z): x(x), y(y), z(z){}
virtual ~vec3() {}
inline double length() const { return sqrt((x*x)+(y*y)+(z*z)); }
inline vec3 negative() const { return vec3(-x,-y,-z); }
inline vec3 normalize() const { double l= length(); return vec3(x/l, y/l, z/l); }
inline double dot(const vec3& v) const { return (x*v.x)+(y*v.y)+(z*v.z); }
inline vec3 cross(const vec3& v) const { return vec3(y*v.z- z*v.y, z*v.x- x*v.z, x*v.y- y*v.x); }
inline vec3 add(const vec3& v) const { return vec3(x+v.x, y+v.y, z+v.z); }
inline vec3 scale(const double scalar) const { return vec3(scalar*x, scalar*y, scalar*z); }
inline vec3 reflect(const vec3& n) const {
return this->add(n.negative().scale(this->dot(n)*2.0f));
}
double x, y, z;
};
}
#endif