librtl

csg.h

This is the verbatim text of the csg.h include file.
#ifndef csg_h
#define csg_h

#include "object.h"


class rtl_csg : public rtl_object
{
public:


    rtl_object* leftobject() { return left; }


    rtl_object* rightobject() { return right; }

    Type type() const { return objCSG; }

protected:
    rtl_csg( rtl_object*, rtl_object* );
    ~rtl_csg();

    inline jFlt lclintersect( const rtl_ray& );
    inline jNorm3 lclnormal( const jVec3& );
    inline jFlt rehit();

    jVec2 uv( const jVec3& p )
        { return struck->uv(p); }
    
    rtl_object* left;
    rtl_object* right;
    rtl_object* struck;

    jInt hitcnt, hiti, lhit;
    
    struct csghit
    {
        bool inleft() const { return flg&Left; }
        bool inright() const { return flg&Right; }
        
        rtl_object* obj;
        jVec3 I;
        jFlt t;
        jULng flg;

        static int compare( csghit*, csghit* );
    } *hits;

    inline jFlt nexthit( const rtl_ray&, rtl_object*, jFlt, bool );
    inline void newhit( rtl_object*, jFlt, jULng );
    inline void processhits(bool,bool);
    void sethit( const csghit& hit, bool nn = false )
        {
            struck = hit.obj;
            flags().set(Entrance,hit.flg&(LeftEntrance|RightEntrance));
            struck->objectspace(hit.I);
            flags().set(NegateNormal,hit.flg&NegateNormal || nn);
        }

    virtual jFlt combine() = 0;

    const jVec3& objectspace() const
        {  return struck->objectspace(); }
    void objectspace( const jVec3& osi )
        { if(struck)struck->objectspace(osi); }
    rtl_object* laststruck()
        { return struck; }
    
    static const jULng Left;
    static const jULng Right;

    static const jULng LeftEntrance;
    static const jULng LeftExit;
    static const jULng RightEntrance;
    static const jULng RightExit;

    static const jFlt Delta;
public:
    
    static const jULng Debug;
    
};


class rtl_union : public rtl_csg
{
public:
    rtl_union( rtl_object*, rtl_object* );

private:
    jFlt combine();

};


class rtl_intersection : public rtl_csg
{
public:
    rtl_intersection( rtl_object*, rtl_object* );
    
private:
    jFlt combine();
};


class rtl_difference : public rtl_csg
{
public:
    rtl_difference( rtl_object*, rtl_object* );

private:
    jFlt combine();
};


#include "csg.inl"

#endif

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