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"
00011 #include "geom/texture.H"
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
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
00077
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
00114
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,
00126 RIGHT_EYE_MONO,
00127 SCISSOR_STEREO
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) {}
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
00154
00155
00156
00157
00158
00159 #define CHANGED(X) VIEWobs::notify_viewobs(this, X)
00160
00161 class ThreadData;
00162
00163
00164
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
00194
00195 private:
00196 static TAGlist *_v_tags;
00197 protected:
00198 bool _in_data_file;
00199 public:
00200
00201
00202
00203
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
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;
00269
00270
00271 static VIEWlist _views;
00272 static str_list _rend_types;
00273
00274 VIEWimpl *_impl;
00275
00276 static int _num_views;
00277 const int _view_id;
00278
00279 ARRAY<STENCILCB*> _stencil_cbs;
00280
00281 str_ptr _name;
00282 CAMptr _cam;
00283 CAMhist _cam_hist;
00284 int _cam_hist_cur;
00285
00286 GELlist _active;
00287 GELlist _drawn;
00288
00289 int _width;
00290 int _height;
00291 COLOR _bkgnd_col;
00292
00293 stereo_mode _stereo;
00294 str_ptr _render_type;
00295 int _tris;
00296
00297 bool _is_clipping;
00298 mlib::Wplane _clip_plane;
00299
00300 int _dont_swap;
00301 int _dont_draw;
00302 int _messages_sent;
00303
00304 int _has_scissor_region;
00305 double _sxmin, _sxmax;
00306
00307 mlib::Wtransf _lens;
00308
00309
00310
00311 mlib::Wtransf _jitter;
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];
00321 COLOR _light_global_ambient;
00322
00323 static ARRAY<ARRAY<mlib::VEXEL>*> _jitters;
00324
00325
00326 void init_lights();
00327 void init_jitter();
00328
00329 double _alpha;
00330 bool _use_paper;
00331 str_ptr _bkg_file;
00332 TEXTUREptr _bkg_tex;
00333 mlib::Wtransf _bkg_tf;
00334
00335 str_ptr _data_file;
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);
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
00375 void set_bkg_file(str_ptr f) { _bkg_file = f; _bkg_tex = NULL; CHANGED(TEXTURE_CHANGED);}
00376
00377
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
00388
00389
00390 void light_set_global_ambient(CCOLOR &c) {
00391 _light_global_ambient = c;
00392 CHANGED(LIGHTING_CHANGED);
00393 }
00394
00395 COLOR light_get_global_ambient() const {
00396 return _light_global_ambient;
00397 }
00398
00399
00400
00401
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
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
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
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
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
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
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
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
00459
00460
00461 const Light& get_light(int i) const {
00462 assert(0 <= i && i < MAX_LIGHTS);
00463 return _lights[i];
00464 }
00465
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
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
00506
00507 double _line_scale;
00508
00509 bool _grabbing_screen;
00510
00511 double _spf;
00512 stop_watch _spf_timer;
00513 double _frame_time;
00514 static unsigned int _stamp;
00515 static double _pix_to_ndc_scale;
00516
00517
00518
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
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
00569 Recorder* recorder() { return _recorder;}
00570
00571
00572 static mlib::Wpt eye() { return peek_cam()->data()->from(); }
00573
00574 static mlib::Wvec eye_vec(mlib::CWpt& p) { return (p - eye()).normalized(); }
00575
00576
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
00585 void save_cam(CCAMptr c=0);
00586 void fwd_cam_hist();
00587 void bk_cam_hist();
00588
00589
00590 void copy_cam(CCAMptr &c);
00591
00592
00593 void use_cam(CCAMptr &c);
00594
00595 int tick();
00596 int view_id() const { return _view_id; }
00597
00598
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
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
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
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
00671
00672
00673 void viewall();
00674
00675 static double pix_to_ndc_scale() { return _views.empty() ?
00676 1.0 : 1.0/peek()->ndc2pix_scale();}
00677
00678
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
00687
00688 int screen_grab(int scale, Cstr_ptr &filename);
00689 void screen_grab(int scale, Image &im);
00690
00691
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
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
00712
00713
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
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;
00734 extern hashvar<int> DONOT_CLIP_OBJ;
00735
00736
00737
00738
00739
00740 double at_length(mlib::CWpt& p, double length);
00741
00742 #endif // VIEW_H
00743
00744