Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

DrawObj.H

Go to the documentation of this file.
00001 
00010 #ifndef DRAWOBJ_H
00011 #define DRAWOBJ_H
00012 
00013 
00014 #include "BBox.H"
00015 #include "Color.H"
00016 
00017 // Gluebase includes
00018 #define OUTSIDE_GLUE_CORE
00019 #include <mlib/points.H>
00020 
00021 #include "glwrap.H"
00022 #include "PropertyChangeNotifier.H"
00023 
00024 #include "streamwrap.H"
00025 
00026 class ColorMap;
00027 
00028 // Modes of drawing with display lists.  Defaults to DL_NONE.  If want
00029 // to generate a display list for the object, set to DL_BUILD and next
00030 // time through draw the display list should be created and the mode should
00031 // be updated to DL_DRAW.  When this is set the draw function should simply
00032 // call the DL.
00033 enum DL_MODE {
00034   DL_NONE = 0,
00035   DL_BUILD = 1,
00036   DL_REBUILD = 2,
00037   DL_DRAW = 3,
00038   DL_NO_PENDING_SETMODE = 4
00039 };
00040 
00041 
00042 class DrawObj:public PropertyChangedNotifier
00043 {
00044  public:
00045 
00046   DrawObj(str_ptr name, int roomObj = 0, int display = 1); 
00047   virtual ~DrawObj(); 
00048 
00049   // pure virtual function, must be implemented in subclasses
00050   // should also implement contextInit if you need to do initialization
00051   // in a GL context
00052   virtual void draw()=0;
00053   virtual void contextInit() {}
00054 
00055   str_ptr name() { return _name; }
00056   void setName(str_ptr n) { _name = n; }
00057   
00058   // handle calling draw appropriately given that we sometimes want to
00059   // call a display list..
00060   virtual void setDLMode(DL_MODE mode);
00061   virtual void drawWrapper();
00062   virtual void contextInitWrapper();
00063 
00064   // default selection feedback..
00065   virtual void highlight()   { showBBox(); }
00066   virtual void unhighlight() { hideBBox(); }
00067 
00068   // override these in a subclass..
00069   virtual void reColor(const Color c);
00070   virtual void reColor(ColorMap *cm); 
00071   virtual void reTexture(str_ptr texname);
00072   // for multi-pass rendering, by default draw everying in first pass only
00073   virtual int  drawInPass(int pass) { return (pass==0); }
00074 
00075 
00076   // object's transformation
00077   virtual Wtransf  xform() const      { return _trans*_rot*_scale; }
00078   virtual Wtransf  trans() const      { return _trans; }
00079   virtual Wtransf  rot()   const      { return _rot; }
00080   virtual Wtransf  scale() const      { return _scale; }
00081 
00082   // all these may not have the desired effect if obj is a room obj..
00083   virtual void scaleBy(const double s);
00084   virtual void scaleBy(const Wvec sv);
00085   virtual void transBy(const Wvec v);
00086   virtual void rotBy(const Wtransf m);
00087 
00088 
00089   virtual void setXform(cWtransf& m);
00090   virtual void setTrans(cWtransf& m);
00091   virtual void setRot(cWtransf& m);
00092   virtual void setScale(cWtransf& m);
00093 
00094 
00095   // accessors
00096   virtual BBox*    bbox()               { return &_bbox; }
00097   virtual int      display()     const  { return _display; }
00098   virtual int      displayBBox() const  { return _dispBBox; }
00099   virtual int      selectable()  const  { return _selectable; }
00100   virtual int      movable()     const  { return _movable; }
00101   virtual int      transparent() const  { return _transparent; }
00102   virtual int      isRoomObj()   const  { return _roomObj; }
00103 
00104   // control display status
00105   virtual void show()     { _display = 1; }
00106   virtual void hide();
00107   virtual void showBBox() { _dispBBox = 1; }
00108   virtual void hideBBox() { _dispBBox = 0; }
00109 
00110   virtual void setRoomObj(const int i)     { _roomObj = i; }
00111   virtual void setSelectable(const int s)  { _selectable = s; }
00112   virtual void setMovable(const int m)     { _movable = m; }
00113   virtual void setTransparent(const int t) { _transparent = t; }
00114 
00115   // write VRML 1.0 format description of the drawobj
00116   virtual void writeVRML(ostream *os);
00117   // write CPS (CavePainting format) description of the drawobj
00118   virtual void writeCPS(ostream *os);
00119 
00120 
00121   virtual bool isLightOn(const int i) const { return _useLights[i]; }
00122 
00123   virtual void turnOnLight(const int l) {
00124     if (l<8) 
00125       _useLights[l]=true;
00126   }
00127   virtual void turnOffLight(const int l) {
00128     if (l<8) 
00129       _useLights[l]=false;
00130   }
00131 
00132  
00133   // bounding box level of detail selection, returns 1 if point
00134   // lies within bounding box
00135   virtual int pointSelectCoarse(Wpt pw);
00136   virtual int pointSelectCoarse(ROOMpt pr);
00137 
00138   // fine selection, typically returns 1 if the point lies on or
00139   // within the object
00140   virtual int pointSelectFine(Wpt pw);
00141   virtual int pointSelectFine(ROOMpt pr);
00142 
00143   // TODO: return 1 if this ray intersects the object
00144   virtual int raySelectCoarse(Wpt p, Wvec dir, Wpt &isect_point);
00145   virtual int raySelectFine(Wpt p, Wvec dir, Wpt &isect_point);
00146 
00147 
00148 
00149  protected:
00150   
00151   Wtransf _trans,_rot,_scale;
00152   BBox    _bbox;
00153   str_ptr _name;
00154   int     _roomObj;
00155   int     _display,_dispBBox;
00156   int     _selectable;
00157   int     _movable;
00158   int     _transparent;
00159 
00160   DL_MODE                  _pendingDLMode;
00161   isGlContextData<DL_MODE> _dlMode;
00162   isGlContextData<GLuint>  _dl;
00163 
00164   bool _useLights[8];
00165 
00166 };
00167 
00168 #endif

Generated on Mon Sep 15 16:27:55 2003 for inspace by doxygen1.2.18