librtl

surfaces.h

This is the verbatim text of the surfaces.h include file.

#ifndef surfaces_h
#define surfaces_h

#include "plane.h"
#include "csg.h"


class rtl_floor : public rtl_plane
{
public:

    rtl_floor();
    

    Type type() const { return objFloor; }

protected:

    jFlt lclintersect( const rtl_ray& ray )
        {
            jFlt t = rtl_plane::lclintersect(ray);
            if(t>EPS)
            {
                jVec3 v = ray.intersection(t);
                if(v[0]>1 || v[0]<-1 || v[2]>1 || v[2]<-1) t = -1;
            }
            return t;
        }

    jVec2 uv( const jVec3& p )
    {
        return jVec2((p[0]+1.0)/2.0, (p[2]+1.0)/2.0);
    }
    
};



class rtl_cylinder : public rtl_intersection
{
public:
    rtl_cylinder();

    Type type() const { return objCylinder; }

protected:
    jVec2 uv( const jVec3& p )
        {
            jFlt d = sqrt(p[0]*p[0]+p[2]*p[2]);
            jFlt v = 1.0-(p[1]+1.0)/2.0;
            jFlt u = p[0]<0 ? asin(fltabs(p[2])/d) : pi-asin(fltabs(p[2])/d);
            if(p[2] > 0) u = pi2-u;
            return jVec2(1.0-u/pi2,v);
        }
    void setMaterial( rtl_material* );
};


class rtl_cone : public rtl_intersection
{
public:
    rtl_cone();

    Type type() const { return objCone; }

protected:
    jVec2 uv( const jVec3& p )
        {
            jFlt d = sqrt(p[0]*p[0]+p[2]*p[2]);
            jFlt v = 1.0-(p[1]+1.0)/2.0;
            jFlt u = p[0]<0 ? asin(fltabs(p[2])/d) : pi-asin(fltabs(p[2])/d);
            if(p[2] > 0) u = pi2-u;
            return jVec2(u/pi2,v);
        }
    void setMaterial( rtl_material* );
};

#endif

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