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

cam_fp.C

Go to the documentation of this file.
00001 #include "disp/ray.H"
00002 #include "geom/world.H"
00003 #include "gtex/smooth_shade.H"  // used in CAMwidget_anchor
00004 #include "mesh/lmesh.H"
00005 #include "std/time.H"
00006 #include "manip/cam_fp.H"
00007 
00008 using namespace mlib;
00009  
00010 static double DOT_DIST = 0.012; // cheesy XY-space distance threshold
00011 
00012 //ARRAY<CamIcon *> CamIcon::_icons;
00013 //CamIcon         *CamIcon::_orig_icon;
00014 /*
00015   CamIcon *
00016   CamIcon::intersect_all(CXYpt &pt)
00017   {
00018   CamIcon *icon = 0;
00019   for (int i = 0; !icon && i < _icons.num(); i++)
00020   if (_icons[i]->intersect_icon(pt)) 
00021   icon = _icons[i];
00022   return icon;
00023   }
00024 */
00025 /*****************************************************************
00026  * CAMwidget_anchor:
00027  *
00028  *      Class used for those blue "camera balls"
00029  *****************************************************************/
00030 MAKE_PTR_SUBC(CAMwidget_anchor, GEOM);
00031 class CAMwidget_anchor : public GEOM {
00032  public:
00033    CAMwidget_anchor() : GEOM() {
00034       // Start with an empty LMESH:
00035       LMESHptr mesh = new LMESH();
00036 
00037       // Ensure mesh knows its containing GEOM:
00038       mesh->set_geom(this);
00039 
00040       // Make a ball shape
00041       mesh->Icosahedron();
00042       mesh->refine();           // smooth it once
00043 
00044       // Regardless of current rendering mode,
00045       // always use Gouraud shading:
00046       mesh->set_render_style(SmoothShadeTexture::static_name());
00047 
00048       // Color the Patch blue:
00049       mesh->patch(0)->set_color(COLOR(0.1, 0.1, 0.9));
00050 //      mesh->patch(0)->set_transp(0.9);
00051 
00052       // Store the mesh:
00053       _body = mesh;
00054 
00055       set_name("CAMwidget_anchor");
00056    }
00057 
00058    // We're not in the picking game:
00059    virtual int draw_vis_ref() { return 0; }
00060 
00061    virtual bool needs_blend() const { return false; }
00062 };
00063 
00064 /*****************************************************************
00065  *
00066  *  Cam_int_fp : the camera interactor
00067  *
00068  * The interactor is initiated when one of the _entry arcs  
00069  * occurs.  The primary entry event calls the down() function which 
00070  * rotates the camera. 
00071  *
00072  *****************************************************************/
00073 Cam_int_fp::Cam_int_fp(
00074    CEvent    &down_ev,
00075    CEvent    &move_ev, 
00076    CEvent    &up_ev,   // up_ev,
00077 
00078    CEvent    &down2_ev, 
00079    CEvent    &up2_ev, 
00080 
00081    CEvent    &rot_down_ev,
00082    CEvent    &trans_down_ev,
00083    CEvent    &zoom_down_ev,
00084 
00085    CEvent    &rot_up_ev,
00086    CEvent    &trans_up_ev,
00087    CEvent    &zoom_up_ev
00088    )
00089 {
00090    //_size = 1;_height = 6;_regularity = 20;min_dist = 0.35;
00091    //_collision = new Collide(1,6,20,.35);
00092    //Collide       colli = new Collide(1,6,20,.35);// = BaseCollide::instance(); 
00093         
00094 
00095    //create key events
00096    Event  for_up(NULL, Evd('8', KEYU));
00097    Event  for_down(NULL, Evd('8', KEYD));
00098    Event  back_up(NULL, Evd('2', KEYU));
00099    Event  back_down(NULL, Evd('2', KEYD));
00100    Event  left_up(NULL, Evd('4', KEYU));
00101    Event  left_down(NULL, Evd('4', KEYD));
00102    Event  right_up(NULL, Evd('6', KEYU));
00103    Event  right_down(NULL, Evd('6', KEYD));
00104    Event  breathe(NULL, Evd('5', KEYD));
00105    Event  orbit(NULL, Evd('9', KEYD));
00106    Event  toggle(NULL, Evd('Y', KEYD));
00107 
00108    //events possible while moving foward
00109    _cam_forward += Arc(for_up,   Cb(&Cam_int_fp::moveup,    (State *)-1));
00110    _cam_forward += Arc(for_down, Cb(&Cam_int_fp::forward));
00111    _cam_forward += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_cam_rot));
00112 
00113    //events possible while moving backward
00114    _cam_back    += Arc(back_up,   Cb(&Cam_int_fp::moveup,    (State *)-1));
00115    _cam_back    += Arc(back_down, Cb(&Cam_int_fp::back));
00116    _cam_back    += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_cam_rot));
00117 
00118    //events possible while moving left
00119    _cam_left    += Arc(left_up,   Cb(&Cam_int_fp::moveup,    (State *)-1));
00120    _cam_left    += Arc(left_down, Cb(&Cam_int_fp::left));
00121    _cam_left    += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_cam_rot));
00122 
00123    //events possible while moving right
00124    _cam_right   += Arc(right_up,   Cb(&Cam_int_fp::moveup,    (State *)-1));
00125    _cam_right   += Arc(right_down, Cb(&Cam_int_fp::right));
00126    _cam_right   += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_cam_rot));
00127 
00128    //events possible while rotating the camera
00129    _cam_rot    += Arc(move_ev, Cb(&Cam_int_fp::rot));
00130    _cam_rot    += Arc(up_ev,   Cb(&Cam_int_fp::up,    (State *)-1));
00131    _cam_rot    += Arc(up2_ev,  Cb(&Cam_int_fp::up,    (State *)-1));
00132 
00133    _cam_rot    += Arc(for_up,   Cb(&Cam_int_fp::moveup));
00134    _cam_rot    += Arc(for_down, Cb(&Cam_int_fp::forward));
00135 
00136    _cam_rot    += Arc(back_up,   Cb(&Cam_int_fp::moveup));
00137    _cam_rot    += Arc(back_down, Cb(&Cam_int_fp::back));
00138 
00139    _cam_rot    += Arc(left_up,   Cb(&Cam_int_fp::moveup));
00140    _cam_rot    += Arc(left_down, Cb(&Cam_int_fp::left));
00141 
00142    _cam_rot    += Arc(right_up,   Cb(&Cam_int_fp::moveup));
00143    _cam_rot    += Arc(right_down, Cb(&Cam_int_fp::right));
00144 
00145    //evens possible while the camera is orbiting
00146    _orbit      += Arc(orbit,     Cb(&Cam_int_fp::stop_orbit, (State *)-1));
00147    _orbit      += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_cam_choose));//&_orb_rot));
00148    _orbit      += Arc(down2_ev,   Cb(&Cam_int_fp::down2));
00149    _orbit          += Arc(toggle,   Cb(&Cam_int_fp::toggle_buttons));
00150 
00151    _cam_choose += Arc(move_ev, Cb(&Cam_int_fp::choose));
00152    _cam_choose += Arc(up_ev,   Cb(&Cam_int_fp::up,    &_orbit));
00153 
00154    _orb_rot    += Arc(move_ev, Cb(&Cam_int_fp::orbit_rot));
00155    _orb_rot    += Arc(up_ev,   Cb(&Cam_int_fp::orbit_rot_up,    &_orbit));
00156    _orb_zoom   += Arc(move_ev, Cb(&Cam_int_fp::orbit_zoom));
00157    _orb_zoom   += Arc(up_ev,   Cb(&Cam_int_fp::up,   &_orbit));
00158 
00159    //events possible while "breathing"
00160    /*
00161      _breathe      += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_breathe_rot));
00162      _breathe      += Arc(down2_ev,   Cb(&Cam_int_fp::down2));
00163   
00164      _breathe      += Arc(for_down,  Cb(&Cam_int_fp::forward));
00165      _breathe      += Arc(for_up,    Cb(&Cam_int_fp::moveup));
00166      _breathe      += Arc(back_down, Cb(&Cam_int_fp::back));
00167      _breathe      += Arc(back_up,   Cb(&Cam_int_fp::moveup));
00168      _breathe      += Arc(left_down, Cb(&Cam_int_fp::left));
00169      _breathe      += Arc(left_up,   Cb(&Cam_int_fp::moveup));
00170      _breathe      += Arc(right_down,Cb(&Cam_int_fp::right));
00171      _breathe      += Arc(right_up,   Cb(&Cam_int_fp::moveup));
00172 
00173      _breathe_rot    += Arc(move_ev, Cb(&Cam_int_fp::rot));
00174      _breathe_rot    += Arc(up_ev,   Cb(&Cam_int_fp::up,    &_breathe));
00175      _breathe_rot    += Arc(for_down,  Cb(&Cam_int_fp::forward));
00176      _breathe_rot    += Arc(for_up,    Cb(&Cam_int_fp::moveup));
00177      _breathe_rot    += Arc(back_down, Cb(&Cam_int_fp::back));
00178      _breathe_rot    += Arc(back_up,   Cb(&Cam_int_fp::moveup));
00179      _breathe_rot    += Arc(left_down, Cb(&Cam_int_fp::left));
00180      _breathe_rot    += Arc(left_up,   Cb(&Cam_int_fp::moveup));
00181      _breathe_rot    += Arc(right_down,Cb(&Cam_int_fp::right));
00182      _breathe_rot    += Arc(right_up,   Cb(&Cam_int_fp::moveup));
00183 
00184      _breathe      += Arc(breathe,   Cb(&Cam_int_fp::stop_breathe, (State *)-1));
00185    */
00186 
00187    //events possible while in cruise control
00188    _cruise      += Arc(down_ev,   Cb(&Cam_int_fp::cruise_down));
00189    _cruise      += Arc(down2_ev,   Cb(&Cam_int_fp::down2));
00190    /*
00191      _cruise      += Arc(for_down,  Cb(&Cam_int_fp::forward));
00192      _cruise      += Arc(for_up,    Cb(&Cam_int_fp::moveup));
00193      _cruise      += Arc(back_down, Cb(&Cam_int_fp::back));
00194      _cruise      += Arc(back_up,   Cb(&Cam_int_fp::moveup));*/
00195    _cruise      += Arc(toggle,   Cb(&Cam_int_fp::toggle_buttons));
00196 
00197    _cruise_rot    += Arc(move_ev, Cb(&Cam_int_fp::rot));
00198    _cruise_rot    += Arc(up_ev,   Cb(&Cam_int_fp::up,    &_cruise));
00199 
00200    _cruise_zoom    += Arc(move_ev, Cb(&Cam_int_fp::cruise_zoom));
00201    _cruise_zoom    += Arc(up_ev,   Cb(&Cam_int_fp::cruise_zoom_up,  &_cruise));
00202 
00203    //events possible while in grow mode
00204 
00205    _grow                   += Arc(down_ev,   Cb(&Cam_int_fp::grow, &_grow_down));
00206    _grow               += Arc(down2_ev,   Cb(&Cam_int_fp::down2));
00207    _grow                   += Arc(toggle,   Cb(&Cam_int_fp::toggle_buttons));
00208    _grow_down      += Arc(move_ev, Cb(&Cam_int_fp::grow));
00209    _grow_down      += Arc(up_ev,   Cb(&Cam_int_fp::up, &_grow));
00210 
00211    //events possible while in the initial state
00212    _entry      += Arc(down_ev,   Cb(&Cam_int_fp::down,  &_cam_rot));
00213    _entry      += Arc(down2_ev,   Cb(&Cam_int_fp::down2));
00214    _entry      += Arc(for_down,  Cb(&Cam_int_fp::forward,  &_cam_forward));
00215    _entry      += Arc(back_down, Cb(&Cam_int_fp::back,  &_cam_back));
00216    _entry      += Arc(left_down, Cb(&Cam_int_fp::left,  &_cam_left));
00217    _entry      += Arc(right_down,Cb(&Cam_int_fp::right,  &_cam_right));
00218    _entry      += Arc(breathe,   Cb(&Cam_int_fp::breathe));
00219    _entry      += Arc(orbit,     Cb(&Cam_int_fp::orbit, &_orbit));
00220 
00221    _breathing = false;
00222    _size = 1;
00223    _gravity =  new Gravity(); 
00224 }
00225 
00226 Cam_int_fp::CAMwidget::CAMwidget():_a_displayed(0)
00227 {
00228    _anchor = new CAMwidget_anchor;
00229    _anchor->set_pickable(0); // Don't allow picking of anchor
00230    NETWORK.set(_anchor, 0);// Don't network the anchor
00231    CONSTRAINT.set(_anchor, GEOM::SCREEN_WIDGET);
00232    WORLD::create   (_anchor, false); 
00233    WORLD::undisplay(_anchor, false);
00234 }
00235 
00236 void
00237 Cam_int_fp::CAMwidget::undisplay_anchor()
00238 {
00239    WORLD::undisplay(_anchor, false);
00240    _a_displayed=0; 
00241 }
00242 
00243 void   
00244 Cam_int_fp::CAMwidget::display_anchor(
00245    CWpt &p
00246    )
00247 {
00248    WORLD::display(_anchor, false);  
00249    _a_displayed = 1;
00250 
00251    Wvec    delt(p-Wpt(XYpt(p)+XYvec(VEXEL(5,5)), p));
00252    Wtransf ff = Wtransf(p) * Wtransf::scaling(delt.length()); 
00253    _anchor->set_xform(Wtransf(p) * Wtransf::scaling(1.5*delt.length())); 
00254 }
00255 
00256 void 
00257 Cam_int_fp::CAMwidget::drag_anchor(
00258    CXYpt &p2d
00259    ) 
00260 {
00261    Wpt     apos(_anchor->xform().origin());
00262    Wpt     p   (Wplane(apos,Wvec(XYpt())).intersect(p2d));
00263    double  rad = (p-apos).length();
00264    Wtransf ff  = Wtransf(apos) * Wtransf::scaling(rad);
00265    _anchor->set_xform(Wtransf(apos) * Wtransf::scaling(rad));
00266 }
00267 
00268 int
00269 Cam_int_fp::predown(
00270    CEvent &e, 
00271    State *&
00272    )
00273 {
00274    DEVice_buttons *btns = (DEVice_buttons *)e._d;
00275    DEVice_2d      *ptr  = btns->ptr2d();
00276 
00277    _view = e.view();
00278 
00279    _do_reset = 0;
00280    _dtime    = the_time();
00281    _dist     = 0;
00282    _scale_pt = ptr->cur();
00283    _start_pix= ptr->cur();
00284 
00285 
00286 
00287    CAMdataptr  data(_view->cam()->data());
00288    RAYhit      r   (_view->intersect(ptr->cur()));
00289    if (r.success()) {
00290       double dist = r.dist();
00291       _down_pt = r.point() + dist * r.vec();
00292    } else {
00293       _down_pt = Wplane(data->center(),data->at_v()).intersect(ptr->cur());
00294    }
00295    _down_pt_2d = _down_pt;
00296 
00297    //Notify all the CAMobs's of the start of mouse down
00298   
00299    //if we're in cruise mode give it the scale and down point
00300    if(CamCruise::cur()) 
00301       {
00302          CamCruise::cur()->set_scale_pt(_scale_pt);
00303          CamCruise::cur()->set_down_pt(_down_pt);
00304       }
00305 
00306 
00307    data->start_manip();
00308    return 0;
00309 }
00310 
00311 ////////////////////////////////////
00312 //Right Click
00313 ////////////////////////////////////
00314 
00315 int
00316 Cam_int_fp::down(
00317    CEvent &e, 
00318    State *&s
00319    )
00320 {
00321    DEVice_buttons *btns = (DEVice_buttons *)e._d;
00322    DEVice_2d      *ptr  = btns->ptr2d();
00323    VIEWptr         view(e.view());
00324    int             is_dot = _camwidg.anchor_displayed();
00325    int             x, y; view->get_size(x,y);
00326    PIXEL           curpix(ptr->cur());
00327    XYpt            curpt (curpix[0]/x*2-1, curpix[1]/y*2-1);
00328 
00329    //set timer...
00330    _clock.set();
00331 
00332    predown(e,s);
00333    if(CamBreathe::cur()) CamBreathe::cur()->pause();
00334 
00335 
00336    // Did we click on a camera icon?
00337    CamIcon *icon = CamIcon::intersect_all(ptr->cur()); 
00338    if (icon) {
00339       // XXX - fix
00340       _icon = icon;
00341       switch (icon->test_down(e, s)) {
00342        case CamIcon::RESIZE : _resizing = true;
00343        case CamIcon::FOCUS  : s = &_icon_click;
00344          brcase CamIcon::MOVE   : {
00345             s = &_move_view;
00346             return move(e, s);
00347          }
00348       }
00349       return 0;
00350    } else
00351       {
00352          if (is_dot)
00353             view->cam()->data()->set_center(_camwidg.anchor_wpt());
00354          _do_reset = is_dot;
00355 
00356          if(!is_dot){
00357 
00358             VIEWptr         view(e.view());
00359             view->save_cam();
00360          }
00361          return 0;
00362       }
00363 
00364    return 0;
00365 }
00366 
00367 //////////////////////////////
00368 //Left-Click:tests for intersection
00369 //with camera buttons
00370 /////////////////////////////
00371 
00372 int
00373 Cam_int_fp::down2(
00374    CEvent &e, 
00375    State *&s
00376    )
00377 {
00378    DEVice_buttons *btns = (DEVice_buttons *)e._d;
00379    DEVice_2d      *ptr  = btns->ptr2d();
00380 
00381    _view = e.view();
00382 
00383    CAMdataptr  data(_view->cam()->data());
00384    RAYhit      r   (_view->intersect(ptr->cur()));
00385    if (r.success()) {
00386       //check if intersects with buttons
00387       //////////////////
00388       //Orbit Button
00389       //////////////////
00390       if(r.geom()->name() == "orbit")
00391          {
00392             //if(CamBreathe::cur()) CamBreathe::cur()->stop(); 
00393             BaseJOTapp::deactivate_button();
00394             //_button = r.geom();
00395             //GELptr sad = r.geom();
00396             //r.geom()->toggle_active();
00397             //_button = r.geom();
00398             if(s == &_orbit)
00399                { 
00400                   s = (State *)-1;
00401                   return stop_orbit(e,s);
00402                } 
00403             else
00404                {
00405                   BaseJOTapp::activate_button("orbit");
00406                   stop_actions(e,s);
00407                   s = &_orbit;
00408                   return orbit(e,s);
00409                } 
00410          }
00411       //////////////////
00412       //Breathing Button
00413       //////////////////
00414       else if(r.geom()->name() == "breathe")
00415          {
00416             BaseJOTapp::toggle_button("breathe");
00417             return breathe(e,s); 
00418          }
00419       //////////////////
00420       //Cruise Button
00421       //////////////////
00422       else if(r.geom()->name() == "cruise")
00423          {
00424             if(CamBreathe::cur()) CamBreathe::cur()->stop(); 
00425             BaseJOTapp::deactivate_button();
00426             if(s == &_cruise)
00427                { 
00428                   s = (State *)-1;
00429                   return stop_cruise(e,s);
00430                } 
00431             else
00432                { 
00433                   BaseJOTapp::activate_button("cruise");
00434                   stop_actions(e,s);
00435                   s = &_cruise;
00436                   BaseCollide::update_scene();
00437                   return cruise(e,s); 
00438                }
00439          }
00440       //////////////////
00441       //Grow Button
00442       //////////////////
00443       else if(r.geom()->name() == "grow")
00444          {
00445             BaseJOTapp::deactivate_button();
00446             if(s == &_grow)
00447                s = (State *)-1;
00448             else
00449                { 
00450                   BaseJOTapp::activate_button("grow");
00451                   stop_actions(e,s);
00452                   s = &_grow; 
00453                }
00454          }
00455       //////////////////
00456       //Gravity Button
00457       //////////////////
00458       else if(r.geom()->name() == "gravity")
00459          {
00460             //BaseJOTapp::deactivate_button();
00461             BaseJOTapp::update_button("gravity");
00462          }
00463       //////////////////
00464       //CamSwitch Button
00465       //////////////////
00466       else if(r.geom()->name() == "eye_button")
00467          {
00468             stop_actions(e,s);
00469 
00470             s = (State *)-1;
00471             BaseJOTapp::cam_switch(e,s);
00472          }
00473    }
00474 
00475    return 0;
00476 }
00477 ///////////////////////////
00478 //Stop Actions:stops all
00479 //possible scheduled actions
00480 ///////////////////////////
00481 int
00482 Cam_int_fp::stop_actions(
00483    CEvent &e, 
00484    State *&s
00485    )
00486 {
00487    if(CamOrbit::cur()) CamOrbit::cur()->stop(); 
00488    //if(CamBreathe::cur()) CamBreathe::cur()->stop();
00489    if(CamCruise::cur()) CamCruise::cur()->stop(); 
00490    return 0;
00491 }
00492 
00493 ////////////////////////////////////////////////////////////////////////////
00494 //while in the orbit state, when mouse down chooses to zoom or change orbit 
00495 //speed and direction
00496 ///////////////////////////////////////////////////////////////////////////
00497 int 
00498 Cam_int_fp::choose(
00499    CEvent &e,
00500    State *&s
00501    )
00502 {
00503    _clock.set();
00504 
00505    DEVice_2d *ptr =(DEVice_2d *)e._d;
00506    PIXEL      te   (ptr->cur());
00507    XYvec      delta(ptr->delta());
00508    double     tdelt(the_time() - _dtime);
00509 
00510    _dist += sqrt(delta * delta);
00511 
00512    VEXEL sdelt(te - _start_pix);
00513 
00514    int xa=0,ya=1;
00515    if (Config::get_var_bool("FLIP_CAM_MANIP",false,true))
00516       swap(xa,ya);
00517      
00518    if (fabs(sdelt[ya])/sdelt.length() > 0.9 && tdelt > 0.05) {
00519       s = &_orb_zoom;
00520       ptr->set_old(_start_pix);
00521    } else if (tdelt < 0.1 && _dist < 0.03)
00522       return 0;
00523    else {
00524       if (fabs(sdelt[xa])/sdelt.length() > 0.6 )
00525          s = &_orb_rot;
00526       else s = &_orb_zoom;
00527       ptr->set_old(_start_pix);
00528    }
00529 
00530 
00531    /* if we got this far, we actually have a valid choice, so save the camera */  
00532    
00533    VIEWptr         view(e.view());
00534    view->save_cam();
00535 
00536    return 0;
00537 }
00538 
00539 
00540 int
00541 Cam_int_fp::stop_orbit(CEvent &e, State *&s) 
00542 {
00543    CamOrbit::cur()->stop(); 
00544 
00545    return 0;
00546 }
00547 
00548 
00549 //Orbit function, schedules the camera to orbit around a point
00550 int
00551 Cam_int_fp::orbit(CEvent &e, State *&s) 
00552 {
00553 
00554    CAMptr      cam (e.view()->cam());
00555    CAMdataptr  data(cam->data());
00556 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
00557    VIEWptr         view(e.view());
00558      
00559 
00560 
00561    //get the object to orbit
00562    RAYhit r(view->intersect(data->center()));  
00563    //if it hits nothing or the sky box, can't orbit so return
00564    if (!r.success() || (r.geom()->name() == "Skybox Geom")) 
00565       {
00566          BaseJOTapp::toggle_button("orbit");
00567          s = (State *)-1;
00568          return 0;
00569       }
00570 
00571    GEOMptr geom(ray_geom(r,GEOM::null));
00572 
00573    //start orbit
00574    CamOrbit::cur() = new CamOrbit(cam, geom->bbox().center());
00575 
00576    view->save_cam();
00577    view->schedule(&*CamOrbit::cur());
00578 
00579    return 0;
00580 }
00581 
00582 
00583 
00584 //Breathe function, schedules a breathing animation for the camera
00585 int
00586 Cam_int_fp::breathe(CEvent &e, State *&) 
00587 {
00588    CAMptr      cam (e.view()->cam());
00589    CAMdataptr  data(cam->data());
00590 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
00591    VIEWptr         view(e.view());
00592       
00593 //if(CamBreathe::cur()) CamBreathe::cur()->stop();
00594 
00595    if(CamBreathe::cur())
00596       {
00597          CamBreathe::cur()->stop();
00598          CamBreathe::cur() = NULL;
00599       }
00600    else
00601       {
00602          CamBreathe::cur() = new CamBreathe(cam);
00603          view->save_cam();
00604          view->schedule(&*CamBreathe::cur());
00605          _breathing = true;
00606       }
00607 
00608    return 0;
00609 }
00610 
00611 
00612 int
00613 Cam_int_fp::cruise_down(CEvent &e, State *&s) 
00614 {
00615    DEVice_buttons *btns = (DEVice_buttons *)e._d;
00616    DEVice_2d      *ptr  = btns->ptr2d();
00617    VIEWptr         view(e.view());
00618    int             x, y; view->get_size(x,y);
00619    PIXEL           curpix(ptr->cur());
00620    XYpt            curpt (curpix[0]/x*2-1, curpix[1]/y*2-1);
00621 
00622    //robcm
00623    if(_land_clock.elapsed_time()<.5)
00624       {
00625          RAYhit      r   (_view->intersect(ptr->cur()));
00626          if (r.success() && CamCruise::cur())
00627             {
00628                GEOMptr g = GEOM::upcast(r.geom());
00629                CamCruise::cur()->travel(r.point());
00630                CamCruise::cur()->speed(.001 * g->bbox().dim().length());
00631                _gravity->set_grav(g, Wvec(1,0,0), 0);
00632                //_gravity->set_globe(g);
00633                cout << "VOL: " << g->bbox().volume() << endl;
00634                cout << "DIM: " << g->bbox().dim().length() << endl;
00635             }
00636          return 0;
00637       }
00638 
00639    predown(e,s);
00640    _clock.set();
00641    _land_clock.set();
00642    
00643    //if the user clicks at the edge of the screen rotate
00644    if (fabs(curpt[0]) > .6 )//|| fabs(curpt[1]) > .6)
00645       {
00646          s = &_cruise_rot;
00647          return 0;
00648       }
00649 
00650    //else zoom
00651    s = &_cruise_zoom;
00652    return 0;
00653 }
00654 
00655 
00656 //in orbit state zooms in and out on orbiting object
00657 int
00658 Cam_int_fp::cruise_zoom(
00659    CEvent &e,
00660    State *&
00661    )
00662 {
00663    //XYvec      delta(_te-_tp);
00664    //double     ratio;
00665 
00666    DEVice_2d *ptr=(DEVice_2d *)e._d;
00667    CAMptr     cam  (e.view()->cam());
00668    CAMdataptr data (cam->data());
00669    XYvec      delta(ptr->delta());
00670    double     ratio;
00671 
00672    _tp    = ptr->old(); 
00673    _te    = ptr->cur();
00674    _move_clock.set();
00675 
00676    CamCruise::cur()->pause();
00677    if(CamBreathe::cur()) CamBreathe::cur()->pause();
00678 
00679    if (data->persp()) {
00680       Wvec    movec(data->at() - data->from());
00681 
00682       data->set_center(data->at());
00683       //BaseCollide::instance()->get_move(.1 * movec.normalized() 
00684       //                                                                      * (movec.length() * delta[1] * -4));
00685 /*
00686   Wvec    movec(_down_pt - data->from());
00687 
00688   data->set_center(_down_pt);*/
00689       // data->translate(.1 * movec.normalized() * (movec.length() * delta[1] * -4));
00690       data->translate(.1 * movec.normalized() * (movec.length() * delta[1] * -4));
00691 
00692       ratio = cam->height() / cam->width() * 
00693          (movec * data->at_v()) * data->width() / data->focal();
00694 
00695    } else {
00696       Wpt     spt  (XYpt(ptr->cur()[0],_scale_pt[1]));
00697       Wvec    svec (spt - Wline(data->from(), data->at_v()).project(spt));
00698       double  sfact(1 + delta[1]);
00699       data->translate( svec * (1.0 - sfact));
00700       data->set_width (data->width() * sfact);
00701       data->set_height(data->height()* sfact);
00702       ratio = data->height();
00703    }
00704 
00705    //data->translate(-delta[0]/2 * data->right_v() * ratio);
00706    //data->set_at(Wline(data->from(), data->at_v()).project(data->center()));
00707    //data->set_center(data->at());
00708 
00709 
00710    /*
00711      XYvec      delta(_te-_tp);
00712      double     ratio;
00713 
00714      Wpt     spt  (XYpt(_tp[0],_te[1]));
00715      Wvec    svec (spt - Wline(data->from(), data->at_v()).project(spt));
00716      double  sfact(1 + delta[1]);
00717 
00718 
00719      data->translate( svec * (1.0 - sfact));
00720      data->set_width (data->width() * sfact);
00721      data->set_height(data->height()* sfact);
00722      ratio = data->height();
00723 
00724      //.2 is temperary to slow it down a bit
00725      Wvec velocity = .2 * delta[0]/2 * data->at_v() * ratio;
00726  
00727      data->translate(velocity);
00728      data->set_at(Wline(data->from(), data->at_v()).project(data->center()));
00729      data->set_center(data->at());
00730    */
00731    return 0;
00732 }
00733 
00734 int
00735 Cam_int_fp::cruise_zoom_up(
00736    CEvent &e,
00737    State *&s
00738    )
00739 {
00740         
00741    if(_clock.elapsed_time()<.1 || _move_clock.elapsed_time()> .2)
00742       {
00743          CamCruise::cur()->pause();
00744          if(CamBreathe::cur()) CamBreathe::cur()->unpause();
00745          //travel(e,s);
00746       }
00747    else
00748       {
00749          CamCruise::cur()->set_cruise(_tp,_te); 
00750       }
00751    return 0;
00752 }
00753 
00754 
00755 //Cruise Control, moves the camera foward automatically
00756 //towards point of interest
00757 int
00758 Cam_int_fp::cruise(CEvent &e, State *&s) 
00759 {
00760         
00761 
00762    CAMptr      cam (e.view()->cam());
00763    CAMdataptr  data(cam->data());
00764 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
00765    VIEWptr         view(e.view());
00766       
00767 
00768    CamCruise::cur() = new CamCruise(cam, data->center());
00769 
00770    view->save_cam();
00771    view->schedule(&*CamCruise::cur());
00772 
00773    return 0;
00774 }
00775 
00776 //Orbit function, schedules the camera to orbit around a point
00777 int
00778 Cam_int_fp::stop_cruise(CEvent &e, State *&s) 
00779 {
00780    CamCruise::cur()->stop(); 
00781    CamCruise::cur() = NULL;
00782 
00783    return 0;
00784 }
00785 
00786 //stop the breathing animation
00787 int
00788 Cam_int_fp::stop_breathe(CEvent &e, State *&) 
00789 {
00790    CamBreathe::cur()->stop(); 
00791    CamBreathe::cur() = NULL;
00792 
00793    return 0;
00794 }
00795 
00796 
00797 
00798 //in orbit state zooms in and out on orbiting object
00799 int
00800 Cam_int_fp::orbit_zoom(
00801    CEvent &e,
00802    State *&
00803    )
00804 {
00805    DEVice_2d *ptr=(DEVice_2d *)e._d;
00806    CAMptr     cam  (e.view()->cam());
00807    CAMdataptr data (cam->data());
00808    XYvec      delta(ptr->delta());
00809 //   double     ratio;
00810 
00811 
00812    XYpt        tp    = ptr->old(); 
00813    XYpt        te    = ptr->cur();
00814 
00815    double distscale = -100 * (te[1] - tp[1]); //tp.dist(te);
00816 
00817    cam->set_zoom(1);
00818    cam->set_min(NDCpt(XYpt(-1,-1)));
00819    cam->data()->changed();
00820 
00821    //move along the view vector, at the normalized length
00822    Wvec delt = data->at_v().normalized();
00823 
00824    //update camera
00825    data->translate(distscale * delt);
00826    data->set_center(data->at());
00827 
00828    return 0;
00829 }
00830 
00831 //while in the orbit stage you can change orbit movement
00832 int
00833 Cam_int_fp::orbit_rot(
00834    CEvent &e, 
00835    State *&
00836    ) 
00837 {
00838 
00839    CAMptr      cam (e.view()->cam());
00840    CAMdataptr  data(cam->data());
00841    DEVice_2d  *ptr=(DEVice_2d *)e._d;
00842 
00843         
00844 
00845    CamOrbit::cur()->set_orbit(XYpt(0,0),XYpt(0,0)); 
00846    cam->set_zoom(1);
00847    cam->set_min(NDCpt(XYpt(-1,-1)));
00848    cam->data()->changed();
00849 
00850    XYpt        cpt   = data->center();
00851    double      radsq = sqr(1+fabs(cpt[0])); // squared rad of virtual cylinder
00852    _tp    = ptr->old(); 
00853    _te    = ptr->cur();
00854    _move_clock.set();
00855 
00856    Wvec   op  (_tp[0], 0, 0);             // get start and end X coordinates
00857    Wvec   oe  (_te[0], 0, 0);             //    of cursor motion
00858    double opsq = op * op, oesq = oe * oe;
00859    double lop  = opsq > radsq ? 0 : sqrt(radsq - opsq);
00860    double loe  = oesq > radsq ? 0 : sqrt(radsq - oesq);
00861    Wvec   nop  = Wvec(op[0], 0, lop).normalized();
00862    Wvec   noe  = Wvec(oe[0], 0, loe).normalized();
00863    double dot  = nop * noe;
00864 
00865    if (fabs(dot) > 0.0001) {
00866       data->rotate(Wline(data->center(), Wvec::Y()),
00867                    -2*Acos(dot) * Sign(_te[0]-_tp[0]));
00868 
00869       Wvec   dvec  = data->from() - data->center();
00870       double rdist = _te[1]-_tp[1];
00871 //      double tdist = Acos(Wvec::Y() * dvec.normalized());
00872 
00873       CAMdata   dd = CAMdata(*data);
00874 
00875       Wline raxe(data->center(),data->right_v());
00876       data->rotate(raxe, rdist);
00877       data->set_up(data->from() + Wvec::Y());
00878       if (data->right_v() * dd.right_v() < 0)
00879          *data = dd;
00880    }
00881 
00882    return 0;
00883 }
00884 //while in the orbit stage you can change orbit movement
00885 int
00886 Cam_int_fp::orbit_rot_up(
00887    CEvent &e, 
00888    State *&
00889    ) 
00890 {
00891    if(_clock.elapsed_time()<.1 || _move_clock.elapsed_time()>.2)
00892       {
00893          CamOrbit::cur()->pause();       //pause orbit
00894          if(CamBreathe::cur()) CamBreathe::cur()->unpause();
00895       }
00896    else
00897       {
00898          CamOrbit::cur()->set_orbit(_tp,_te); //set the constant X-axis rotation
00899          if(CamBreathe::cur()) CamBreathe::cur()->pause();
00900       }
00901    return 0;
00902 }
00903 
00904 //Forward Function, moves the camera foward
00905 int
00906 Cam_int_fp::forward(
00907    CEvent &e, 
00908    State *&s
00909    ) 
00910 {
00911    if(s==&_cruise)
00912       {
00913          CamCruise::cur()->speed(1); 
00914          return 0;
00915       }
00916 
00917    CAMptr      cam (e.view()->cam());
00918    CAMdataptr  data(cam->data());
00919 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
00920 
00921 
00922    VIEWptr         view(e.view());
00923    RAYhit ray(view->intersect(data->center()));         
00924 
00925    if(!ray.success() || ray.dist() > 1 || ray.dist() < 0)
00926       {
00927          cam->set_zoom(1);
00928          cam->set_min(NDCpt(XYpt(-1,-1)));
00929          cam->data()->changed();
00930 
00931          //move along the view vector, at the normalized length
00932          Wvec delt = data->at_v().normalized();
00933 
00934          //update camera
00935          data->translate(delt);
00936          data->set_center(data->at());
00937       }
00938 
00939    
00940    return 0;
00941 }
00942 
00943 //Back Function, moves the camera backwards
00944 int
00945 Cam_int_fp::back(
00946    CEvent &e, 
00947    State *&s
00948    ) 
00949 {
00950  
00951    if(s==&_cruise)
00952       {
00953          CamCruise::cur()->speed(-1); 
00954          return 0;
00955       }
00956 
00957 
00958    CAMptr      cam (e.view()->cam());
00959    CAMdataptr  data(cam->data());
00960 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
00961 
00962    XYpt        cpt   = (data->from()-data->at_v());
00963    VIEWptr         view(e.view());
00964    RAYhit ray(view->intersect(cpt));         
00965 
00966 //if(!ray.success() || ray.dist() > 1 || ray.dist() < 0)
00967 //   {
00968    cam->set_zoom(1);
00969    cam->set_min(NDCpt(XYpt(-1,-1)));
00970    cam->data()->changed();
00971 
00972    //move along the view vector, at the normalized length
00973    Wvec delt = data->at_v().normalized();
00974 
00975    //update camera
00976    data->translate(-delt);
00977    data->set_center(data->at());
00978 //   }
00979    
00980    return 0;
00981 }
00982 
00983 //Left function, moves the camera left
00984 int
00985 Cam_int_fp::left(
00986    CEvent &e, 
00987    State *&
00988    ) 
00989 {
00990 
00991    CAMptr      cam (e.view()->cam());
00992    CAMdataptr  data(cam->data());
00993 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
00994 
00995    cam->set_zoom(1);
00996    cam->set_min(NDCpt(XYpt(-1,-1)));
00997    cam->data()->changed();
00998 
00999    //move along the right axis, at the normalized length
01000    Wvec delt = 2*data->right_v().normalized();
01001 
01002    data->translate(-delt);
01003    //data->set_at(Wline(data->from(), data->at_v()).project(_down_pt));
01004    data->set_center(data->at());
01005    
01006    return 0;
01007 }
01008 
01009 //Right function, moves the camera right
01010 int
01011 Cam_int_fp::right(
01012    CEvent &e, 
01013    State *&
01014    ) 
01015 {
01016   
01017    CAMptr      cam (e.view()->cam());
01018    CAMdataptr  data(cam->data());
01019 //   DEVice_2d  *ptr=(DEVice_2d *)e._d;
01020 
01021    cam->set_zoom(1);
01022    cam->set_min(NDCpt(XYpt(-1,-1)));
01023    cam->data()->changed();
01024 
01025    //move along the right axis, at the normalized length
01026    Wvec delt = 2*data->right_v().normalized();
01027 
01028    data->translate(delt);
01029    //data->set_at(Wline(data->from(), data->at_v()).project(_down_pt));
01030    data->set_center(data->at());
01031    
01032    return 0;
01033 }
01034 
01035 //rot function, turns the direction of the camera
01036 int
01037 Cam_int_fp::rot(
01038    CEvent &e, 
01039    State *&
01040    ) 
01041 {
01042         
01043    CAMptr      cam (e.view()->cam());
01044    CAMdataptr  data(cam->data());
01045    DEVice_2d  *ptr=(DEVice_2d *)e._d;
01046 
01047 
01048 //cam->set_zoom(1);
01049    cam->set_min(NDCpt(XYpt(-1,-1)));
01050    cam->data()->changed();
01051 
01052    XYpt        cpt   = data->center();
01053    double      radsq = sqr(1+fabs(cpt[0])); // squared rad of virtual cylinder
01054    XYpt        tp    = ptr->old(); 
01055    XYpt        te    = ptr->cur();
01056 
01057    Wvec   op  (tp[0], 0, 0);             // get start and end X coordinates
01058    Wvec   oe  (te[0], 0, 0);             //    of cursor motion
01059 
01060 
01061    double opsq = op * op, oesq = oe * oe;
01062    double lop  = opsq > radsq ? 0 : sqrt(radsq - opsq);
01063    double loe  = oesq > radsq ? 0 : sqrt(radsq - oesq);
01064    Wvec   nop  = Wvec(op[0], 0, lop).normalized();
01065    Wvec   noe  = Wvec(oe[0], 0, loe).normalized();
01066    double dot  = nop * noe;
01067 
01068    if (fabs(dot) > 0.0001) {
01069       data->rotate(Wline(data->from(), Wvec::Y()),
01070                    -2*Acos(dot) * Sign(te[0]-tp[0]));
01071 
01072       Wvec   dvec  = data->from() - data->center();
01073       double rdist = te[1]-tp[1];
01074 //      double tdist = Acos(Wvec::Y() * dvec.normalized());
01075 
01076       CAMdata   dd = CAMdata(*data);
01077 
01078       Wline raxe(data->from(),data->right_v());
01079       data->rotate(raxe, rdist);
01080       data->set_up(data->from() + Wvec::Y());
01081       if (data->right_v() * dd.right_v() < 0)
01082          *data = dd;
01083    }
01084 
01085 
01086 
01087    //rot not working when cruising =[
01088    data->set_center(data->at());
01089    //VIEWptr         view(e.view());
01090    //view->save_cam();
01091    return 0;
01092 }
01093 
01094 int
01095 Cam_int_fp::focus(
01096    CEvent &e,
01097    State *&s
01098    ) 
01099 {
01100    DEVice_buttons *btns=(DEVice_buttons *)e._d;
01101    DEVice_2d      *ptr=btns->ptr2d();
01102    VIEWptr         view(e.view());
01103    CAMptr          cam (view->cam());
01104    CAMdataptr      data(cam->data());
01105 
01106    RAYhit  r   (view->intersect(ptr->cur()));
01107    GEOMptr geom(ray_geom(r,GEOM::null));
01108    if (geom) {
01109       XYvec    vec  (VEXEL(25,0));
01110       RAYhit   sil_r(ptr->cur() + vec);
01111       RAYhit   sil_l(ptr->cur() - vec);
01112       geom->intersect(sil_r);
01113       geom->intersect(sil_l);
01114 
01115       if ((r.norm().normalized() * Wvec::Y()) < 0.98 &&
01116           ( sil_r.success() && !sil_l.success()) ||
01117           (!sil_r.success() &&  sil_l.success())) {
01118          Wvec sil_comp;                         // do silhouette focus
01119          if (sil_r.success())
01120             sil_comp = -data->right_v() * 6.0 * r.dist();
01121          else
01122             sil_comp =  data->right_v() * 6.0 * r.dist();
01123 
01124          Wvec v(sil_comp + r.norm() * 4.0 * r.dist());
01125          Wpt  newpos(r.surf() + r.dist() * v.normalized());
01126          newpos[1] = data->from()[1];
01127          newpos = r.surf() + (newpos - r.surf()).normalized() * r.dist();
01128          //  if(s==&_cruise)
01129          //      CamCruise::cur()->
01130          //else
01131          //{
01132     
01133          new CamFocus(view, newpos, r.surf(), newpos + Wvec::Y(), r.surf(),
01134                       data->width(), data->height());
01135       }
01136       else {
01137          Wpt  center(r.surf());              // do normal focus
01138          Wvec norm  (r.norm().normalized());
01139          if (norm * Wvec::Y() > 0.98)
01140             norm = -data->at_v();
01141 
01142          Wvec  off   (cross(Wvec::Y(),norm).normalized() * 3);
01143          Wvec  atv   (data->at_v() - Wvec::Y() * (data->at_v() * Wvec::Y()));
01144          // Must use 4.0 instead of 4 due to AIX C++ weirdness
01145          Wvec  newvec(norm*6 + 4.0*Wvec::Y()); 
01146          if ((center + newvec + off - data->from()).length() > 
01147              (center + newvec - off - data->from()).length())
01148             off = newvec - off;
01149          if (data->persp())
01150             off = (newvec + off).normalized() * 
01151 //                  (geom->bbox().min() - geom->bbox().max()).length();
01152                (data->from()-Wline(data->from(),data->at()).project(center)).
01153                length();
01154 
01155          //       if(s = &_cruise)
01156          //              {
01157          //               CamCruise::cur()->set_focus(center + off);
01158          //              }
01159          //       else
01160          //       {
01161          new CamFocus(view, center + off, center, center + off + Wvec::Y(), 
01162                       center, data->width(), data->height());
01163          // }
01164       }
01165    } else
01166       cerr << "Cam_int_fp::focus() - Nothing to focus on!!!\n";
01167 
01168    return 0;
01169 }
01170 
01171 int
01172 Cam_int_fp::move(
01173    CEvent &e, 
01174    State *&
01175    )
01176 {
01177    if (_icon) _icon->set_icon_loc(((DEVice_2d *)e._d)->cur());
01178    return 0;
01179 }
01180 
01181 int
01182 Cam_int_fp::moveup(
01183    CEvent &, 
01184    State *&
01185    )
01186 {
01187    for (int i = 0; i < _up_obs.num(); i++) 
01188       _up_obs[i]->reset(_do_reset);  // reset everyone watching us
01189    _geom = 0;
01190    _icon = 0;
01191    return 0;
01192 }
01193 
01194 int
01195 Cam_int_fp::iconmove(
01196    CEvent &e, 
01197    State *&s
01198    )
01199 {
01200    if (_resizing) return _icon->icon_move(e, s);
01201    return 0;
01202 }
01203 
01204 int
01205 Cam_int_fp::iconup(
01206    CEvent &e, 
01207    State *&s
01208    )
01209 {
01210    if (_resizing) {
01211       _resizing = false;
01212       const int retval = _icon->resize_up(e, s);
01213       _icon = 0;
01214       return retval;
01215    }
01216    DEVice_buttons *btns=(DEVice_buttons *)e._d;
01217    DEVice_2d      *ptr=btns->ptr2d();
01218    PIXEL           curpt(ptr->cur());
01219 
01220    // Delete
01221    if (the_time() - _dtime < 0.25 && _icon &&
01222        (curpt - _start_pix).length() > 20 &&
01223        (curpt - _start_pix).normalized() * VEXEL(1,1).normalized() > 0.5) {
01224       _icon->remove_icon();
01225       _icon = 0;
01226       return 0;
01227    }
01228 
01229    if (_icon->intersect_icon(ptr->cur())) {
01230       new CamFocus(e.view(), _icon->cam());
01231    }
01232    return 0;
01233 }
01234 
01235 int
01236 Cam_int_fp::dragup(
01237    CEvent &e, 
01238    State *&s
01239    )
01240 {
01241    DEVice_buttons *btns=(DEVice_buttons *)e._d;
01242    DEVice_2d      *ptr=btns->ptr2d();
01243    VIEWptr         view(e.view());
01244    CAMptr          cam (view->cam());
01245    PIXEL           curpt(ptr->cur());
01246 
01247    double elapsed = the_time() - _dtime;
01248    // Are we close to the cam globe?
01249    if (ptr->cur().dist(_camwidg.anchor_pos()) < DOT_DIST && elapsed < 0.25)
01250       return up(e,s);
01251    
01252    reset(1);
01253 
01254    for (int i = 0; i < _up_obs.num(); i++) 
01255       _up_obs[i]->reset(_do_reset);  // reset everyone watching us
01256 
01257    if ((curpt - _start_pix).length() > 20 &&
01258        (curpt - _start_pix).normalized() * VEXEL(-1,0).normalized() > 0.5)
01259       return 0;
01260    
01261    RAYhit ray(view->intersect(_camwidg.anchor_pos()));
01262    if (!ray.success())
01263       return 0;
01264 
01265    CAMdataptr data(cam->data());
01266    double dist = _camwidg.anchor_size() * 2*data->focal()/data->height();
01267    Wvec dirvec((data->from() - ray.surf()).normalized());
01268 
01269    Wpt from = ray.surf() + dist * dirvec;
01270    new CamFocus(view, 
01271                 from,
01272                 ray.surf(),                 // at
01273                 from + Wvec::Y(),           // up
01274                 ray.surf(),                 // center
01275                 data->width(), data->height());
01276 
01277    return 0;
01278 }
01279 
01280 int
01281 Cam_int_fp::up(
01282    CEvent &e, 
01283    State *&s
01284    )
01285 {
01286 
01287    //if the camera is rotating and user taps...then pause orbit
01288    if(CamOrbit::cur() && _clock.elapsed_time()<.1)
01289       {
01290          CamOrbit::cur()->pause();
01291          if(CamBreathe::cur()) CamBreathe::cur()->unpause();
01292       }
01293    //if(CamCruise::cur())
01294    //      return travel(e,s);
01295 
01296    if(CamBreathe::cur()) CamBreathe::cur()->unpause();
01297    DEVice_buttons *btns=(DEVice_buttons *)e._d;
01298    DEVice_2d      *ptr=btns->ptr2d();
01299    VIEWptr         view(e.view());
01300    CAMptr          cam (view->cam());
01301 
01302    for (int i = 0; i < _up_obs.num(); i++) 
01303       _up_obs[i]->reset(_do_reset);  // reset everyone watching us
01304    if (_camwidg.anchor_displayed()) {
01305       if (ptr->cur().dist(_camwidg.anchor_pos()) < DOT_DIST)
01306          {
01307             focus(e,s);
01308          }
01309       reset(1);
01310    } else if (ptr->cur().dist(_down_pt_2d) < DOT_DIST) {
01311       RAYhit ray(view->intersect(ptr->cur()));
01312       if (ray.success()) {
01313          GEOMptr geom(ray_geom(ray,GEOM::null));
01314          //geom->set_xform(Wtransf::scaling(2,2,2));
01315          if (CamOrbit::cur()) {CamOrbit::cur()->set_target(ray.surf());}
01316 
01317          // Create the anchor (blue ball) on the surface:
01318          _camwidg.display_anchor(ray.surf());
01319          // If clicked on a mesh, make it the "center of interest":
01320          BMESHptr m = gel_to_bmesh(ray.geom());
01321          if (m)
01322             BMESH::set_center_of_interest(m);
01323       } else {
01324          //if (CamCruise::cur()) {CamCruise::cur()->unset_target();}
01325          // _camwidg.display_anchor(hitp.intersect(ray.screen_point()));
01326       }
01327    }
01328    cam->data()->end_manip();
01329    return 0;
01330 }
01331 /*
01332 //robcm - travel
01333 int
01334 Cam_int_fp::travel(
01335 CEvent &e, 
01336 State *&s
01337 )
01338 {
01339 DEVice_buttons *btns=(DEVice_buttons *)e._d;
01340 DEVice_2d      *ptr=btns->ptr2d();
01341 VIEWptr         view(e.view());
01342 CAMptr          cam (view->cam());
01343 
01344 if(_down_pt_2d == ptr->cur() && _clock2.elapsed_time() < .2) 
01345 {
01346 RAYhit ray(view->intersect(ptr->cur()));
01347 if (ray.success())
01348 CamCruise::cur()->travel(ray.surf());
01349 }
01350 else
01351 {
01352 _clock2.set();
01353 _down_pt_2d = ptr->cur();
01354 }
01355 
01356 return 0;
01357 }
01358 */
01359 int
01360 Cam_int_fp::grow(
01361    CEvent &e, 
01362    State *&s
01363    )
01364 {
01365    DEVice_2d *ptr=(DEVice_2d *)e._d;
01366    CAMptr     cam  (e.view()->cam());
01367    CAMdataptr data (cam->data());
01368    XYvec      delta(ptr->delta());
01369 //   double     ratio;
01370 
01371    _tp    = ptr->old(); 
01372    _te    = ptr->cur();
01373 
01374    cout << "grow: " << _te[0]-_tp[0] << endl;
01375    if (CamBreathe::cur()) CamBreathe::grow(_te[0]-_tp[0]);
01376 
01377 
01378    return 0;
01379 }
01380 
01381 int
01382 Cam_int_fp::grow_change(
01383    CEvent &e, 
01384    State *&s
01385    )
01386 {
01387    cout << "_" << endl;
01388    return 0;
01389 }
01390 //
01391 // reset() - UP observer method
01392 //   Cam_int_fp is an observer of 'UP' events on other objects.
01393 // In particular, Cam_int_fp observes the 'UP' events of ObjManip
01394 // so that the Cam_int_fp can clear its widget after an object
01395 // is dragged.
01396 //
01397 void
01398 Cam_int_fp::reset(int rst)
01399 {
01400    if (rst)
01401       _camwidg.undisplay_anchor();
01402 }
01403 
01404 // Make a view (camera icon)
01405 void
01406 Cam_int_fp::make_view(
01407    CXYpt  &curpt
01408    )
01409 {
01410    // Create new cam icon
01411    _icon = CamIcon::create(curpt, _view->cam());
01412    _geom = 0;
01413    
01414    reset(1);
01415 }
01416 
01417 int
01418 Cam_int_fp::toggle_buttons(
01419    CEvent &e, 
01420    State *&s
01421    )
01422 {
01423    BaseJOTapp::button_toggle(e,s);
01424    return 0;
01425 }
01426 
01427 // end of file cam_fp.C

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