Esempio n. 1
0
int
Cam_int::zoom2(
   CEvent &e,
   State *&
   )
{
   if (debug_fsa)
      cerr << "Cam_int::zoom2"
           << endl;

   DEVice_2d  *ptr =  (DEVice_2d *)e._d;
   CAMptr      cam    (e.view()->cam());
   PIXEL       curpt  (ptr->cur());
   XYpt        startpt(_start_pix);
   int w,h;    e.view()->get_size(w,h);

   double zoom_factor =  1 + Sign(ptr->delta()[0]) * 
      (PIXEL(ptr->cur())-PIXEL(ptr->old())).length()/(w/4);

   cam->set_zoom(cam->zoom() * zoom_factor);
   cam->set_min (cam->min() + NDCvec(XYpt(_start_pix) - startpt));

   ptr->set_cur(curpt);
   cam->data()->changed();
   
   return 0;
}
Esempio n. 2
0
int
Cam_int::predown(
   CEvent &e, 
   State *&
   )
{
   // de-activate current CamFocus, if any:
   CamFocus::cancel_cur();
   
   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();

   _view = e.view();

   _do_reset = 0;
   _dtime    = the_time();
   _dist     = 0;
   _scale_pt = ptr->cur();
   _start_pix= ptr->cur();

   CAMdataptr  data(_view->cam()->data());
   RAYhit      r   (_view->intersect(ptr->cur()));
   if (r.success()) {
      _down_pt = r.surf();
   } else {
      _down_pt = Wplane(data->center(),data->at_v()).intersect(ptr->cur());
   }
   _down_pt_2d = _down_pt;

   //Notify all the CAMobs's of the start of mouse down
  
   data->start_manip();
   return 0;
}
Esempio n. 3
0
//left-click:test for any buttons used in this camera mode
int
Cam_int::down2(
   CEvent &e, 
   State *&s
   )
{
   if (debug_fsa)
      cerr << "Cam_int::down2"
           << endl;

   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();

   _view = e.view();

   CAMdataptr  data(_view->cam()->data());
   RAYhit      r   (_view->intersect(ptr->cur()));
   if (r.success()) {
      if(r.geom()->name() == "eye_button")
         {
            s = (State *)-1;
            BaseJOTapp::cam_switch(e,s);
         }
   }
   return 0;
}
Esempio n. 4
0
int
Cam_int_edit::down(
   CEvent &e, 
   State *&s
   )
{
   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();
   VIEWptr         view(e.view());

   int             x, y; view->get_size(x,y);
   PIXEL           curpix(ptr->cur());
   XYpt            curpt (curpix[0]/x*2-1, curpix[1]/y*2-1);

   predown(e,s);
   
   //if the user clicks at the edge of the screen rotate
   if (fabs(curpt[0]) > .85 || fabs(curpt[1]) > .9)
      {
         s = &_cam_rot;
         return 0;
      }

   // } 

   return 0;
}
Esempio n. 5
0
int
Cam_int_edit::predown(
   CEvent &e, 
   State *&
   )
{
   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();

   _view = e.view();


   _do_reset = 0;
   _dtime    = the_time();
   _dist     = 0;
   _scale_pt = ptr->cur();
   _start_pix= ptr->cur();

   CAMdataptr  data(_view->cam()->data());
   RAYhit      r   (_view->intersect(ptr->cur()));
   if (r.success()) {
      double dist = r.dist();
      _down_pt = r.point() + dist * r.vec();
   } else {
      _down_pt = Wplane(data->center(),data->at_v()).intersect(ptr->cur());
   }
   _down_pt_2d = _down_pt;

   //Notify all the CAMobs's of the start of mouse down
  
   data->start_manip();
   return 0;
}
Esempio n. 6
0
///////////////////////////////////////////////////
//scale_z: scales the selected model 
//              based on mouse movement
///////////////////////////////////////////////////
int  
Cam_int_edit::scale_z   
(CEvent &e,
 State *&s)
{
   CAMptr      cam (e.view()->cam());
   CAMdataptr  data(cam->data());
   DEVice_2d  *ptr=(DEVice_2d *)e._d;
   
   if(_model == NULL)
      return 0;

   XYpt tp   = ptr->old(); 
   XYpt te  = ptr->cur();

   double Scale;
   double dist = te[1]-tp[1];

   //rotate the Y-axis
   if(dist < 0)
      Scale = 1-(abs(dist));
   else
      Scale = 1+(abs(dist));

   Wtransf xf = _model->obj_to_world() * Wtransf::scaling(1,1,Scale);

   _model->set_xform(xf);
 
   return 0;

}
Esempio n. 7
0
int
Cam_int::iconup(
   CEvent &e, 
   State *&s
   )
{
   if (debug_fsa)
      cerr << "Cam_int::iconup"
           << endl;

   if (_resizing) {
      _resizing = false;
      const int retval = _icon->resize_up(e, s);
      _icon = nullptr;
      return retval;
   }
   DEVice_buttons *btns=(DEVice_buttons *)e._d;
   DEVice_2d      *ptr=btns->ptr2d();
   PIXEL           curpt(ptr->cur());

   // Delete
   if (the_time() - _dtime < 0.25 && _icon &&
       (curpt - _start_pix).length() > 20 &&
       (curpt - _start_pix).normalized() * VEXEL(1,1).normalized() > 0.5) {
      _icon->remove_icon();
      _icon = nullptr;
      return 0;
   }

   if (_icon->intersect_icon(ptr->cur())) {
      new CamFocus(e.view(), _icon->cam());
   }
   return 0;
}
Esempio n. 8
0
int
Cam_int::down(
   CEvent &e, 
   State *&s
   )
{
   if (debug_fsa)
      cerr << "Cam_int::down"
           << endl;

   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();
   VIEWptr         view(e.view());
   bool            is_dot = _camwidg.anchor_displayed();
   int             x, y; view->get_size(x,y);
   PIXEL           curpix(ptr->cur());
   XYpt            curpt (curpix[0]/x*2-1, curpix[1]/y*2-1);

   predown(e,s);

   // Did we click on a camera icon?
   CamIcon *icon = CamIcon::intersect_all(ptr->cur()); 
   if (icon) {

      // XXX - fix

      _icon = icon;
      switch (icon->test_down(e, s)) {
       case CamIcon::RESIZE :
         _resizing = true;
         // drops through to next case:
       case CamIcon::FOCUS  :
         s = &_icon_click;
         break;
       case CamIcon::MOVE   :
         s = &_move_view;
         return move(e, s);
      }
      return 0;
   } else if ((fabs(curpt[0]) > .85 || fabs(curpt[1]) > .9) || is_dot) {
      if (is_dot)
         view->cam()->data()->set_center(_camwidg.anchor_wpt());
      _do_reset = is_dot;

      if (!is_dot){
         /* alexni- is there a better way to handle this?  we want to
          * save the camera if we're going to enter a mode that causes
          * change to the camera
          */
         _view->save_cam();
      }

      s = &_cam_rot;
      return 0;
   }

   return 0;
}
Esempio n. 9
0
int
Pen::check_interactive(CEvent &e, State *&s)
{
   DEVice_buttons *btns=(DEVice_buttons *)e._d;
   DEVice_2d      *ptr=btns->ptr2d();
   RAYhit r(ptr->cur());

   return (e.view()->intersect(r).success() &&
           ray_geom(r,GEOM::null) &&
           ray_geom(r,GEOM::null)->interactive(e,s));
}
Esempio n. 10
0
int
Cam_int::focus(
   CEvent &e,
   State *&
   ) 
{
   if (debug_fsa)
      cerr << "Cam_int::focus"
           << endl;

   GEOM::find_cam_focus(e.view(), DEVice_2d::last->cur());
   return 0;
}
Esempio n. 11
0
int
Cam_int_edit::rot2(
   CEvent &e,
   State *&
   )
{
   CAMptr  cam(e.view()->cam());

   cam->set_zoom(1);
   cam->set_min(NDCpt(XYpt(-1,-1)));
   cam->data()->changed();

   return 0;
}
Esempio n. 12
0
int
Cam_int::dragup(
   CEvent &e, 
   State *&s
   )
{
   if (debug_fsa)
      cerr << "Cam_int::dragup"
           << endl;

   DEVice_buttons *btns=(DEVice_buttons *)e._d;
   DEVice_2d      *ptr=btns->ptr2d();
   VIEWptr         view(e.view());
   CAMptr          cam (view->cam());
   PIXEL           curpt(ptr->cur());

   double elapsed = the_time() - _dtime;
   // Are we close to the cam globe?
   if (ptr->cur().dist(_camwidg.anchor_pos()) < DOT_DIST && elapsed < 0.25)
      return up(e,s);
   
   reset(1);

   set<UPobs*>::iterator i;
   for (i = _up_obs.begin(); i != _up_obs.end(); ++i)
      (*i)->reset(_do_reset);  // reset everyone watching us

   if ((curpt - _start_pix).length() > 20 &&
       (curpt - _start_pix).normalized() * VEXEL(-1,0).normalized() > 0.5)
      return 0;
   
   RAYhit ray(view->intersect(_camwidg.anchor_pos()));
   if (!ray.success())
      return 0;

   CAMdataptr data(cam->data());
   double dist = _camwidg.anchor_size() * 2*data->focal()/data->height();
   Wvec dirvec((data->from() - ray.surf()).normalized());

   Wpt from = ray.surf() + dist * dirvec;
   new CamFocus(view, 
                from,                   // from
                ray.surf(),             // at
                from + Wvec::Y(),       // up
                ray.surf(),             // center
                data->width(), data->height());

   return 0;
}
Esempio n. 13
0
int
Cam_int::rot(
   CEvent &e, 
   State *&
   ) 
{
   if (debug_fsa)
      cerr << "Cam_int::rot"
           << endl;

   CAMptr      cam (e.view()->cam());
   CAMdataptr  data(cam->data());
   DEVice_2d  *ptr=(DEVice_2d *)e._d;

   cam->set_zoom(1);
   cam->set_min(NDCpt(XYpt(-1,-1)));
   cam->data()->changed();

   XYpt        cpt   = data->center();
   double      radsq = sqr(1+fabs(cpt[0])); // squared rad of virtual cylinder
   XYpt        tp    = ptr->old(); 
   XYpt        te    = ptr->cur();

   Wvec   op  (tp[0], 0, 0);             // get start and end X coordinates
   Wvec   oe  (te[0], 0, 0);             //    of cursor motion
   double opsq = op * op, oesq = oe * oe;
   double lop  = opsq > radsq ? 0 : sqrt(radsq - opsq);
   double loe  = oesq > radsq ? 0 : sqrt(radsq - oesq);
   Wvec   nop  = Wvec(op[0], 0, lop).normalized();
   Wvec   noe  = Wvec(oe[0], 0, loe).normalized();
   double dot  = nop * noe;

   if (fabs(dot) > 0.0001) {
      data->rotate(Wline(data->center(), Wvec::Y()),
                   -2*Acos(dot) * Sign(te[0]-tp[0]));

      double rdist = te[1]-tp[1];

      CAMdata   dd = CAMdata(*data);

      Wline raxe(data->center(),data->right_v());
      data->rotate(raxe, rdist);
      data->set_up(data->from() + Wvec::Y());
      if (data->right_v() * dd.right_v() < 0)
         *data = dd;
   }

   return 0;
}
Esempio n. 14
0
int
Cam_int_edit::pan2(
   CEvent &e,
   State *&
   )
{
   DEVice_2d  *ptr=(DEVice_2d *)e._d;
   CAMptr      cam  (e.view()->cam());
   PIXEL       curpt(ptr->cur());

   cam->set_min(cam->min() + NDCvec(ptr->delta()));
   cam->data()->changed();
   ptr->set_cur(curpt);
   return 0;
}
Esempio n. 15
0
int
Cam_int_edit::up(
   CEvent &e, 
   State *&s
   )
{
//   DEVice_buttons *btns=(DEVice_buttons *)e._d;
//   DEVice_2d      *ptr=btns->ptr2d();
   VIEWptr         view(e.view());
   CAMptr          cam (view->cam());

   _model = NULL;
   cam->data()->end_manip();
   return 0;
}
Esempio n. 16
0
int
Cam_int_edit::pan(
   CEvent &e,
   State *&
   )
{
   DEVice_2d  *ptr=(DEVice_2d *)e._d;
   CAMptr      cam  (e.view()->cam());
   CAMdataptr  data (cam->data());
   Wvec        delta(Wpt(ptr->cur(),_down_pt) - Wpt(ptr->old(),_down_pt));

   data->translate(-delta);
   data->set_at(Wline(data->from(), data->at_v()).project(_down_pt));
   data->set_center(data->at());
   return 0;
}
Esempio n. 17
0
////////////////////////////////////////////////////
//edit_down: grabs the model that is clicked on for
//                   editing
/////////////////////////////////////////////////////
int 
Cam_int_edit::edit_down (
   CEvent &e,
   State *&s)
{
   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();

   _view = e.view();

   CAMdataptr  data(_view->cam()->data());
   RAYhit      r   (_view->intersect(ptr->cur()));
   if (r.success()) 
      _model = (ray_geom(r,GEOM::null));
   return 0;
                
}
Esempio n. 18
0
int
Cam_int::rot2(
   CEvent &e,
   State *&
   )
{
   if (debug_fsa)
      cerr << "Cam_int::rot2"
           << endl;

   CAMptr  cam(e.view()->cam());

   cam->set_zoom(1);
   cam->set_min(NDCpt(XYpt(-1,-1)));
   cam->data()->changed();

   return 0;
}
Esempio n. 19
0
int
Cam_int::pan2(
   CEvent &e,
   State *&
   )
{
   if (debug_fsa)
      cerr << "Cam_int::pan2"
           << endl;

   DEVice_2d  *ptr=(DEVice_2d *)e._d;
   CAMptr      cam  (e.view()->cam());
   PIXEL       curpt(ptr->cur());

   cam->set_min(cam->min() + NDCvec(ptr->delta()));
   cam->data()->changed();
   ptr->set_cur(curpt);
   return 0;
}
Esempio n. 20
0
int
Cam_int::zoom(
   CEvent &e,
   State *&
   )
{
   if (debug_fsa)
      cerr << "Cam_int::zoom"
           << endl;

   DEVice_2d *ptr=(DEVice_2d *)e._d;
   CAMptr     cam  (e.view()->cam());
   CAMdataptr data (cam->data());
   XYvec      delta(ptr->delta());
   double     ratio;

   if (data->persp()) {
      Wvec    movec(_down_pt - data->from());

      data->set_center(_down_pt);
      data->translate(movec.normalized() * (movec.length() * delta[1] * -4));
   
      ratio = cam->height() / cam->width() * 
         (movec * data->at_v()) * data->width() / data->focal();

   } else {
      Wpt     spt  (XYpt(ptr->cur()[0],_scale_pt[1]));
      Wvec    svec (spt - Wline(data->from(), data->at_v()).project(spt));
      double  sfact(1 + delta[1]);
      data->translate( svec * (1.0 - sfact));
      data->set_width (data->width() * sfact);
      data->set_height(data->height()* sfact);
      ratio = data->height();
   }

   data->translate(-delta[0]/2 * data->right_v() * ratio);
   data->set_at(Wline(data->from(), data->at_v()).project(data->center()));
   data->set_center(data->at());


   return 0;
}
Esempio n. 21
0
int
Cam_int::up(
   CEvent &e, 
   State *&s
   )
{
   if (debug_fsa)
      cerr << "Cam_int::up"
           << endl;

   DEVice_buttons *btns=(DEVice_buttons *)e._d;
   DEVice_2d      *ptr=btns->ptr2d();
   VIEWptr         view(e.view());
   CAMptr          cam (view->cam());

   set<UPobs*>::iterator i;
   for (i = _up_obs.begin(); i != _up_obs.end(); ++i)
      (*i)->reset(_do_reset);  // reset everyone watching us

   if (_camwidg.anchor_displayed()) {
      if (ptr->cur().dist(_camwidg.anchor_pos()) < DOT_DIST)
         focus(e,s);
      reset(1);
   } else if (ptr->cur().dist(_down_pt_2d) < DOT_DIST) {
      RAYhit ray(view->intersect(ptr->cur()));
      if (ray.success()) {
         // Create the anchor (blue ball) on the surface:
         _camwidg.display_anchor(ray.surf());
         // If clicked on a mesh, make it the "focus":
         BMESHptr m = gel_to_bmesh(ray.geom());
         if (m)
            BMESH::set_focus(m, dynamic_cast<Patch*>(ray.appear()));
      } else {
         Wplane hitp(cam->data()->center(), cam->data()->at_v());
         _camwidg.display_anchor(hitp.intersect(ray.screen_point()));
      }
   }
   cam->data()->end_manip();
   return 0;
}
Esempio n. 22
0
int
FilmTrans::down(
   CEvent &e,
   State *&s
   )
{
   DEVice_buttons *btns=(DEVice_buttons *)e._d;
   DEVice_2d      *ptr=btns->ptr2d();
   RAYhit          r(ptr->cur());
   GEOMptr         geom;

   _view = e.view();
   if (_view->intersect(r,VIEW::H_TEXT).success() && GEOM::isa(r.geom())) {
      geom = ray_geom(r, GEOM::null);
      if (geom->interactive(e, s, &r)) {
         _obj      = 0;
         _no_xform = 1;
         return 1; // Interactive - return....
      }
   }
   // interactive() could have changed r so that now !success(),
   //  so we have to check again
   if (!r.success() || (geom && NO_XFORM_MOD.get(geom))) {
      _no_xform = 1;
      _obj      = geom;
   } else {
      if (CONSTRAINT.get(geom) == GEOM::SCREEN_WIDGET)
           _down_pt = geom->xform();
      else _down_pt = r.surf();

      _down_norm = r.norm();
      _obj       = geom;

      if (_call_xform_obs)
         XFORMobs::notify_xform_obs(_obj, XFORMobs::START);
      _no_xform = 0;
   }

   return 0;
}
Esempio n. 23
0
int
Cam_int_fp::down(
   CEvent &e, 
   State *&s
   )
{
   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();
   VIEWptr         view(e.view());
   int             is_dot = _camwidg.anchor_displayed();
   int             x, y; view->get_size(x,y);
   PIXEL           curpix(ptr->cur());
   XYpt            curpt (curpix[0]/x*2-1, curpix[1]/y*2-1);

   //set timer...
   _clock.set();

   predown(e,s);
   if(CamBreathe::cur()) CamBreathe::cur()->pause();


   // Did we click on a camera icon?
   CamIcon *icon = CamIcon::intersect_all(ptr->cur()); 
   if (icon) {
      // XXX - fix
      _icon = icon;
      switch (icon->test_down(e, s)) {
       case CamIcon::RESIZE : _resizing = true;
       case CamIcon::FOCUS  : s = &_icon_click;
         brcase CamIcon::MOVE   : {
            s = &_move_view;
            return move(e, s);
         }
      }
      return 0;
   } else
      {
         if (is_dot)
Esempio n. 24
0
///////////////////////////////////////////////////
//rot_x: rotates selected model around the x-axis
///////////////////////////////////////////////////
int  
Cam_int_edit::rot_x   
(CEvent &e,
 State *&s)
{
   CAMptr      cam (e.view()->cam());
   CAMdataptr  data(cam->data());
   DEVice_2d  *ptr=(DEVice_2d *)e._d;
   
   //return if you didn't select a model to edit
   if(_model == NULL)
      return 0;

   XYpt tp  = ptr->old(); 
   XYpt te  = ptr->cur();

   //get a angle based on mouse movement(up/down)
   double angle = (te[1]-tp[1])*3;

   //rotate on the X-axis
   Wtransf xf = _model->obj_to_world() * Wtransf::rotation(Wvec::X(), angle);
   _model->set_xform(xf);
   return 0;
}
Esempio n. 25
0
int
DrawManip::down(CEvent& e, State*& s)
{
   err_adv(debug, "DrawManip::down");

   _down_pix = ptr_cur(); // used in choose_cb()

   // special handling for active curve sketch
   // XXX - needs comments
   CRV_SKETCHptr cs = CRV_SKETCH::get_instance();
   if (cs && cs->is_active()) {
      PIXEL_list pix = cs->shadow_pix();
      if (pix[0].dist(_down_pix) < 8) {
         _down = true;
         _first = true;
      } else if (pix.last().dist(_down_pix) < 8) {
         _down = true;
         _first = false;
      }
   }

   assert(e.view() != 0);
   BMESHray ray(ptr_cur());
   e.view()->intersect(ray);
   GEOMptr geom;
   if (ray.success()) {
      geom = GEOM::upcast(ray.geom());
      if (geom && geom->interactive(e, s, &ray)) {
         return 1; // geom is taking over remaining events until up event
      }
      _down_pt = ray.surf();                    
      _vec = ray.norm();
   }

   if (init_point(Bpoint::hit_ctrl_point(ptr_cur()),s) ||
       init_curve(Bcurve::hit_ctrl_curve(ptr_cur(), 6, _down_pt),s)) {
      return 0; // all set
   }
   if (FLOOR::isa(geom)) {
      // XXX - should handle floor manipulation
      return 0;
   }
   // this part seems to crash on windows in some cases...
   // turning it off for now:
   bool find_components = false;
   Bvert_list verts;
   if (find_components)
      verts = Bvert_list::connected_verts(VisRefImage::get_simplex(ptr_cur()));

   // map vertices to Bbase controllers at top level of subdiv hierarchy:
   Bbase_list bbases = Bbase::find_controllers(verts).get_ctrl_list();
   if (debug) {
      cerr << "  found " << bbases.num() << " controllers:" << endl << "  ";
      bbases.print_identifiers();
   }
   err_adv(debug, "  same mesh: %s", bbases.same_mesh() ? "true" : "false");

   if (bbases.empty() && !geom)
      return 0;

   _cmd = bbases.empty() ? new MOVE_CMD(geom) : new MOVE_CMD(bbases);
   assert(_cmd);
   WORLD::add_command(_cmd);
   _cmd->notify_xf_obs(XFORMobs::START);

   return 0;
}
Esempio n. 26
0
int
Cam_int_edit::down2(
   CEvent &e, 
   State *&s
   )
{
   DEVice_buttons *btns = (DEVice_buttons *)e._d;
   DEVice_2d      *ptr  = btns->ptr2d();

   _view = e.view();

   CAMdataptr  data(_view->cam()->data());
   RAYhit      r   (_view->intersect(ptr->cur()));
   if (r.success()) {
      //////////////////
      //Scale Button
      //////////////////
      if(r.geom()->name() == "scale")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_scale)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("scale");
                  s = &_scale;
               }
         }
      //////////////////
      //ScaleX Button
      //////////////////
      if(r.geom()->name() == "scalex")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_scalex)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("scalex");
                  s = &_scalex;
               }
         }
      //////////////////
      //ScaleY Button
      //////////////////
      if(r.geom()->name() == "scaley")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_scaley)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("scaley");
                  s = &_scaley;
               }
         }
      //////////////////
      //ScaleZ Button
      //////////////////
      if(r.geom()->name() == "scalez")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_scalez)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("scalez");
                  s = &_scalez;
               }
         }
      //////////////////
      //Rotate Button
      //////////////////
      if(r.geom()->name() == "rotateX")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_rot_x)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("rotateX");
                  s = &_rot_x;
               }
         }
      //////////////////
      //RotateY Button
      //////////////////
      if(r.geom()->name() == "rotateY")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_rot_y)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("rotateY");
                  s = &_rot_y;
               }
         }
      //////////////////
      //Rotate Button
      //////////////////
      if(r.geom()->name() == "rotateZ")
         {
            BaseJOTapp::deactivate_button();
            if(s == &_rot_z)
               s = (State *)-1;
            else
               {
                  BaseJOTapp::activate_button("rotateZ");
                  s = &_rot_z;
               }
         }
      /////////////////
      //Eye Button
      ////////////////
      else if(r.geom()->name() == "eye_button")
         {
            s = (State *)-1;
            BaseJOTapp::cam_switch(e,s);
         }
   }
   return 0;
}
Esempio n. 27
0
int 
Cam_int_edit::choose(
   CEvent &e,
   State *&s
   )
{
   DEVice_2d *ptr =(DEVice_2d *)e._d;
   PIXEL      te   (ptr->cur());
   XYvec      delta(ptr->delta());
   double     tdelt(the_time() - _dtime);
   
   _dist += sqrt(delta * delta);

   VEXEL sdelt(te - _start_pix);

   int xa=0,ya=1;
   if (Config::get_var_bool("FLIP_CAM_MANIP",false,true))
      swap(xa,ya);
     
   if (fabs(sdelt[ya])/sdelt.length() > 0.9 && tdelt > 0.05) {
      s = &_cam_zoom;
      ptr->set_old(_start_pix);
   } else if (tdelt < 0.1 && _dist < 0.03)
      return 0;
   else {
      if (fabs(sdelt[xa])/sdelt.length() > 0.6 )
         s = &_cam_pan;
      else s = &_cam_zoom;
      ptr->set_old(_start_pix);
   }
   /* if we got this far, we actually have a valid choice, so save the camera */   VIEWptr         view(e.view());
   view->save_cam();

   return 0;
}
Esempio n. 28
0
int
DrawManip::choose_cb(CEvent &e, State *&s)
{
   // Based on initial motion, decide whether to constrain motion
   // to the selected Bpoint's y-axis, or to the plane
   // perpendicular to its y-axis.
   //
   // If the plane is nearly edge-on don't prefer constraining in
   // plane
   //
   // If y-axis is nearly tip-on, don't prefer motion along it.
   err_adv(debug, "DrawManip::choose_cb");

   if (!plane().is_valid()) {
      // _vec and _down_pt must be set in down() callback
      err_adv(debug, "  error: invalid plane");
      return 0;
   }

   PIXEL cur = ptr_cur();
   if (_down_pix.dist(cur) > 6) {
      // Pointer moved over 6 pixels... we're ready to choose

      _down_pix = cur;

      Wpt      eye = e.view()->cam()->data()->from();
      Wvec eye_vec = (eye - _down_pt).normalized();
      Wvec       n = _vec.normalized();
      double dot = fabs(eye_vec * n);
      if (dot > cos(deg2rad(15))) {
         // Angle between view vector and plane normal is less
         // than 15 degrees.  Constrain motion to plane.
         err_adv(debug, "  onto plane");
         s = &_plane_trans;
      } else if (dot < cos(deg2rad(85))) {
         // Angle between view vector and plane normal is
         // greater than 85 degrees. I.e., plane is
         // foreshortened.  Constrain motion to axis.
         err_adv(debug, "  foreshortened plane");
         s = &_line_trans;
      } else {
         // Viewing is not too extreme either way.  For a
         // Bpoint with no ability to do a line constraint,
         // do a plane constraint.

         // Check angle in film plane; if motion is aligned
         // w/ the axis we'll do constraint along the
         // axis. Otherwise in the plane:
         Wpt   o = _down_pt;
         PIXEL film_o = o;
         VEXEL film_y = (PIXEL(o + n) - film_o).normalized();
         VEXEL film_d = (cur     - film_o).normalized();
         dot = fabs(film_d * film_y);
         if (dot > cos(deg2rad(25))) {
            // moving along axis
            // constrain motion to axis
            s = &_line_trans;
            err_adv(debug, "  line constraint");
         } else {
            // moving cross-ways to axis
            // constrain motion to plane
            s = &_plane_trans;
            err_adv(debug, "  plane constraint");
         }
      }
   }

   return 0;
}