librtl

torus.h

This is the verbatim text of the torus.h include file.
#ifndef torus_h
#define torus_h

#include "object.h"


class rtl_torus : public rtl_object
{
public:


    rtl_torus( jFlt = 0.75, jFlt = 0.25 );

    Type type() const { return objTorus; }

private:
    jFlt lclintersect( const rtl_ray& );
    jNorm3 lclnormal( const jVec3& );

    jVec2 uv( const jVec3& p )
        {
            jFlt d = sqrt(p[0]*p[0]+p[2]*p[2]);
            jFlt v = p[1] > 0 ? asin(d) : pi-asin(d);
            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(v / pi,u / pi2);
        }
    
    jFlt a,b;
};

#endif

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