arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

mouseEvent.h

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////
00002 //              _____________  ______________________    __   __  _____
00003 //             /  ________  |  |   ___   ________   /   |  \ /  \   |
00004 //            |  |       |  |_ |  |_ |  |       /  /    \__  |      |
00005 //            |  |  ___  |  || |  || |  |      /  /        | |      |
00006 //            |  | |   \ |  || |  || |  |     /  /      \__/ \__/ __|__
00007 //            |  | |_@  ||  || |  || |  |    /  /          Institute
00008 //            |  |___/  ||  ||_|  || |  |   /  /_____________________
00009 //             \_______/  \______/ | |__|  /___________________________
00010 //                        |  |__|  |
00011 //                         \______/
00012 //                    University of Utah       
00013 //                           2002
00014 ///////////////////////////////////////////////////////////////////////////
00015 
00016 //mouseEvent.h
00017 
00018 #ifndef __GUTZ_MOUSE_EVENT_DOT_H
00019 #define __GUTZ_MOUSE_EVENT_DOT_H
00020 
00021 #include <mathGutz.h>
00022 #include "gutzKeyMouse.h"
00023 #include "cameraEvent.h"
00024 
00025 namespace gutz {
00026 
00027 ///////////////////////////////////////////////////////////////////////////
00028 /// MouseEvent, the mouse went down or up...
00029 ///   Don't forget, part of this interface is in the 
00030 ///   CameraEvent.
00031 ///////////////////////////////////////////////////////////////////////////
00032 
00033 class MouseEvent : public CameraEvent {
00034 public:
00035    typedef std::vector<unsigned int> DataVec;
00036 
00037    /// standard init. camera and manip are optional, but
00038    ///  they proabaly should be required!
00039    MouseEvent( const vec3f &pos, bool down, unsigned int button,
00040                const CameraSP camera=0, const ManipSP manip=0)
00041       : CameraEvent(camera,manip), _pos(pos), _down(down), _button(button)
00042    {setWorldPos();}
00043    /// init with data vec
00044    MouseEvent(const vec3f &pos, bool down, unsigned int button, 
00045               const DataVec &dv,
00046               const CameraSP camera=0, const ManipSP manip=0)
00047       : CameraEvent(camera,manip), _pos(pos), pickData(dv), _down(down), _button(button)
00048    {setWorldPos();}
00049    /// init with data vec from unsigned int*
00050    MouseEvent(const vec3f &pos, bool down, unsigned int button, 
00051               const unsigned int *dv, int dataSize,
00052               const CameraSP camera=0, const ManipSP manip=0)
00053       : CameraEvent(camera,manip), _pos(pos), _down(down), _button(button)
00054    {
00055       setWorldPos();
00056       pickData.resize(dataSize);
00057       for(int i=0; i<dataSize; ++i)
00058          pickData[i] = dv[i];
00059    }
00060    /// using default copy and assignment
00061    virtual ~MouseEvent() {}
00062 
00063    ////////////////////////////////////////////////////////////
00064    /// @name GUTZ_MOUSE_BUTTON <gutzKeyMouse.h>
00065    ///@{
00066    unsigned int   getButton() const         { return _button; }
00067    void           setButton(unsigned int b) { _button = b; }
00068    ///@}
00069 
00070    ////////////////////////////////////////////////////////////
00071    /// @name is the button down or up?
00072    ///@{
00073    bool           isButtonDown() const    { return _down; }
00074    void           setButtonDown(bool yes) { _down = yes; }
00075    ///@}
00076 
00077    ////////////////////////////////////////////////////////////
00078    /// @name current SCREEN SPACE position
00079    ///@{
00080    float        x()      const           { return _pos.x; }
00081    float        y()      const           { return _pos.y; }
00082    float        z()      const           { return _pos.z; }
00083    vec3f        getPos() const           { return _pos; }
00084    virtual void setPos(const vec3f &pos) { _pos = pos; setWorldPos(); }
00085    /// this is convenient since the z pos can't be known till
00086    /// something is "picked", unless you set it (z) to zero which
00087    /// indicates picking on the "near clip", or image plane.
00088    ///  usually, z is in the range [0,1]: 0 =near clip, 1 =far clip
00089    void         setZ(const float zp)     { _pos.z = zp; setWorldPos(); }
00090    ///@}
00091 
00092    ////////////////////////////////////////////////////////////
00093    ///@name current WORLD SPACE position
00094    ///@{
00095    vec3f        getWorldPos() const      { return _wpos; }
00096    ///@}
00097 
00098    ////////////////////////////////////////////////////////////
00099    /// @name Pick Data.
00100    ///@{
00101    /// public data
00102    /// data/ids associated with mouse event, currently used for
00103    ///  gl style picking name ids.
00104    DataVec  pickData;
00105 
00106    void resetPickData()
00107    {
00108       pickData.resize(0);
00109    }
00110    void setPickData(const DataVec &dv)
00111    {
00112       pickData.resize(dv.size());
00113       for(int i=0; i< int(dv.size()); ++i)
00114          pickData[i] = dv[i];
00115    }
00116    void setPickData(const unsigned int *dv, int dvSize)
00117    {
00118       pickData.resize(dvSize);
00119       for(int i=0; i<dvSize; ++i)
00120          pickData[i] = dv[i];
00121    }
00122    ///@}
00123    ////////////////////////////////////////////////////////////
00124 
00125 protected:
00126    /// set the world pos based on the screen pos
00127    void setWorldPos() 
00128    {
00129       if(!_cam)
00130       {
00131          _wpos = _pos;
00132          return;
00133       }
00134       _wpos = _cam->getPickPos(_pos);
00135    }
00136 
00137    MouseEvent(); /// not used
00138    unsigned int _button;
00139    bool         _down;
00140    gutz::vec3f  _pos;  ///< screen space postion
00141    gutz::vec3f  _wpos; ///< world space position
00142 };
00143 
00144 typedef gutz::SmartPtr<MouseEvent> MouseEventSP;
00145 
00146 ///////////////////////////////////////////////////////////////////////////
00147 /// MouseMoveEvent, the mouse is moving.  
00148 ///   Be sure to look up the hierarchy for more interface stuff... 
00149 ///////////////////////////////////////////////////////////////////////////
00150 
00151 class MouseMoveEvent : public MouseEvent {
00152 public:
00153    MouseMoveEvent(const vec3f &pos, const vec3f &last,
00154                   bool down = true, unsigned int button = gutz::GUTZ_BUTTON_NONE,
00155                   const CameraSP cam=0, const ManipSP manip=0)
00156       : MouseEvent(pos, down, button, cam, manip), _last(last)
00157    {setWorldLast();}
00158    /// for initallizing from a preceeding MouseEvent
00159    MouseMoveEvent(const MouseEvent &me, const vec3f &curPos)
00160       : MouseEvent(curPos, me.isButtonDown(), me.getButton(), me.pickData, 
00161                    me.getCamera(), me.getManip()),
00162         _last(me.getPos())
00163    {setWorldLast();}
00164    /// using default copy and assignment
00165    virtual ~MouseMoveEvent() {}
00166 
00167    /// update current position, copies old pos to last pos, then sets current.
00168    void setPos(const vec3f &pos)       
00169    { _last = getPos(); _wlast = getWorldPos(); MouseEvent::setPos(pos); }
00170 
00171    ////////////////////////////////////////////////////////////
00172    /// @name screen space delta from last move event
00173    ///@{
00174    float       dx()     const          { return _pos.x - _last.x; }
00175    float       dy()     const          { return _pos.y - _last.y; }
00176    float       dz()     const          { return _pos.z - _last.z; }
00177    vec3f       getDel() const          { return _pos - _last; }
00178    ///@}
00179 
00180    /// world space delta.
00181    vec3f       getWorldDel() const     { return _wpos - _wlast; }
00182 
00183    ////////////////////////////////////////////////////////////
00184    /// @name screen space position at last move event
00185    ///@{
00186    float       lx()     const          { return _last.x; }
00187    float       ly()     const          { return _last.y; }
00188    float       lz()     const          { return _last.z; }
00189    vec3f       getLast()const          { return _last; }
00190    void        setLast(const vec3f &l) { _last = l; setWorldLast(); }
00191    ///@}
00192 
00193    /// world space last position
00194    vec3f       getWorldLast() const          { return _wlast; }
00195 
00196 protected:
00197    void        setWorldLast() 
00198    {
00199       if(!_cam)
00200       {
00201          _wlast = _last;
00202          return;
00203       }
00204       _wlast = _cam->getPickPos(_last); 
00205    }
00206 
00207 
00208    MouseMoveEvent(); /// not used
00209    vec3f _last;
00210    vec3f _wlast;
00211 
00212 };
00213 
00214 typedef gutz::SmartPtr<MouseMoveEvent> MouseMoveEventSP;
00215 
00216 } //< end namespace gutz
00217 
00218 #endif
00219 
00220 

Send questions, comments, and bug reports to:
jmk