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

but_track.H

Go to the documentation of this file.
00001 #ifndef GLUE_BUT_TRACK_H
00002 #define GLUE_BUT_TRACK_H
00003 
00004 #include "event/event.H"
00005 #include "dev/dev.H"
00006 #include "dev/room6d.H"
00007 #include "dev/buttons.H"
00008 #include "mlib/points.H"
00009 #include "mlib/math_translate.H"
00010 
00011 extern DllImpExp cWtransf &Identity;
00012 
00013 class DEVbtn_tracker_agg: public EVENTfilter {
00014      str_ptr        _hname, _tname, _bname;
00015      DEVice_room6d *_head;
00016      DEVice_room6d *_tkr;
00017      DEVice        *_btn;     // possible real source of button events
00018      EVENTsource    _btn_src; // cached description of button event source
00019 
00020      bool     button_evt(cEVENTptr &evt) { 
00021            if (!_btn && !(_btn = DEVice::lookup(_bname)) && evt->debug_on())
00022           cerr <<"DEVbtn_tracker_agg: can't find button device "
00023                << _bname << endl;
00024            return _btn_src.test(*evt->source()) && EVENTbtn::isa(evt); }
00025      cWtransf &cur_tracker(bool dbg) { 
00026                if (!_tkr&&!(_tkr=(DEVice_room6d*)DEVice::lookup(_tname))&&dbg)
00027                   cerr << "DEVbtn_tracker_agg: can't find tracker device "
00028                    << _tname << endl; 
00029            return _tkr ? _tkr->cur() : Identity; }
00030      cWtransf &cur_head(bool dbg) { 
00031                if(!_head &&!(_head=(DEVice_room6d*)DEVice::lookup(_hname))&&dbg)
00032               cerr<<"DEVbtn_tracker_agg: can't find head device "
00033               << _hname << endl; 
00034            return _head ? _head->cur() : Identity; }
00035    public:
00036       DEVbtn_tracker_agg(Cstr_ptr &h, Cstr_ptr &t, Cstr_ptr &b):
00037                  _hname(h),_tname(t),_bname(b),_head(0),_tkr(0),_btn(0),
00038          _btn_src(_bname,0)    { }
00039       virtual ~DEVbtn_tracker_agg()    { }
00040 
00041       EVENTptr filter(cEVENTptr &evt) {
00042      if (button_evt(evt)) {
00043         EVENTbtnptr btn = EVENTbtn::cast(evt);
00044             Wtransf r2w(MathTranslate::instance() ? 
00045                          MathTranslate::instance()->ROOM_TO_WORLD() : Identity);
00046             if (!MathTranslate::instance())
00047                cerr << "DEVbtn_tracker_agg::filter - Warning, no MathTranslate instance is available" << endl;
00048 
00049             // XXX: This isn't really very safe...
00050             // we need to make static variables out of the head and tracker
00051             // world matrices because EVENTbtn_vr receives its parameters as 
00052             // references.   
00053             static Wtransf world_head_xf;
00054             static Wtransf world_tkr_xf;
00055             world_head_xf = r2w * cur_head(evt->debug_on());
00056             world_tkr_xf  = r2w * cur_tracker(evt->debug_on());
00057             return new EVENTbtn_vr(btn->source(), 
00058                    world_head_xf,
00059                    world_tkr_xf,
00060                                    btn->transition());
00061      }
00062      return evt;
00063       }
00064 };
00065 
00066 #endif

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18