libjbt

attribute.h

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

#ifndef jbt_attribute_h
#define jbt_attribute_h

#include <jgl/jgl.h>

class jbt_attributenode;


class jbt_attribute
{
public:    
    virtual ~jbt_attribute(){};

    typedef unsigned long Type;


    virtual void reset();


    virtual Type type() const { return 0; }


    static const Type User;


    bool valid() const { return v; }

    static const Type DiffuseClr;
    static const Type SpecularClr;

    static const Type DiffuseCoeff;
    static const Type SpecularCoeff;
    static const Type AmbientCoeff;
    static const Type ReflectionCoeff;
    static const Type TransmissionCoeff;
    
    static const Type SpecularExp;



    inline void add( jbt_attribute* attr, jbt_attributenode* );


    inline void setScale( jFlt );


    inline jFlt getScale() const;
    
protected:
    jbt_attribute();


    virtual void add( jbt_attribute* attr, jFlt c, jbt_attributenode* ) = 0;

private:


    jFlt C;


    bool v;
};


class jbt_colour : public jbt_attribute
{
public:


    jbt_colour( const jColour& _clr, jbt_attribute::Type _t ) 
            : jbt_attribute(), clr(_clr), t(_t)
        {}
    

    jbt_colour( jbt_attribute::Type _t )
            : jbt_attribute(), clr(jColour::black), t(_t)
        {}


    operator const jColour& () const { return clr; }


    const jColour& getColour() const { return clr; }


    void setColour( const jColour& _clr ) { clr = _clr; }


    void reset();

    void add( jbt_attribute*, jFlt, jbt_attributenode* );

protected:
    

    virtual const jColour& colour( jbt_attributenode* ) { return clr; }
    
    jbt_attribute::Type type() const { return t; }

    jColour clr;

private:
    
    jbt_attribute::Type t;
    
};


class jbt_scalar : public jbt_attribute
{
public:


    jbt_scalar( jFlt _val, jbt_attribute::Type _t ) 
            : jbt_attribute(), val(_val), t(_t)
        {}
    

    jbt_scalar( jbt_attribute::Type _t )
            : jbt_attribute(), val(0), t(_t)
        {}


    operator const jFlt& () const { return val; }


    const jFlt& getValue() const { return val; }


    void setValue( const jFlt& _val ) { val = _val; }


    void reset();

    void add( jbt_attribute*, jFlt, jbt_attributenode* );

protected:
    

    virtual const jFlt& value( jbt_attributenode* ) { return val; }
    
    jbt_attribute::Type type() const { return t; }

    jFlt val;

private:
    
    jbt_attribute::Type t;
    
};

class jbt_diffuse : public jbt_colour
{
public:
    jbt_diffuse( const jColour& clr = jColour::black )
            : jbt_colour(clr,jbt_attribute::DiffuseClr)
        {}
};

class jbt_specular : public jbt_colour
{
public:
    jbt_specular( const jColour& clr = jColour::black )
            : jbt_colour(clr,jbt_attribute::SpecularClr)
        {}
};

void jbt_attribute::setScale( jFlt _C ) 
{ 
    C = _C; 
}

jFlt jbt_attribute::getScale() const
{
    return C;
}

void jbt_attribute::add( jbt_attribute* attr, jbt_attributenode* n )
{
    // if the attributes are of the same type and this term in the 
    // linear combination is non-zero.
    if(type()==attr->type() && C>0)
    {
        add(attr,C,n);  // add in this term to the combination
        v = true;       // set the validity flag.
        C = 0.0;        // set the coefficient to indicate the term is now 0
    }
}


#endif

JSP / libjbt v0.1 mtigges@cpsc.ucalgary.ca