Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cam_focus.H

Go to the documentation of this file.
00001 #ifndef CAM_FOCUS_H_IS_INCLUDED
00002 #define CAM_FOCUS_H_IS_INCLUDED
00003 
00004 #include "disp/view.H"
00005 
00006 /*****************************************************************
00007  * CamFocus:
00008  *
00009  *      Animates a camera to focus on something
00010  *****************************************************************/
00011 MAKE_PTR_SUBC(CamFocus, FRAMEobs);
00012 class CamFocus : public FRAMEobs {
00013  public :
00014    //******** MANAGERS ********
00015    CamFocus(VIEWptr v, CCAMptr &dest);
00016    CamFocus(VIEWptr v, mlib::CWpt& from, mlib::CWpt& at, mlib::CWpt& up,
00017             mlib::CWpt& center, double fw=0, double fh=0);
00018        
00019    virtual ~CamFocus();
00020 
00021    //******** ACCESSORS ********
00022    VIEWptr view()  const { return _view; }
00023    CAMptr  cam()   const { return _cam; }
00024 
00025    //******** STATIC METHODS ********
00026 
00027    static void cancel_cur();
00028 
00029    //******** FRAMEobs VIRTUAL METHODS ********
00030    virtual int tick(void);
00031 
00032  protected:
00033    //******** DATA MEMBERS ********
00034    VIEWptr      _view;          // the VIEW owning the cam we're animating
00035    CAMptr       _cam;           // the cam we're animating
00036 
00037    double       _width;         // CAMdata parameter (at target)
00038    double       _height;        // CAMdata parameter (at target)
00039 
00040    double       _orig_time; // time (VIEW::frame_time()) when starting CamFocus
00041    double       _last_time; // time (VIEW::frame_time()) of last call to tick()
00042    double       _duration;  // length of time for animation to run
00043 
00044    double       _speed;
00045    double       _max_speed; // max allowable speed for moving camera location
00046 
00047    // camera parameters at start of animation (world coords)
00048    mlib::Wpt     _o1; // "from"
00049    mlib::Wpt     _a1; // "at"
00050    mlib::Wvec    _u1; // "up" vector
00051    mlib::Wpt     _c1; // "center"
00052 
00053    // camera parameters at end of animation
00054    mlib::Wpt     _o2; // "from"
00055    mlib::Wpt     _a2; // "at"
00056    mlib::Wvec    _u2; // "up" vector
00057    mlib::Wpt     _c2; // "center"
00058 
00059    //******** STATIC DATA ********
00060 
00061    static CamFocusptr  _cur; // only 1 instance active at a time
00062 
00063    //******** UTILITIES ********
00064 
00065    // called in the constructor to activate this CamFocus:
00066    void schedule() {
00067       if (view()) {
00068          view()->save_cam();     // allow undo
00069          view()->schedule(this); // sign up for per-frame callbacks
00070       }
00071    }
00072 
00073    // called in the destructor to deactivate this CamFocus:
00074    void unschedule() {
00075       if (view())
00076          view()->unschedule(this);
00077    }
00078 
00079    void set_cur(CamFocus* cf);
00080 
00081    // time utilities:
00082    double cur_time()     const { return VIEW::peek()->frame_time(); }
00083    double elapsed_time() const { return cur_time() - _orig_time; }
00084    double t_param()      const {
00085       // animation parameter:
00086       //   fraction of time used so far, in range [0,1]
00087       return clamp(elapsed_time()/_duration, 0.0, 1.0);
00088    }
00089    double cartoon_t() const;
00090 
00091    // compute cached values during initialization
00092    // input parameters are: from, at, up, and center for final camera
00093    void setup(
00094       mlib::CWpt& o2, mlib::CWpt& a2, mlib::CWvec& u2, mlib::CWpt& c2
00095       );
00096 };
00097 
00098 /*****************************************************************
00099  * CamBreathe:
00100  *
00101  *      Animates a camera to make it seem like it's "breathing"
00102  *****************************************************************/
00103 MAKE_PTR_SUBC(CamBreathe, FRAMEobs);
00104 class CamBreathe : public FRAMEobs {
00105  protected:
00106    CAMptr       _cam;
00107    mlib::Wpt    _from;
00108    mlib::Wpt    _at;
00109    mlib::Wpt    _up;
00110    mlib::Wpt    _cent;
00111    double       _width,_height;
00112    double       _min, _Kf, _Kc, _Ku;
00113    double       _speed;
00114    static double _size;
00115    double       _tick;
00116    bool                 _stop;
00117    bool                 _pause;
00118    const double kKf, kKc, kKu;
00119    static CamBreatheptr  _breathe;
00120 
00121  public :
00122    virtual ~CamBreathe();
00123    CamBreathe(CAMptr &p);
00124 
00125        
00126    virtual int tick(void);
00127    virtual void stop() { _stop = true; }
00128    virtual void pause()  { _pause = true; }
00129    virtual void unpause(){ _pause = false; }
00130    virtual void set_speed(double s) {_speed = s; }
00131    static void grow(double s) { _size += s; }
00132 
00133    virtual bool stopped() { return _stop; }
00134 
00135    static CamBreatheptr &cur()      { return _breathe; }
00136 };
00137 
00138 /*****************************************************************
00139  * CamOrbit:
00140  *
00141  *      Animates a camera to orbit around a object
00142  *****************************************************************/
00143 MAKE_PTR_SUBC(CamOrbit, FRAMEobs);
00144 class CamOrbit : public FRAMEobs {
00145  protected:
00146    CAMptr       _cam;
00147    mlib::Wpt    _from, _at,_up,_cent;
00148    double       _width,_height;
00149    double       _min;
00150    double       _speed;
00151    double       _tick;
00152    bool                 _pause;
00153    bool         _stop;
00154    mlib::XYpt         tp; 
00155    mlib::XYpt         te;
00156    static CamOrbitptr  _orbit;
00157 
00158  public :
00159    virtual ~CamOrbit();
00160    CamOrbit(CAMptr &p, mlib::Wpt center);
00161 
00162        
00163    virtual int tick(void);
00164    virtual void pause() { _pause = true; }
00165    virtual void unpause(){ _pause = false; }
00166    virtual void stop() { _stop = true; }
00167    virtual void set_target(mlib::Wpt p) { _cent = p;}
00168 
00169    virtual void set_orbit(mlib::XYpt o, mlib::XYpt e)
00170       { 
00171          _pause = false;
00172          tp    = o;
00173          te    = e;
00174       }
00175 
00176    virtual bool stopped() { return _stop; }
00177    static CamOrbitptr &cur()      { return _orbit; }
00178 };
00179 
00180 /*****************************************************************
00181  * CamCruise:
00182  *
00183  *      Animates a camera to Cruise around a object
00184  *****************************************************************/
00185 MAKE_PTR_SUBC(CamCruise, FRAMEobs);
00186 class CamCruise : public FRAMEobs {
00187  protected:
00188    CAMptr       _cam;
00189    double               _t;
00190    mlib::Wpt    _from, _at,_up,_cent;
00191    double       _width,_height;
00192    double       _min;
00193    double       _speed;
00194    double       _tick;
00195    static double _size;
00196    bool                 _pause;
00197    bool         _stop;
00198    bool                 _target;
00199    bool                 _travel;
00200    mlib::Wpt    _start;
00201    mlib::Wpt    _dest;
00202    mlib::XYpt   _scale_pt;
00203    mlib::Wpt    _down_pt;
00204    mlib::XYpt         tp; 
00205    mlib::XYpt         te;
00206 
00207    stop_watch    _clock;      // clock measuring time
00208    static CamCruiseptr  _cruise;
00209 
00210  public :
00211    virtual ~CamCruise();
00212    CamCruise(CAMptr &p, mlib::Wpt center);
00213 
00214        
00215    virtual int tick(void);
00216    virtual void pause() { _pause = true; }
00217    virtual void unpause(){ _pause = false; }
00218    virtual void stop() { _stop = true; }
00219    virtual void speed(double i) { _speed = i; }
00220    static void grow(double s) { _size += s; }
00221 
00222    //virtual void unset_target() { _target = false;}
00223    virtual void travel(mlib::Wpt p);
00224    virtual void set_cruise(mlib::XYpt o, mlib::XYpt e);
00225 
00226 
00227    virtual void set_scale_pt(mlib::XYpt s) { _scale_pt = s; }
00228    virtual void set_down_pt(mlib::Wpt d) { _down_pt = d; }
00229    
00230    virtual double get_speed() {return _speed;}
00231    virtual bool stopped() { return _stop; }
00232    static CamCruiseptr &cur()      { return _cruise; }
00233 };
00234 
00235 #endif // CAM_FOCUS_H_IS_INCLUDED
00236 
00237 // end of file cam_focus.H 

Generated on Mon Sep 18 11:39:29 2006 for jot by  doxygen 1.4.4