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

view.H

Go to the documentation of this file.
00001 #ifndef VIEW_H
00002 #define VIEW_H
00003 
00004 #include "disp/gel.H"
00005 #include "disp/cam.H"
00006 #include "disp/gel_filt.H"
00007 #include "disp/color.H"
00008 #include "disp/ray.H"
00009 #include "disp/light.H"
00010 #include "geom/image.H"         // disp should not include geom
00011 #include "geom/texture.H"       //  ditto
00012 #include "std/support.H"
00013 #include "std/stop_watch.H"
00014 
00015 class Animator;
00016 class Recorder;
00017 class WINSYS;
00018 class FRAME_TIME_OBSERVER;
00019 
00020 class FRAME_TIME_OBSERVER_list: public ARRAY<FRAME_TIME_OBSERVER*> {
00021  public:
00022    FRAME_TIME_OBSERVER_list(int n=0) : ARRAY<FRAME_TIME_OBSERVER*>(n) {}
00023    FRAME_TIME_OBSERVER_list(const FRAME_TIME_OBSERVER_list& l) :
00024       ARRAY<FRAME_TIME_OBSERVER*>(l) {}
00025 
00026    void frame_time_changed() const;
00027 };
00028 
00029 extern Cstr_ptr RSMOOTH_SHADE;
00030 extern Cstr_ptr RFLAT_SHADE;
00031 extern Cstr_ptr RSPEC_SHADE;
00032 extern Cstr_ptr RHIDDEN_LINE;
00033 extern Cstr_ptr RWIRE_FRAME;
00034 extern Cstr_ptr RNORMALS;
00035 extern Cstr_ptr RNORMALS_ONLY;
00036 extern Cstr_ptr RCOLOR_ID;
00037 extern Cstr_ptr RSHOW_TRI_STRIPS;
00038 extern Cstr_ptr RKEY_LINE;
00039 extern Cstr_ptr RSIL_FRAME;
00040 extern Cstr_ptr SKYBOX_GRADIENT;
00041 
00042 MAKE_PTR_SUBC(VIEW, SCHEDULER);
00043 //
00044 // Observe changes to VIEW's
00045 //
00046 class VIEWobs {
00047 
00048  public:
00049    typedef ARRAYptrs<VIEWobs *> view_list;
00050  protected:
00051    static view_list *_view_obs;
00052    static view_list *viewobs_list() { return _view_obs ? _view_obs: 
00053       _view_obs = new view_list;}
00054  public :
00055    virtual ~VIEWobs() {}
00056    virtual void notify_view   (CVIEWptr &, int) = 0;
00057    static  void notify_viewobs(CVIEWptr &v, int f) {
00058       for (int i=0; i<viewobs_list()->num(); i++)
00059          (*_view_obs)[i]->notify_view(v,f); }
00060    void view_obs  ()     { viewobs_list()->add_uniquely(this); }
00061    void unobs_view()     { viewobs_list()->rem         (this); }
00062 };
00063 
00064 #define CVIEWlist const VIEWlist
00065 class VIEWlist : public LIST<VIEWptr> {
00066  public :
00067    VIEWlist(int num=16):LIST<VIEWptr>(num) { }
00068 
00069    void rem     (CVIEWptr &v) { LIST<VIEWptr>::rem(v); 
00070    VIEWobs::notify_viewobs(v,0); }
00071    void add     (CVIEWptr &v) { LIST<VIEWptr>::add_uniquely(v); 
00072    VIEWobs::notify_viewobs(v,1); }
00073 };
00074 
00075 //
00076 // ThreadObs - get called back before a render thread starts rendering for
00077 // the first time
00078 //
00079 class ThreadObs;
00080 typedef ARRAYptrs<ThreadObs*> Threadobs_list;
00081 class ThreadObs {
00082  protected:
00083    static Threadobs_list *_all_thread;
00084    static Threadobs_list *thread_list() { if (!_all_thread)
00085       _all_thread = new Threadobs_list; return _all_thread; }
00086  public:
00087    virtual ~ThreadObs() {}
00088    virtual void notify_render_thread    (CVIEWptr &) = 0;
00089    static  void notify_render_thread_obs(CVIEWptr &v) {
00090       for (int i=0; i < thread_list()->num(); i++)
00091          (*thread_list())[i]->notify_render_thread(v); }
00092 
00093    void thread_obs()           { thread_list()->add_uniquely(this); }
00094    void unobs_thread()         { thread_list()->rem         (this); }
00095 };
00096 
00097 class STENCILCB {
00098  public:
00099    virtual ~STENCILCB() {}
00100    virtual int  stencil_cb() = 0;
00101    virtual void stencil_bounds(mlib::XYpt_list &pts) = 0;
00102 };
00103 
00104 #define CCLEARobsptr const CLEARobsptr
00105 MAKE_PTR_BASEC(CLEARobs);
00106 class CLEARobs : public REFcounter {
00107  public :
00108    virtual void notify_clear(CVIEWptr &) = 0;
00109 };
00110 
00111 
00112 //
00113 // VIEWimpl is the implementation interface that enables a VIEW to actually 
00114 //          have a side effect on a display surface
00115 //
00116 class REF_CLASS(VIEWimpl) {
00117   protected:
00118    VIEWptr  _view;
00119   public:
00120    enum stereo_mode {
00121       NONE = 0,
00122       HMD,
00123       LCD,
00124       TWO_BUFFERS,
00125       LEFT_EYE_MONO,   // used for IBM's Yotta hardware
00126       RIGHT_EYE_MONO,  // used for IBM's Yotta hardware
00127       SCISSOR_STEREO   // XXX - obsolete?
00128    };
00129    virtual        ~VIEWimpl()                    {}
00130    virtual void   set_view(CVIEWptr &v)          { _view = v; }
00131    virtual void   set_rendering(Cstr_ptr &)      {}
00132    virtual void   set_stereo (stereo_mode)       {}
00133    virtual void   set_size   (int, int, int, int){}
00134    virtual void   set_cursor (int)               {} // Switch to 'i'th cursor
00135    virtual int    get_cursor ()                  { return -1;} 
00136    virtual void   set_focus()                    {}
00137    virtual void   draw_bb    (mlib::CWpt_list &) const {}
00138    virtual void   setup_lights(CAMdata::eye=CAMdata::MIDDLE) {}
00139    virtual int    paint()                        { return 0; }
00140    virtual void   swap_buffers()                 {}
00141    virtual void   prepare_buf_read()             {}
00142    virtual void   end_buf_read()                 {}
00143    virtual void   read_pixels(uchar *,bool a=false)  {}
00144    virtual int    stencil_draw(STENCILCB *, GELlist * = 0) { return 0; }
00145    virtual bool   antialias_check() { return false; }
00146 
00147    virtual void    draw_setup() {}
00148    virtual int     draw_frame(CAMdata::eye = CAMdata::MIDDLE) { return 0; }
00149 };
00150 
00151 //----------------------------------------------
00152 //
00153 //VIEW
00154 //     Contains a list of objects to be displayed, dispatches events to FSA's
00155 //
00156 //----------------------------------------------
00157 // MAKE_PTR_SUBC(VIEW, SCHEDULER); it's called higher up in the file
00158 
00159 #define CHANGED(X) VIEWobs::notify_viewobs(this, X) 
00160 
00161 class ThreadData;
00162 //XXX - Added DATA_ITEM (seem to recall that the
00163 //parent class order matters in some way, hope this
00164 //is okay...)
00165 class VIEW: public SCHEDULER, public DISPobs, public DATA_ITEM  {
00166  public: 
00167    enum filt {
00168       H_GEOM       = 0,
00169       H_TEXT       = (1 << 0),
00170       H_UNPICKABLE = (1 << 1),
00171       H_ALL        = (1 << 8)-1
00172    };
00173 
00174    enum change_t {
00175       LIGHTING_CHANGED = 0,
00176       COLOR_ALPHA_CHANGED,
00177       PAPER_CHANGED,
00178       TEXTURE_CHANGED,
00179       ANTIALIAS_CHANGED,
00180       UNKNOWN_CHANGED
00181    };
00182 
00183    enum render_mode_t {
00184       NORMAL_MODE = 0,
00185       OPAQUE_MODE,
00186       TRANSPARENT_MODE,
00187       RENDER_MODE_NUM
00188    };
00189 
00190    typedef              VIEWimpl::stereo_mode stereo_mode;
00191 
00192    /////////////////
00193    //DATA_ITEM stuff
00194    /////////////////
00195  private:
00196    static TAGlist  *_v_tags;
00197  protected:
00198    bool    _in_data_file;
00199  public:
00200 
00201    //XXX SCHEDULER is a base class that already
00202    //has class_name, etc.  Should use RTTI_METHODS2???
00203    //DEFINE_RTTI_METHODS_BASE("VIEW", CDATA_ITEM*);
00204    VIEW () : _view_id(-1)     { err_msg("VIEW::VIEW() - DUMMY CONSTRUCTOR!!!!!"); }
00205    virtual  DATA_ITEM *dup()  const { return new VIEW; }
00206    virtual  CTAGlist  &tags() const;
00207   
00208    //IO Stuff
00209    void     get_view_animator (TAGformat &d);
00210    void     put_view_animator (TAGformat &d) const;
00211 
00212    void     get_view_data_file (TAGformat &d);
00213    void     put_view_data_file (TAGformat &d) const;
00214 
00215    void     get_view_color (TAGformat &d);
00216    void     put_view_color (TAGformat &d) const;
00217 
00218    void     get_view_alpha (TAGformat &d);
00219    void     put_view_alpha (TAGformat &d) const;
00220 
00221    void     get_view_paper_use (TAGformat &d);
00222    void     put_view_paper_use (TAGformat &d) const;
00223 
00224    void     get_view_paper_name (TAGformat &d);
00225    void     put_view_paper_name (TAGformat &d) const;
00226 
00227    void     get_view_paper_active (TAGformat &d);
00228    void     put_view_paper_active (TAGformat &d) const;
00229 
00230    void     get_view_paper_brig (TAGformat &d);
00231    void     put_view_paper_brig (TAGformat &d) const;
00232 
00233    void     get_view_paper_cont (TAGformat &d);
00234    void     put_view_paper_cont (TAGformat &d) const;
00235 
00236    void     get_view_texture (TAGformat &d);
00237    void     put_view_texture (TAGformat &d) const;
00238 
00239    void     get_view_light_coords (TAGformat &d);
00240    void     put_view_light_coords (TAGformat &d) const;
00241 
00242    void     get_view_light_positional (TAGformat &d);
00243    void     put_view_light_positional (TAGformat &d) const;
00244 
00245    void     get_view_light_cam_space (TAGformat &d);
00246    void     put_view_light_cam_space (TAGformat &d) const;
00247 
00248    void     get_view_light_color_diff (TAGformat &d);
00249    void     put_view_light_color_diff (TAGformat &d) const;
00250 
00251    void     get_view_light_color_amb (TAGformat &d);
00252    void     put_view_light_color_amb (TAGformat &d) const;
00253 
00254    void     get_view_light_color_global (TAGformat &d);
00255    void     put_view_light_color_global (TAGformat &d) const;
00256 
00257    void     get_view_light_enable (TAGformat &d);
00258    void     put_view_light_enable (TAGformat &d) const;
00259 
00260    void     get_view_antialias_enable (TAGformat &d);
00261    void     put_view_antialias_enable (TAGformat &d) const;
00262 
00263    void     get_view_antialias_mode (TAGformat &d);
00264    void     put_view_antialias_mode (TAGformat &d) const;
00265 
00266  protected:
00267 
00268    LIST<CLEARobsptr> _clear_obs;// callbacks for when display is cleared
00269 
00270 
00271    static VIEWlist _views;       // view stack used by points.H types
00272    static str_list _rend_types;  // list of rendering styles
00273 
00274    VIEWimpl     *_impl;          // display implementation
00275 
00276    static        int _num_views;
00277    const         int _view_id;
00278 
00279    ARRAY<STENCILCB*> _stencil_cbs;// Stencil buffers!
00280 
00281    str_ptr       _name;          // view's name
00282    CAMptr        _cam;           // camera definition for view
00283    CAMhist       _cam_hist;      // history of previous camera views 
00284    int           _cam_hist_cur;  // current place in history
00285 
00286    GELlist       _active;        // objects that are active
00287    GELlist       _drawn;         // objects in field of view (post-cull)
00288 
00289    int           _width;         // width of view
00290    int           _height;        // height of view
00291    COLOR         _bkgnd_col;     // background color of view
00292 
00293    stereo_mode   _stereo;        // whether we're in stereo mode
00294    str_ptr       _render_type;   // the current render technique
00295    int           _tris;          // number of triangles drawn
00296 
00297    bool          _is_clipping;   // Is a clipping plane in effect?
00298    mlib::Wplane  _clip_plane;
00299 
00300    int           _dont_swap;     // a buffer swap is pending a network synch
00301    int           _dont_draw;
00302    int           _messages_sent; // number of displays to synch with
00303 
00304    int           _has_scissor_region;
00305    double        _sxmin, _sxmax; // scissoring range (from -1 to 1)
00306 
00307    mlib::Wtransf _lens;          // "lens" for selecting a particular subregion
00308                                  // (or tile) of current window to render at 
00309                                  // full resolution of window:
00310 
00311    mlib::Wtransf _jitter;        // fullscene antialiasing
00312 
00313    Recorder*         _recorder;
00314 
00315    enum { MAX_LIGHTS = 8 };
00316  public:
00317    static int max_lights() { return MAX_LIGHTS; }
00318  protected:
00319 
00320    Light        _lights[MAX_LIGHTS];    // individual lights
00321    COLOR        _light_global_ambient;  // global ambient light
00322 
00323    static ARRAY<ARRAY<mlib::VEXEL>*> _jitters;
00324 
00325    //Used in constructor to setup defaults
00326    void              init_lights();
00327    void              init_jitter();
00328 
00329    double            _alpha;         // alpha of background (used by npr_view for papering)
00330    bool              _use_paper;     // whether paper effect should affect bkg
00331    str_ptr           _bkg_file;      // filename of background image (NULL_STR = none)
00332    TEXTUREptr        _bkg_tex;       // texture of the above image (setup by npr_view)
00333    mlib::Wtransf     _bkg_tf;        // NDC->UV bkg tex transform
00334 
00335    str_ptr           _data_file;     // if not null_str, the view is seralized to _data_file.view
00336 
00337    Animator*         _animator;
00338 
00339    render_mode_t     _render_mode;
00340 
00341    int               _antialias_mode;
00342    int               _antialias_enable;
00343    bool              _antialias_init;
00344   
00345  public:
00346    void              set_focus()                            { if (_impl) _impl->set_focus();  }
00347 
00348    void              set_jitter(int n, int i); //n==-1 resets to identity
00349    static int        get_jitter_num(int n)                  { assert(_jitters.valid_index(n)); return (*(_jitters[n])).num(); }
00350    static int        get_jitter_mode_num()                  { return _jitters.num(); }
00351 
00352    int               get_antialias_enable() const           { return _antialias_enable; }
00353    void              set_antialias_enable(bool a)           
00354       { _antialias_enable = a; if (_impl && !_impl->antialias_check()) _antialias_enable = 0; CHANGED(ANTIALIAS_CHANGED);}
00355 
00356    int               get_antialias_mode() const             { return _antialias_mode; }
00357    void              set_antialias_mode(int a) 
00358       { _antialias_mode = a; if (_impl && !_impl->antialias_check()) _antialias_enable = 0; CHANGED(ANTIALIAS_CHANGED);}
00359 
00360    render_mode_t     get_render_mode() const                { return _render_mode; }
00361    void              set_render_mode(render_mode_t r);
00362 
00363    Animator*         animator()                             { return _animator; }
00364 
00365    void              set_data_file(str_ptr f)               { _data_file = f; }
00366    Cstr_ptr&         get_data_file() const                  { return _data_file; }
00367 
00368    void              set_alpha(double a);
00369    double            get_alpha() const                      { return _alpha; }
00370 
00371    void              set_use_paper(bool p)                  { _use_paper = p; CHANGED(PAPER_CHANGED);}
00372    bool              get_use_paper() const                  { return _use_paper; }
00373 
00374    // Setting filename kills texture:
00375    void              set_bkg_file(str_ptr f)                { _bkg_file = f; _bkg_tex = NULL; CHANGED(TEXTURE_CHANGED);}
00376    
00377    // npr_view sets this from the filename:
00378    Cstr_ptr&         get_bkg_file() const                   { return _bkg_file; }
00379                                              
00380    void              set_bkg_tex(TEXTUREptr t)              { _bkg_tex = t; CHANGED(TEXTURE_CHANGED);}
00381    CTEXTUREptr&      get_bkg_tex() const                    { return _bkg_tex; }
00382 
00383    void              set_bkg_tf(mlib::CWtransf &tf)               { _bkg_tf = tf; }
00384    mlib::CWtransf&         get_bkg_tf() const                     { return _bkg_tf; }
00385 
00386 
00387    //******** GLOBAL AMBIENT LIGHT ********
00388 
00389    // Set global ambient light color:
00390    void light_set_global_ambient(CCOLOR &c) {
00391       _light_global_ambient = c;
00392       CHANGED(LIGHTING_CHANGED);
00393    }
00394    // Get global ambient light color:
00395    COLOR light_get_global_ambient() const {
00396       return _light_global_ambient;
00397    }
00398 
00399    //******** SETTING VALUES FOR LIGHT i ********
00400 
00401    // Set all values for light i:
00402    void set_light(int i, const Light& l) {
00403       if (0 <= i && i < MAX_LIGHTS) {
00404          _lights[i] = l;
00405          CHANGED(LIGHTING_CHANGED);
00406       }
00407    }
00408    // Set type of light i to positional
00409    void light_set_positional(int i, bool p) {
00410       if (0 <= i && i < MAX_LIGHTS) {
00411          _lights[i]._is_positional = p;
00412          CHANGED(LIGHTING_CHANGED);
00413       }
00414    }
00415    // Sets a directional light:
00416    void light_set_coordinates_v(int i, mlib::CWvec &v) {
00417       if (0 <= i && i < MAX_LIGHTS) {
00418          _lights[i].set_direction(v);
00419          CHANGED(LIGHTING_CHANGED);
00420       }
00421    }
00422    // Sets a positional light:
00423    void light_set_coordinates_p(int i,mlib::CWpt &p) {
00424       if (0 <= i && i < MAX_LIGHTS) {
00425          _lights[i].set_position(p);
00426          CHANGED(LIGHTING_CHANGED);
00427       }
00428    }
00429    // Tell if light coordinates are defined in camera space or world space:
00430    void light_set_in_cam_space(int i, bool c) {
00431       if (0 <= i && i < MAX_LIGHTS) {
00432          _lights[i]._is_in_cam_space = c;
00433          CHANGED(LIGHTING_CHANGED);
00434       }
00435    }
00436    // Set the ambient color for light i:
00437    void light_set_ambient(int i, CCOLOR& c) {
00438       if (0 <= i && i < MAX_LIGHTS) {
00439          _lights[i]._ambient_color = c;
00440          CHANGED(LIGHTING_CHANGED);
00441       }
00442    }
00443    // Set the diffuse color for light i:
00444    void light_set_diffuse(int i, CCOLOR& c) {
00445       if (0 <= i && i < MAX_LIGHTS) {
00446          _lights[i]._diffuse_color = c;
00447          CHANGED(LIGHTING_CHANGED);
00448       }
00449    }
00450    // Enable or disable light i
00451    void light_set_enable(int i, bool e) {
00452       if (0 <= i && i < MAX_LIGHTS) {
00453          _lights[i]._is_enabled = e;
00454          CHANGED(LIGHTING_CHANGED);
00455       }
00456    }
00457 
00458    //******** GETTING VALUES FOR LIGHT i ********
00459 
00460    // Get all properties for light i:
00461    const Light& get_light(int i) const {
00462       assert(0 <= i && i < MAX_LIGHTS);
00463       return _lights[i];
00464    }
00465    // Return coordinates for light i:
00466    mlib::Wvec light_get_coordinates_v(int i) const {
00467       assert(0 <= i && i < MAX_LIGHTS);
00468       return _lights[i].get_direction();
00469    }
00470    mlib::Wpt light_get_coordinates_p(int i) const {
00471       assert(0 <= i && i < MAX_LIGHTS);
00472       return _lights[i].get_position();
00473    }
00474    bool light_get_positional(int i) const {
00475       assert(0 <= i && i < MAX_LIGHTS);
00476       return _lights[i]._is_positional;
00477    }   
00478    bool light_get_in_cam_space(int i) const {
00479       assert(0 <= i && i < MAX_LIGHTS);
00480       return _lights[i]._is_in_cam_space;
00481    }
00482    COLOR light_get_diffuse(int i) const {
00483       assert(0 <= i && i < MAX_LIGHTS);
00484       return _lights[i]._diffuse_color;
00485    }
00486    COLOR light_get_ambient(int i) const {
00487       assert(0 <= i && i < MAX_LIGHTS);
00488       return _lights[i]._ambient_color;
00489    }
00490 
00491    bool light_get_enable(int i) const {
00492       assert(0 <= i && i < MAX_LIGHTS);
00493       return _lights[i]._is_enabled;
00494    }
00495    // Return true if any light is enabled:
00496    bool lights_on() const {
00497       for (int i=0; i<MAX_LIGHTS; i++)
00498          if (_lights[i]._is_enabled)
00499             return true;
00500       return false;
00501    }
00502 
00503  protected:
00504 
00505    // scale factor for drawing lines when grabbing screen
00506    // image at hi-res:
00507    double               _line_scale;
00508 
00509    bool                 _grabbing_screen;
00510 
00511    double               _spf;              // target seconds per frames
00512    stop_watch           _spf_timer;        // timer for maintaining target fps
00513    double               _frame_time;       // the "time" of the current frame
00514    static unsigned int  _stamp;            // frame #: incremented by draw()
00515    static double        _pix_to_ndc_scale; // scale from pixel coords to NDC
00516                                            // coords. updated by draw()
00517 
00518    // objects that get notified when _frame_time changes:
00519    FRAME_TIME_OBSERVER_list _frame_time_observers;
00520 
00521    WINSYS              *_win;
00522 
00523    SCREENptr            _screen;
00524 
00525  public:
00526    VIEW (Cstr_ptr &s, WINSYS *win, VIEWimpl *i);
00527    virtual              ~VIEW () { while (_jitters.num() > 0) delete _jitters.pop(); }
00528 
00529    static int           stack_size()               { return _views.num(); }
00530    static void          push(CVIEWptr &view)       { _views += view; }
00531    static void          pop ()                     { _views.pop(); }
00532 #ifdef USE_PTHREAD
00533    static VIEWptr       peek();
00534    static const VIEW    *peek_ptr();
00535 #else
00536    static VIEWptr       peek()                     { return _views.last(); }
00537    static const VIEW    *peek_ptr()                 { return &*_views.last(); }
00538 #endif
00539    static CAMptr        peek_cam()                 { return peek_ptr()->cam(); }
00540    static CCAMptr       &peek_cam_const()          { return peek_ptr()->cam(); }
00541    static void          peek_size(int &w, int &h)  { peek_ptr()->get_size(w,h);}
00542 
00543    // return width and height of current view in one convenient package:
00544    static mlib::Point2i cur_size() {
00545       mlib::Point2i ret;
00546       peek_size(ret[0],ret[1]);
00547       return ret;
00548    }
00549 
00550    double frame_time() const { return _frame_time; }
00551    void set_frame_time(double t);
00552 
00553    void add_frame_time_observer(FRAME_TIME_OBSERVER* obs) {
00554       _frame_time_observers.add_uniquely(obs);
00555    }
00556    void remove_frame_time_observer(FRAME_TIME_OBSERVER* obs) {
00557       _frame_time_observers.rem(obs);
00558    }
00559 
00560    static unsigned int  stamp()                    { return _stamp; }
00561 
00562    static void          add_rend_type(Cstr_ptr &r) { _rend_types += r; }
00563    static Cstr_list&    rend_list()                { return _rend_types; }
00564    static void          set_rend_list(Cstr_list& l){ _rend_types = l; }
00565 
00566    static int           num_views()                { return _num_views;}
00567 
00568    //recorder access
00569    Recorder*    recorder()                 { return _recorder;}
00570 
00571    /// Returns the location of the camera:
00572    static mlib::Wpt       eye()            { return peek_cam()->data()->from(); }
00573    /// Returns a unit vector pointing from the camera to point p:
00574    static mlib::Wvec      eye_vec(mlib::CWpt& p) { return (p - eye()).normalized(); }
00575 
00576    //!METHS: core components of a view
00577    str_ptr              name()               const { return str_ptr(_name); }
00578    VIEWimpl             *impl()               const { return _impl; }
00579    CGELlist             &drawn()              const { return _drawn; }
00580    CGELlist             &active()             const { return _active; }
00581    CCAMptr              &cam()                const { return _cam; }
00582    CAMptr               cam()                      { return _cam; }
00583 
00584    // Camera history
00585    void save_cam(CCAMptr c=0);
00586    void fwd_cam_hist();
00587    void bk_cam_hist();
00588 
00589    // Copies camera params into VIEW's cam:
00590    void copy_cam(CCAMptr &c);
00591   
00592    // VIEW switches to using the given CAM:
00593    void use_cam(CCAMptr &c);
00594    
00595    int         tick();
00596    int         view_id()            const { return _view_id; }
00597 
00598    //!METHS: general rendering parameters
00599    void        stereo(stereo_mode m)      { _stereo      = m;}
00600    stereo_mode stereo()             const { return   _stereo;}
00601    void        set_rendering(Cstr_ptr &s) { _render_type = s;
00602    if (_impl) _impl->set_rendering(s);}
00603    Cstr_ptr&   rendering()          const { return _render_type; }
00604    int         tris()               const { return _tris; }
00605    double      line_scale()         const { return _line_scale; }
00606    bool        grabbing_screen()    const { return _grabbing_screen; }
00607    void        set_grabbing_screen( bool g) { _grabbing_screen = g; }
00608    SCREENptr   screen()             const { return _screen; }
00609    const SCREEN  *screen_ptr()      const { return &*_screen;}
00610    SCREEN     *screen_ptr()               { return &*_screen;}
00611    bool        is_clipping()        const { return _is_clipping;}
00612    mlib::CWplane    &clip_plane ()        const { return _clip_plane;}
00613    CCOLOR&     color()              const { return _bkgnd_col; }
00614 
00615    ARRAY<STENCILCB*> &stencil_cbs()       { return _stencil_cbs; }
00616    void        add_stencil (STENCILCB *cb){ _stencil_cbs += cb; }
00617    void        rem_stencil (STENCILCB *cb){ _stencil_cbs -= cb; }
00618    void        set_color(CCOLOR &c);
00619    void        set_lens(mlib::CWtransf &l)      { _lens = l; }
00620    mlib::Wtransf     get_lens() { return _lens; }
00621    mlib::Wtransf     get_jitter() { return _jitter; }
00622    void        set_screen(CSCREENptr &s)  { _screen = s; }
00623    void        set_is_clipping(bool clip) { _is_clipping = clip;}
00624    void        set_clip_plane(mlib::CWplane &p) { set_is_clipping(true); 
00625    _clip_plane = p; }
00626    void        set_view_impl(VIEWimpl *i) { _impl = i; }
00627 
00628    int         display  (CGELptr &);
00629    int         undisplay(CGELptr &);
00630    void        notify(CGELptr &g, int f)  { if(f) display(g);else undisplay(g);}
00631 
00632    //!METHS: core functions provided by a view
00633    void        paint           ();
00634    void        setup_lights    (CAMdata::eye e=CAMdata::MIDDLE) {
00635       if (_impl) _impl->setup_lights(e);
00636    }
00637    RAYhit      intersect_others(RAYhit&, CGELlist&,     filt f=H_GEOM) const;
00638    RAYhit      intersect       (mlib::CXYpt  &x,              filt f=H_GEOM) const;
00639    RAYhit      intersect       (RAYhit &r,              filt f=H_GEOM) const;
00640    RAYhit      intersect       (RAYhit &r, GELptr &,    filt f=H_GEOM) const;
00641    RAYhit      intersect       (RAYhit &r, Cstr_ptr &cn,filt f=H_GEOM) const;
00642    RAYhit      intersect       (RAYhit &r, const GELFILTlist &)        const;
00643    RAYnear     nearest         (RAYnear&r,              filt f=H_GEOM) const;
00644    RAYnear     nearest         (RAYnear&r, Cstr_ptr&,   filt f=H_GEOM) const;
00645    GELlist     inside          (mlib::CXYpt_list &lasso) const;
00646 
00647    //!METHS: scissor region accessors/setters
00648    void        set_scissor_flag(int b)    { _has_scissor_region = b;   }
00649    void        set_scissor_xmin(double x) { _sxmin=clamp(x,-1.,1.);
00650    set_scissor_flag(1); }
00651    void        set_scissor_xmax(double x) { _sxmax=clamp(x,-1.,1.);
00652    set_scissor_flag(1); }
00653    int         has_scissor_region() const { return _has_scissor_region;}
00654    double      scissor_xmin()       const { return _sxmin; }
00655    double      scissor_xmax()       const { return _sxmax; }
00656 
00657    //!METHS: viewport specific functions
00658    WINSYS     *win()                 const { return _win; }
00659    int         width()               const { return _width; }
00660    int         height()              const { return _height; }
00661    void        get_size(int&w, int&h)const { w = _width; 
00662    h = (stereo()!=VIEWimpl::HMD) ?
00663       _height : _height/2; }
00664    double      ndc2pix_scale()       const { return min(_width,_height)/2.0; }
00665    double      aspect_x()            const { return (_width>_height) ?
00666                                                 double(_width)/_height : 1.0; }
00667    double      aspect_y()            const { return (_width>_height) ? 1.0 :
00668       double(_height)/_width; }
00669 
00670    // Bring the camera back to where it 
00671    // can see everything in the scene.
00672    // (Useful when the camera gets lost in space):
00673    void viewall();
00674 
00675    static double pix_to_ndc_scale()         { return _views.empty() ? 
00676                                                  1.0 : 1.0/peek()->ndc2pix_scale();}
00677 
00678    //!METHS: interface delegated to an implementation object
00679    int         stencil_draw(STENCILCB *cb, GELlist *objs= 0) { return _impl ? 
00680                                                                   _impl->stencil_draw(cb,objs) : 0; }
00681    void        set_size      (int w, int h, int x, int y);
00682    void        set_cursor    (int i)       { if (_impl) _impl->set_cursor(i); }
00683    int         get_cursor    ()            { return ((_impl)?(_impl->get_cursor()):(-1)); }
00684    void        draw_bb(mlib::CWpt_list &p) const { if (_impl) _impl->draw_bb(p); }
00685 
00686    // Grabs current scene as a hi-res image, scaled n times
00687    // the size of the current window in each dimension:
00688    int         screen_grab(int scale, Cstr_ptr &filename);
00689    void        screen_grab(int scale, Image &im);
00690 
00691    //!METHS: callbacks provided by the view 
00692    void         notify_clearobs()       { for (int i=0; i<_clear_obs.num(); i++)
00693       _clear_obs[i]->notify_clear(this);}
00694    void         clear_obs  (CCLEARobsptr &o) { _clear_obs.add_uniquely(o); }
00695    void         unobs_clear(CCLEARobsptr &o) { _clear_obs.rem(o); }
00696 
00697 
00698    //!METHS: methods for synchronizing multiple views
00699    int         messages_sent()      const  { return _messages_sent;}
00700    void        message_recvd()             { _messages_sent--;}
00701    int         dont_swap()          const  { return _dont_swap; }
00702    int         dont_draw()          const  { return _dont_draw; }
00703    void        swap();
00704    void        set_dont_swap(int f=1)      { _dont_swap = f; }
00705    void        set_dont_draw(int f=1)      { _dont_draw = f; }
00706    void        wait_for_displays(int n)    { assert(!_dont_draw && !_dont_swap);
00707    _messages_sent = n;
00708    if (n > 0) 
00709       _dont_draw = _dont_swap = 1; }
00710 
00711    // Projection matrices:
00712    //   Each returns the matrix to use for drawing 
00713    //   the given type of point to the screen.
00714    mlib::Wtransf wpt_proj(SCREENptr s = SCREENptr(),
00715                           CAMdata::eye e=CAMdata::MIDDLE) const;
00716    mlib::Wtransf xypt_proj()            const;
00717    mlib::Wtransf ndc_proj()             const;
00718    mlib::Wtransf pix_proj()             const;
00719    mlib::Wtransf wpt_to_pix_proj(SCREENptr s = SCREENptr(),
00720                  CAMdata::eye e=CAMdata::MIDDLE) const;
00721 
00722    // The matrix that transforms points from world space to eye space:
00723    mlib::Wtransf world_to_eye(CAMdata::eye e=CAMdata::MIDDLE) const {
00724       return cam()->data()->xform(screen(), e);
00725    }
00726    mlib::Wtransf eye_to_world(CAMdata::eye e=CAMdata::MIDDLE) const {
00727       return world_to_eye(e).inverse();
00728    }
00729 
00730    DEFINE_RTTI_METHODS("VIEW", SCHEDULER, CSCHEDULERptr);
00731 };
00732 
00733 extern VIEWlist  VIEWS;              // List of all views 
00734 extern hashvar<int> DONOT_CLIP_OBJ;  // objs unaffected by clip plane
00735 
00736 // Gives length in pixels of a segment strarting at the wpt given and 
00737 // going in an arbitrary direction by length given, does it by moving
00738 // the point onto a at_vector and then projecting world length
00739 // into PIXEL length
00740 double at_length(mlib::CWpt& p, double length);
00741 
00742 #endif // VIEW_H
00743 
00744 // end of file view.H

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