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

ManipEvents.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 //                           2003
00014 ///////////////////////////////////////////////////////////////////////////
00015 
00016 //ManipEvents.h
00017 // Joe Kniss
00018 
00019 #ifndef __MANIPULATOR_EVENTS_DOT_H
00020 #define __MANIPULATOR_EVENTS_DOT_H
00021 
00022 #include "ManipEventBase.h"
00023 #include "Manip.h"
00024 
00025 namespace gutz {
00026 
00027 typedef ManipEventBase<Manip>        ManipEvent;
00028 typedef gutz::SmartPtr< ManipEvent > ManipEventSP;
00029 
00030 ///////////////////////////////////////////////////////////////////////////
00031 /// Rotate Manip Event.  Rotates a manipulator about its center of
00032 /// rotation.  
00033 ///////////////////////////////////////////////////////////////////////////
00034 class RotateManipEvent : public ManipEventBase<Manip> {
00035 public:
00036    RotateManipEvent(float speed = 1.0f)
00037       : ManipEventBase<Manip>(speed), _tumbquat(quatf_id) {}
00038    RotateManipEvent(const RotateManipEvent &mre)
00039       : ManipEventBase<Manip>(mre), _tumbquat(mre._tumbquat)
00040    {}
00041    virtual ~RotateManipEvent() {}
00042 
00043    RotateManipEvent &operator=(const RotateManipEvent &mre)
00044    { ManipEventBase<Manip>::operator =(mre); return *this; 
00045      _tumbquat = mre._tumbquat;
00046    }
00047 
00048    virtual ManipEventBase<Manip> *clone() const { return new RotateManipEvent(*this); }
00049 
00050    ///@name Event Handlers
00051    ///@{
00052 
00053    /// should be called on a Mouse-down event, starts the event
00054    bool startEvent(Manip *m, const MouseEvent &me);
00055    /// should be called when the mouse moves
00056    bool handleEvent(Manip *m, const MouseMoveEvent &mme);
00057    /// called when the event is over, may or may not be on a Mouse-up event
00058    void endEvent(Manip *m, const MouseEvent &me);
00059    /// repeat last event
00060    bool tumble(Manip *m);
00061    ///@}
00062 
00063 protected:
00064    float _rad;
00065    quatf _tumbquat;
00066 };
00067 
00068 ///////////////////////////////////////////////////////////////////////////
00069 /// Translate XY Manip Event.  Translates the manipulator in X&Y relative
00070 ///  to the current view. This is also a base class for other translation
00071 ///  events.
00072 ///////////////////////////////////////////////////////////////////////////
00073 
00074 class TransXYManipEvent : public ManipEventBase<Manip> {
00075 public:
00076    TransXYManipEvent(float speed = 1.0f)
00077       : ManipEventBase<Manip>(speed), _lastTrans(vec3f_zero)
00078    {}
00079    TransXYManipEvent(const TransXYManipEvent &tme)
00080       : ManipEventBase<Manip>(tme), _lastTrans(vec3f_zero)
00081    {}
00082    virtual ~TransXYManipEvent() {}
00083 
00084    TransXYManipEvent &operator=(const TransXYManipEvent &tme)
00085    {  ManipEventBase<Manip>::operator =(tme); 
00086       _lastTrans = vec3f_zero;
00087       return *this; 
00088    }
00089 
00090    /// be sure to override this in any sub-classes
00091    virtual ManipEventBase<Manip> *clone() const { return new TransXYManipEvent(*this); }
00092 
00093    ///@name Event Handlers
00094    ///@{
00095 
00096    /// should be called on a Mouse-down event, starts the event
00097    bool startEvent(Manip *m, const MouseEvent &me);
00098    /// should be called when the mouse moves
00099    bool handleEvent(Manip *m, const MouseMoveEvent &mme);
00100    /// called when the event is over, may or may not be on a Mouse-up event
00101    void endEvent(Manip *m, const MouseEvent &me);
00102    /// repeat last event
00103    bool tumble(Manip *m);
00104    ///@}
00105 
00106 protected:
00107    /// returns the translaton for this local frame (actually defined in parent's space)
00108    vec3f getDelta(Manip *m, const MouseMoveEvent &mme) const;
00109 
00110    vec3f _lastTrans;
00111 };
00112 
00113 ///////////////////////////////////////////////////////////////////////////
00114 /// Translate Z Manip Event.  Translates the manipulator in Z relative
00115 ///  to the current view (along the view direction)
00116 ///////////////////////////////////////////////////////////////////////////
00117 
00118 class TransZManipEvent : public TransXYManipEvent {
00119 public:
00120    TransZManipEvent(float speed = 1.0f)
00121       : TransXYManipEvent(speed)
00122    {}
00123    TransZManipEvent(const TransZManipEvent &tme)
00124       : TransXYManipEvent(tme)
00125    {}
00126    virtual ~TransZManipEvent() {}
00127 
00128    TransZManipEvent &operator=(const TransZManipEvent &tme)
00129    {  TransXYManipEvent::operator =(tme); 
00130       return *this; 
00131    }
00132 
00133    virtual ManipEventBase<Manip> *clone() const { return new TransZManipEvent(*this); }
00134 
00135    ///@name Event Handlers
00136    ///@{
00137    /// should be called when the mouse moves
00138    bool handleEvent(Manip *m, const MouseMoveEvent &mme);
00139    ///@}
00140 
00141 protected:
00142 };
00143 
00144 ///////////////////////////////////////////////////////////////////////////
00145 /// Translate in Plane.  Translates only in a user-defined plane.  
00146 ///  This class "HAS_SLOTS" so that the plane can be defined dynamically.
00147 ///  See gutz::Signal for more info on Signals & Slots.  The plane is 
00148 ///  defined in WORLD space.
00149 ///////////////////////////////////////////////////////////////////////////
00150 
00151 class TransPlaneManipEvent : public TransXYManipEvent {
00152 public:
00153    HAS_SLOTS;
00154 
00155    TransPlaneManipEvent(gutz::vec3f ppos = vec3f_zero, 
00156                         gutz::vec3f pnorm = vec3f_z, 
00157                         float speed = 1.0f)
00158                         : TransXYManipEvent(speed), _ppos(ppos), _pnorm(pnorm)
00159    {}
00160    TransPlaneManipEvent(const TransPlaneManipEvent &tpme)
00161       : TransXYManipEvent(tpme), _ppos(tpme._ppos), _pnorm(tpme._pnorm)
00162    {}
00163    virtual ~TransPlaneManipEvent() {}
00164 
00165    TransPlaneManipEvent &operator=(const TransPlaneManipEvent &tpme)
00166    {
00167       TransXYManipEvent::operator =(tpme);
00168       _ppos = tpme._ppos;
00169       _pnorm = tpme._pnorm;
00170    }
00171 
00172    virtual ManipEventBase<Manip> *clone() const { return new TransPlaneManipEvent(*this); }
00173 
00174    ///////////////////////////////
00175    ///@name Set/Get Plane 
00176    ///   The plane should be set in WORLD space 
00177    ///@{
00178    void setPlane(const gutz::planef &pln)
00179    {  _ppos = pln.p; _pnorm = pln.n; }
00180    void        setPlanePos( const gutz::vec3f &ppos)   { _ppos = ppos; }
00181    gutz::vec3f getPlanePos() const                     { return _ppos; }
00182    void        setPlaneNorm( const gutz::vec3f &pnorm) { _pnorm = pnorm; }
00183    gutz::vec3f getPlaneNorm()const                     { return _pnorm; }
00184    ///@}
00185    ///////////////////////////////
00186 
00187    ///@name Event Handlers
00188    ///@{
00189    bool startEvent(Manip *m, const MouseEvent &me);
00190    /// should be called when the mouse moves
00191    bool handleEvent(Manip *m, const MouseMoveEvent &mme);
00192    ///@}
00193 
00194 protected:
00195    gutz::vec3f _start;
00196    gutz::vec3f _ppos;
00197    gutz::vec3f _pnorm;
00198 
00199 };
00200 
00201 
00202 } /// end namespace gutz
00203 
00204 
00205 #endif
00206 
00207 

Send questions, comments, and bug reports to:
jmk