Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class 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 namespace InSpace {
00027 
00028 class ColorMap;
00029 
00030 // Modes of drawing with display lists.  Defaults to DL_NONE.  If want
00031 // to generate a display list for the object, set to DL_BUILD and next
00032 // time through draw the display list should be created and the mode should
00033 // be updated to DL_DRAW.  When this is set the draw function should simply
00034 // call the DL.
00035 enum DL_MODE {
00036   DL_NONE = 0,
00037   DL_BUILD = 1,
00038   DL_REBUILD = 2,
00039   DL_DRAW = 3,
00040   DL_NO_PENDING_SETMODE = 4
00041 };
00042 
00043 
00044 class DrawObj:public PropertyChangedNotifier
00045 {
00046  public:
00047 
00048   DrawObj(str_ptr name, int roomObj = 0, int display = 1); 
00049   virtual ~DrawObj(); 
00050 
00056   virtual void draw() { cerr << _name << ": draw() not implemented!" << endl; }
00057 
00067   virtual void drawG3D();
00068 
00071   virtual void contextInit() {}
00072 
00073   
00074   str_ptr name() { return _name; }
00075   void setName(str_ptr n) { _name = n; }
00076   
00079   virtual void drawWrapper(bool useG3D);
00080   virtual void contextInitWrapper();
00081   virtual void setDLMode(DL_MODE mode);
00082 
00083   // default selection feedback..
00084   virtual void highlight()   { showBBox(); }
00085   virtual void unhighlight() { hideBBox(); }
00086 
00087   // override these in a subclass..
00088   virtual void reColor(const Color c);
00089   virtual void reColor(ColorMap *cm); 
00090   virtual void reTexture(str_ptr texname);
00091   // for multi-pass rendering, by default draw everying in first pass only
00092   virtual int  drawInPass(int pass) { return (pass==0); }
00093 
00094 
00095   // object's transformation
00096   virtual Wtransf  xform() const      { return _trans*_rot*_scale; }
00097   virtual Wtransf  trans() const      { return _trans; }
00098   virtual Wtransf  rot()   const      { return _rot; }
00099   virtual Wtransf  scale() const      { return _scale; }
00100 
00101   // all these may not have the desired effect if obj is a room obj..
00102   virtual void scaleBy(const double s);
00103   virtual void scaleBy(const Wvec sv);
00104   virtual void transBy(const Wvec v);
00105   virtual void rotBy(const Wtransf m);
00106 
00107 
00108   virtual void setXform(cWtransf& m, bool propagate=true);
00109   virtual void setTrans(cWtransf& m);
00110   virtual void setRot(cWtransf& m);
00111   virtual void setScale(cWtransf& m);
00112 
00113 
00114   // accessors
00115   virtual BBox*    bbox()               { return &_bbox; }
00116   virtual int      display()     const  { return _display; }
00117   virtual int      displayBBox() const  { return _dispBBox; }
00118   virtual int      selectable()  const  { return _selectable; }
00119   virtual int      movable()     const  { return _movable; }
00120   virtual int      transparent() const  { return _transparent; }
00121   virtual int      isRoomObj()   const  { return _roomObj; }
00122 
00123   // control display status
00124   virtual void show()     { _display = 1; }
00125   virtual void hide();
00126   virtual void showBBox() { _dispBBox = 1; }
00127   virtual void hideBBox() { _dispBBox = 0; }
00128 
00129   virtual void setRoomObj(const int i)     { _roomObj = i; }
00130   virtual void setSelectable(const int s)  { _selectable = s; }
00131   virtual void setMovable(const int m)     { _movable = m; }
00132   virtual void setTransparent(const int t) { _transparent = t; }
00133 
00134   // write VRML 1.0 format description of the drawobj
00135   virtual void writeVRML(ostream *os);
00136   // write CPS (CavePainting format) description of the drawobj
00137   virtual void writeCPS(ostream *os);
00138 
00139 
00140   virtual bool isLightOn(const int i) const { return _useLights[i]; }
00141 
00142   virtual void turnOnLight(const int l) {
00143     if (l<8) 
00144       _useLights[l]=true;
00145   }
00146   virtual void turnOffLight(const int l) {
00147     if (l<8) 
00148       _useLights[l]=false;
00149   }
00150 
00151  
00152   // bounding box level of detail selection, returns 1 if point
00153   // lies within bounding box
00154   virtual int pointSelectCoarse(Wpt pw);
00155   virtual int pointSelectCoarse(ROOMpt pr);
00156 
00157   // fine selection, typically returns 1 if the point lies on or
00158   // within the object
00159   virtual int pointSelectFine(Wpt pw);
00160   virtual int pointSelectFine(ROOMpt pr);
00161 
00162   // TODO: return 1 if this ray intersects the object
00163   virtual int raySelectCoarse(Wpt p, Wvec dir, Wpt &isect_point);
00164   virtual int raySelectFine(Wpt p, Wvec dir, Wpt &isect_point);
00165 
00166 
00167 
00168  protected:
00169   
00170   Wtransf _trans,_rot,_scale;
00171   BBox    _bbox;
00172   str_ptr _name;
00173   int     _roomObj;
00174   int     _display,_dispBBox;
00175   int     _selectable;
00176   int     _movable;
00177   int     _transparent;
00178 
00179   DL_MODE                  _pendingDLMode;
00180   isGlContextData<DL_MODE> _dlMode;
00181   isGlContextData<GLuint>  _dl;
00182 
00183   bool _useLights[8];
00184 
00185 };
00186 
00187 
00188 }
00189 
00190 #endif

Generated on Thu Jul 8 15:19:28 2004 for inspace by doxygen 1.3.4