// // ray.h // // The low-level classes used by ray tracing: the ray and isect classes. // #ifndef __RAY_H__ #define __RAY_H__ #include "algebra.h" #include "material.h" class SceneObject; // A ray has a position where the ray starts, and a direction (which should // always be normalized!) class ray { public: ray( const vec3& pp, const vec3& dd ) : p( pp ), d( dd ) {} ray( const ray& other ) : p( other.p ), d( other.d ) {} ~ray() {} ray& operator =( const ray& other ) { p = other.p; d = other.d; return *this; } vec3 at( double t ) const { return p + (t*d); } vec3 getPosition() const { return p; } vec3 getDirection() const { return d; } protected: vec3 p; vec3 d; }; // The description of an intersection point. class isect { public: isect() : obj( NULL ) , t( 0.0 ) , N() , material( NULL ) , previndex( 1.0 ) , nextindex( 1.0 ) {} ~isect() { delete material; } void setObject( SceneObject *o ) { obj = o; } void setT( double tt ) { t = tt; } void setN( const vec3& n ) { N = n; } void setMaterial( Material *m ) { delete material ; material = m; } void setIndices( double pi, double ni ) { previndex = pi; nextindex = ni; } isect& operator =( const isect& other ) { if( this != &other ) { obj = other.obj; t = other.t; N = other.N; if( other.material ) { if( material ) *material = *other.material; else material = new Material(*other.material ); } else { delete material; material = 0; } // material = other.material ? new Material( *(other.material) ) : 0; previndex = other.previndex; nextindex = other.nextindex; } return *this; } public: const SceneObject *obj; double t; vec3 N; Material *material; // if this intersection has its own material // (as opposed to one in its associated object) // as in the case where the material was interpolated double previndex; double nextindex; const Material &getMaterial() const; }; // Store some useful global variables used by the ray tracer. The epsilons // should be set and left alone. The recursion parameters can be fiddled // with to trade off quality versus speed. struct RayGlobals { static double ray_epsilon; static double normal_epsilon; static double recursion_thresh; static int recursion_depth; }; #endif // __RAY_H__