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

proximityBtnFltr.H

Go to the documentation of this file.
00001 #ifndef GLUE_PROXIMITYBTNFLTR_H
00002 #define GLUE_PROXIMITYBTNFLTR_H
00003 
00004 #define OUTSIDE_GLUE_CORE
00005 
00006 #include "event/event.H"
00007 #include "dev/dev.H"
00008 #include "dev/room6d.H"
00009 #include "dev/buttons.H"
00010 #include "mlib/points.H"
00011 #include <math.h>
00012 #include "config/config.H"
00013 
00014 
00015 class proximityBtnFilt:public EVENTfilter
00016 {
00017 protected:
00018   str_ptr _name;
00019   str_ptr _btnNear;
00020   str_ptr _btnFar;
00021   str_ptr _btn;
00022   str_ptr _tracker1;
00023   str_ptr _tracker2;
00024   Wpt _t1Pos;
00025   Wpt _t2Pos;
00026   double _distance;
00027 public:
00028   proximityBtnFilt(str_ptr name):_name(name){
00029     _btn=CONFIGval(_name+str_ptr("_btn"),"",true);
00030     _tracker1=CONFIGval(_name+str_ptr("_tracker1"),"",true);
00031     _tracker2=CONFIGval(_name+str_ptr("_tracker2"),"",true);
00032     _btnNear=CONFIGval(_name+str_ptr("_near"),_btn+str_ptr("_near"),true);
00033     _btnFar=CONFIGval(_name+str_ptr("_far"),_btn+str_ptr("_far"),true);
00034     _distance=CONFIGval(_name+str_ptr("_distance"),0.5,true);
00035   }
00036   
00037   EVENTptr filter(cEVENTptr &evt){
00038     if (evt){
00039       if (EVENTroom6d::isa(evt)){
00040     EVENTroom6dptr r6d=EVENTroom6d::cast(evt);
00041     if (r6d){
00042       if (evt->source()->evt_name()==_tracker1){
00043         _t1Pos=r6d->cur().origin();
00044       }
00045       if (evt->source()->evt_name()==_tracker2){
00046         _t2Pos=r6d->cur().origin();
00047       }
00048     }
00049       }else if (EVENTbtn::isa(evt)){
00050     EVENTbtnptr btnevent=EVENTbtn::cast(evt);
00051     if (btnevent){
00052       //cout << "have a button event\n";
00053       if (evt->source()->evt_name()==_btn){
00054         //cout << "it is our button\n";
00055         if (sqrt((_t1Pos[0]-_t2Pos[0])*(_t1Pos[0]-_t2Pos[0])+
00056              (_t1Pos[1]-_t2Pos[1])*(_t1Pos[1]-_t2Pos[1])+
00057              (_t1Pos[2]-_t2Pos[2])*(_t1Pos[2]-_t2Pos[2]))<_distance){
00058           //cout << "it was near\n";
00059           //send out the old evt as well
00060           //EVENTmgr::distrib(evt);
00061           //return new EVENTbtn(_btnNear,btnevent->transition());
00062           EVENTmgr::distrib(new EVENTbtn(_btnNear,btnevent->transition()));
00063         }else{
00064           //cout << "it was far\n";
00065           //EVENTmgr::distrib(evt);
00066           //return new EVENTbtn(_btnFar,btnevent->transition());
00067           EVENTmgr::distrib(new EVENTbtn(_btnFar,btnevent->transition()));
00068         }
00069       }
00070     }
00071       }
00072     }
00073     return evt;
00074   }
00075 };
00076           
00077       
00078 #endif

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