Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

appear.H

Go to the documentation of this file.
00001 #ifndef APPEAR_H_IS_INCLUDED
00002 #define APPEAR_H_IS_INCLUDED
00003 
00004 /*!
00005  *  \file appear.H
00006  *  \brief Contains the definition of the APPEAR class.
00007  *
00008  *  \sa appear.C
00009  *
00010  */
00011 
00012 #include "disp/color.H"
00013 #include "geom/texture.H"
00014 #include "mlib/points.H"
00015 #include "net/data_item.H"
00016 #include "net/stream.H"
00017 #include "std/config.H"
00018 
00019 /*!
00020  *  \brief Generic class representing appearance properties associated
00021  *  with a piece of surface.
00022  *  
00023  *  Properties include:
00024  *   - Ambient color
00025  *   - Diffuse color (refered to as just color)
00026  *   - Specular color
00027  *   - Shininess
00028  *   - Transparency
00029  *   - Texture map
00030  *   - Texture transform.
00031  *
00032  */
00033 class APPEAR {
00034    
00035  protected:
00036    
00037    STDdstream &decode_local(STDdstream &ds);
00038    STDdstream &format_local(STDdstream &ds) const;
00039 
00040    COLOR          _ambient_color;      //!< Ambient color
00041    bool           _has_ambient_color;  //!< true if it has ambient color
00042    COLOR          _color;              //!< Diffuse color
00043    bool           _has_color;          //!< true if it has diffuse color
00044    COLOR          _specular_color;     //!< Specular color
00045    bool           _has_specular_color; //!< true if it has specular color
00046    double         _shininess;          //!< Specular shininess
00047    bool           _has_shininess;      //!< true if it has shininess
00048    double         _transp;             //!< transparency (AKA alpha, in OpenGL)
00049    bool           _has_transp;         //!< true if it has transparency
00050    TEXTUREptr     _texture;            //!< What the texture is
00051    bool           _has_texture;        //!< true if we are textured
00052    mlib::Wtransf  _tex_xform;          //!< Texture transformation
00053       
00054  public:
00055    
00056    //! \name Constructors
00057    //@{
00058    
00059    APPEAR() :
00060       _ambient_color(COLOR::white),
00061       _has_ambient_color(false),
00062       _color(COLOR::white),
00063       _has_color(false),
00064       _specular_color(COLOR::white),
00065       _has_specular_color(false),
00066       _shininess(Config::get_var_dbl("SHININESS",20.0)),
00067       _has_shininess(false),
00068       _transp(1.0),
00069       _has_transp(false),
00070       _has_texture(false) {}
00071       
00072    APPEAR(APPEAR *a) : 
00073       _ambient_color(a->_ambient_color),
00074       _has_ambient_color(a->_has_ambient_color),
00075       _color(a->_color),
00076       _has_color(a->_has_color),
00077       _specular_color(a->_specular_color),
00078       _has_specular_color(a->_has_specular_color),
00079       _shininess(a->_shininess),
00080       _has_shininess(a->_has_shininess),
00081       _transp(a->_transp),
00082       _has_transp(a->_has_transp),
00083       _texture(a->_texture),
00084       _has_texture(a->_has_texture),
00085       _tex_xform(a->_tex_xform) {}
00086       
00087    virtual ~APPEAR() {}
00088       
00089    //@}
00090       
00091    //! \name Property Accessors
00092    //@{
00093       
00094    virtual void set_ambient_color(CCOLOR &c)
00095       { _has_ambient_color = true; _ambient_color = c; }
00096    virtual void unset_ambient_color()
00097       { _has_ambient_color = false; }
00098    virtual bool has_ambient_color() const
00099       { return _has_ambient_color; }
00100    virtual CCOLOR &ambient_color() const
00101       { return _has_ambient_color ? _ambient_color : color(); }
00102       
00103    virtual void set_color(CCOLOR &c)
00104       { _has_color = true;_color = c; }
00105    virtual void unset_color()
00106       { _has_color = false; }
00107    virtual bool has_color() const
00108       { return _has_color; }
00109    virtual CCOLOR &color() const
00110       { return _has_color ? _color : COLOR::white; }
00111       
00112    virtual void set_specular_color(CCOLOR &c)
00113       { _has_specular_color = true;_specular_color = c; }
00114    virtual void unset_specular_color()
00115       { _has_specular_color = false; }
00116    virtual bool has_specular_color() const
00117       { return _has_specular_color; }
00118    virtual CCOLOR &specular_color() const
00119       { return _has_specular_color ? _specular_color : COLOR::white; }
00120       
00121    virtual void set_shininess(double s)
00122       { _has_shininess = true; _shininess = s; }
00123    virtual void unset_shininess()
00124       { _has_shininess = false; }
00125    virtual bool has_shininess() const
00126       { return _has_shininess; }
00127    virtual double shininess() const {
00128       return _has_shininess ? _shininess :
00129          Config::get_var_dbl("SHININESS",20.0);
00130    }
00131       
00132    virtual void set_transp(double t)
00133       { _has_transp = true; _transp = t; }
00134    virtual void unset_transp()
00135       { _has_transp = false; }
00136    virtual bool has_transp() const
00137       { return _has_transp; }
00138    virtual double transp() const
00139       { return _has_transp ? _transp : 1.0; }
00140       
00141    virtual void set_texture(CTEXTUREptr& t)
00142       {_texture = t; _has_texture = (!!t); }
00143    virtual void unset_texture()
00144       { _has_texture = false; }
00145    virtual bool has_texture() const
00146       { return _has_texture; }
00147    virtual CTEXTUREptr &texture() const
00148       { return _texture; }
00149          
00150    virtual mlib::CWtransf &tex_xform() const
00151       { return _tex_xform; }
00152    virtual void set_tex_xform(mlib::CWtransf &t)
00153       { _tex_xform = t; }
00154       
00155    //@}
00156       
00157    //! \name TAG Helper Functions
00158    //@{
00159       
00160    void get_transp (TAGformat &d)       { *d >>_transp; _has_transp = true; }
00161    void get_color  (TAGformat &d)       { *d >>_color;  _has_color  = true; }
00162    void get_texture(TAGformat &d);
00163    void put_color  (TAGformat &d) const { if (_has_color)  d.id() <<_color;}
00164    void put_transp (TAGformat &d) const { if (_has_transp) d.id()<<_transp;}
00165    void put_texture(TAGformat &d) const;
00166       
00167    //@}
00168    
00169 };
00170 
00171 class APPEAR_list;
00172 typedef const APPEAR_list CAPPEAR_list;
00173 
00174 /*!
00175  *  \brief An ARRAY of APPEAR pointers that conveniently lets you call
00176  *  selected methods of APPEAR on a whole bunch of APPEARs in just
00177  *  a single line of code!
00178  *
00179  */
00180 class APPEAR_list : public ARRAY<APPEAR*> {
00181    
00182  public:
00183  
00184    APPEAR_list(int num=0) : ARRAY<APPEAR*>(num) {}
00185    APPEAR_list(APPEAR* a) : ARRAY<APPEAR*>(1)   { add(a); }
00186       
00187    //******** COLOR ********
00188    void set_color(CCOLOR &c) {
00189       for (int k=0; k<num(); k++)
00190          (*this)[k]->set_color(c);
00191    }
00192    void unset_color() {
00193       for (int k=0; k<num(); k++)
00194          (*this)[k]->unset_color();
00195    }
00196       
00197    //******** TEXTURE ********
00198    void set_texture(CTEXTUREptr& t) {
00199       for (int k=0; k<num(); k++)
00200          (*this)[k]->set_texture(t);
00201    }
00202    void unset_texture() {
00203       for (int k=0; k<num(); k++)
00204          (*this)[k]->unset_texture();
00205    }
00206       
00207    //******** TEXTURE TRANSFORM ********
00208    void set_tex_xform(mlib::CWtransf &t) {
00209       for (int k=0; k<num(); k++)
00210          (*this)[k]->set_tex_xform(t);
00211    }
00212       
00213    //******** TRANSPARENCY ********
00214    void set_transp(double t) {
00215       for (int k=0; k<num(); k++)
00216          (*this)[k]->set_transp(t);
00217    }
00218    void unset_transp() {
00219       for (int k=0; k<num(); k++)
00220          (*this)[k]->unset_transp();
00221    }
00222    bool has_transp() {
00223       // if any of them have transparency, return true
00224       for (int k=0; k<num(); k++)
00225          if ((*this)[k]->has_transp())
00226             return 1;
00227       return 0;
00228    }
00229 };
00230 
00231 #endif // APPEAR_H_IS_INCLUDED

Generated on Mon Sep 18 11:39:28 2006 for jot by  doxygen 1.4.4