Exemplo n.º 1
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;

}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
int 
CameraPath::read_stream ( iostream& is ) { 

   STDdstream in(&is);
   int fnum;
   double ftime;
   CAMptr cptr = make_shared<CAM>("state");
   in >> fnum;
   for ( int i=0; i < fnum; i++ ) { 
      cerr << "frame " << i << endl;
      in >> ftime;
      CAMdataptr cd = cptr->data(); // XXX - temp variable to avoid warnings
      in >> cd;                 //          here
      state_list.push_back(new CamState ( ftime, cptr ));
   }
   return 1;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
void 
Recorder::pre_draw_CB()
{
   //set/get time, cam_pos, etc...
   CAM tmp("temp");
   
   if ( !_cur_path )
      return;

   if ( !_paused ) { 

      if ( _sync && ( _path_pos > _target_frame ) )
         replay();
      
      double ttime = _swatch->elapsed_time();
      
      if ( _play_on )  { 

         //forward to closest path after current time
         if ( _path_pos >= (int)_cur_path->state_list.size() ||
              _cur_path->state_list.empty() ) {
            cerr << "end of state list reached::camera stop" << endl;
            rec_stop() ; 
            return; 
         } 

         if ( _render_on || _play_all_frames ) {

            CAMptr mine = (_cur_path->state_list[_path_pos]->cam());          
            _view->cam()->data()->set_from ( mine->data()->from() );
            _view->cam()->data()->set_at ( mine->data()->at() );
            _view->cam()->data()->set_up ( mine->data()->up() );
            _view->cam()->data()->set_center ( mine->data()->center() );
            _view->cam()->data()->set_focal ( mine->data()->focal() );
            _view->cam()->data()->set_persp ( mine->data()->persp() );
            _view->cam()->data()->set_iod ( mine->data()->iod() );
            _view->set_frame_time( _cur_path->state_list[_path_pos]->t());
            
            //update UI to reflect which frame is being shown
            _ui->set_frame_num ( _path_pos );
            
            if ( _sync ) { 
               if ( _path_pos == _target_frame )   { 
                  cerr << "at target frame: pausing:" << endl ; 
                  rec_pause(); 
               } else if ( _path_pos > _target_frame ) { 
                  cerr << "ack, we need to set back"<< endl; 
                  replay(); 
               } else _path_pos++;
            } else { 
               if ( _path_pos >= (int)_cur_path->state_list.size() -1 ) rec_stop();
               else if ( _path_pos >= _target_frame ) rec_pause();
               else _path_pos++;
            }   
         } else {                
            while ( _cur_path->state_list[_path_pos]->t() < ttime ) { 
               _path_pos++;
               if ( _path_pos >= (int)_cur_path->state_list.size()) {
                  rec_stop(); 
                  return;
               }
            }
            
            CAMptr mine = (_cur_path->state_list[_path_pos]->cam());          
            _view->cam()->data()->set_from ( mine->data()->from() );
            _view->cam()->data()->set_at ( mine->data()->at() );
            _view->cam()->data()->set_up ( mine->data()->up() );
            _view->cam()->data()->set_center ( mine->data()->center() );
            _view->cam()->data()->set_focal ( mine->data()->focal() );
            _view->cam()->data()->set_persp ( mine->data()->persp() );
            _view->cam()->data()->set_iod ( mine->data()->iod() );
            
            _view->set_frame_time( _cur_path->state_list[_path_pos]->t());
            _ui->set_frame_num ( _path_pos );
         }
         //set view camera to stored camera
      } else if ( _record_on ) { 
         while ( ttime >= _next_time ) {
            _cur_path->add( _next_time, _view->cam()); //always adds to end of list
            _path_pos = _cur_path->state_list.size()-1;
            _next_time += 1.0/_fps; //set next time to get data
            
         }       
      }
   } else if ( _paused && _play_on) {
      if ( _sync && ( _path_pos > _target_frame )  ) {
         replay();
         _paused = true; 
      }
      
      if ( _path_pos < 0 ||
           _path_pos >= (int)_cur_path->state_list.size() ||
           _cur_path->state_list.empty() ) {
         rec_stop();
         return;
      }
   }

   _ui->update_checks();
}