librtl

ray.h

This is the verbatim text of the ray.h include file.
#ifndef ray_h
#define ray_h

#include <jgl/ray.h>

#include "material.h"

class rtl_object;

const jFlt EPS = 0.001;
const jFlt NOHIT = -1;
const jFlt INFINITY = 1000;


class rtl_ray : public jRay
{
public:


    rtl_ray( const jVec3& o, const jNorm3& d,
         rtl_material* _in = &rtl_material::Default,
         jInt _dep = 0 )
            : jRay(o,d), hit(0), in(_in), dep(_dep), sig(Signature++)
        {}


    rtl_ray( const rtl_ray* ray, jFlt t )
            : jRay(), hit(0), in(ray->in),
              dep(ray->depth()+1), sig(Signature++)
        {
            o = ray->o+ray->d*t;
            d = ray->d;
        }


    jFlt trace();


    rtl_object* objectstruck() { return hit; }


    rtl_object* objectstruck() const { return hit; }


    void at( jFlt t ) { o = o+d*t; }


    rtl_ray at( jFlt t ) const { return rtl_ray(o+d*t, d, in); }


    void inside( rtl_material* o ) { in = o; }


    const rtl_material* inside() const { return in; }


    rtl_material* inside() { return in; }


    jUInt depth() const { return dep; }


    jUInt signature() const { return sig; }


    const rtl_flags& flags() const { return f; }


    rtl_flags& flags() { return f; }


    friend ostream& operator<< ( ostream&, const rtl_ray& );


    static void GetDiskSample( jFlt& x, jFlt& y )
        {
            jFlt _x = PoissonDisk[Sample%128][0];
            jFlt _y = PoissonDisk[Sample%128][1];
            x = srct*_x-srst*_y, y = srst*x+srct*_y;
        }


    static void GetDiskSample( jInt i, jFlt& x, jFlt& y )
        {
            jFlt _x = PoissonDisk[i%128][0];
            jFlt _y = PoissonDisk[i%128][1];
            x = srct*_x-srst*_y, y = srst*x+srct*_y;
        }


    static jFlt DiskSampleLength()
        {
            return PoissonDisk[Sample%128][2];
        }


    static jFlt DiskSampleLength( jUInt i )
        {
            return PoissonDisk[i%128][2];
        }


    static jUInt MaxDepth;
    
    static const jULng ShadowTest;
    
protected:

    rtl_ray( const jMat4&, const jNorm3& );
    
    rtl_object* hit;
    
    rtl_material* in;

    jUInt dep;
    jUInt sig;

    rtl_flags f;

    friend class rtl_world;
    friend class rtl_voxel;
    
    static jFlt PoissonDisk[128][3];

    static jFlt srst, srct;
    static jUInt Sample;
    static jUInt Signature;
    
};

#endif

JSP / librtl v0.2 mtigges@cpsc.ucalgary.ca