Exemplo n.º 1
0
void
scale_along_normal(
   CGEOMptr &obj,
   CWpt     &scale_cent,
   CWpt     &down_pt,
   CWvec    &down_norm,
   CXYpt    &cur
   )
{
   Wtransf xf  (obj->xform());
   Wpt     dpt (xf * down_pt);
   Wpt     spt (xf * scale_cent);
   Wvec    upv ((xf * down_norm).normalized());

   if (upv * (dpt - spt) < 0)
      upv = -upv;

   if ((cur - XYpt(dpt)).length() < 0.01)
      return;

   Wpt npt(Wline(dpt,upv).intersect(cur));
   Wpt ctr(xf * scale_cent);
   double  sval(((npt-dpt) * upv) / (dpt-ctr).length());

   if ((npt-ctr) * (dpt-ctr) < 0)
      return;

   Wvec   dnorm (fabs(down_norm[0]),fabs(down_norm[1]),
                  fabs(down_norm[2]));

   ((GEOMptr)obj)->set_xform(xf *
                  Wtransf::scaling(scale_cent, 
                                    (dnorm*sval+Wvec(1,1,1))));
}
Exemplo n.º 2
0
FPS::FPS()
{
   XYpt c = lr_corner_loc(50, 10);
   // ugh, the above is broken since window dimensions are not
   // available when this is called... switching to hack for now:
   c = XYpt(0.671875,-0.95); // fixed below in tick()

   _text = new TEXT2D(str_ptr("fps"), str_ptr::null, c);

   _text->set_loc(c);
   _text->set_string(str_ptr(""));

   GEOMptr text(&*_text);
   NETWORK       .set(text, 0);
   NO_COLOR_MOD  .set(text, 1);
   NO_XFORM_MOD  .set(text, 1);
   NO_DISP_MOD   .set(text, 1);
   NO_COPY       .set(text, 1);
   DONOT_CLIP_OBJ.set(text, 1);

   WORLD::create(text, false);

   _last_display = VIEW::stamp();
   _clock.set();
}
Exemplo n.º 3
0
extern "C" void
normal_keydown_callback(unsigned char k, int x, int y)
{
   GLUT_MANAGER *mgr = (GLUT_MANAGER *)FD_MANAGER::mgr(); assert(mgr);
   // XXX - Just block events to the blocking window, or all windows?
   //       Rightnow, we only use one window, so this is academic...
   if (mgr->get_blocker() == GLUT_WINSYS::window()) return;

   static bool debug = Config::get_var_bool("JOT_DEBUG_KEY_CALLBACKS",false,true);
   if (debug)
      err_msg("key pressed: %d", int(k));

   GLUT_KBD *kbd = GLUT_KBD::kbd();

   int w, h;
   kbd->winsys()->size(w, h);

   VIEWptr view = GLUT_WINSYS::window()->view();

   VIEWint_list::get(view)->handle_event(Evd(k));
   
   CXYpt curs(PIXEL(x, (double) h - y));

   kbd->update_mods(curs);
}
Exemplo n.º 4
0
int
FilmTrans::move(
   CEvent &e,
   State *&
   )
{
   DEVice_2d* ptr = dynamic_cast<DEVice_2d*>(e._d);
   assert(ptr);
   if (_obj) {
      Wpt cur(Wpt(ptr->cur(),_down_pt));
      Wpt old(Wpt(ptr->old(),_down_pt));
      _obj->mult_by(Wtransf::translation(cur-old));
      if (_call_xform_obs)
         XFORMobs::notify_xform_obs(_obj, XFORMobs::MIDDLE);
   }

   return 0;
}
Exemplo n.º 5
0
RAYhit &
LINE3D::intersect(
   RAYhit  &ray,
   CWtransf&,
   int 
   ) const
{
   // Find the intersection point, its distance, and some kind of normal
   double distance = -1, d_2d = -1;
   Wvec   surf_norm;
   Wpt    nearpt;

   for (int i=0; i<num()-1; i++) {

      // Find the nearest point on the ray to the segment.
      Wpt ray_pt = ray.line().intersect(Wline(point(i), point(i+1)));

      // Accept only if ray_pt is in front of the ray
      if ((ray_pt - ray.point()) * ray.vec() > 0 ) {

         // Ok if the ray passes within 10 pixels of the segment
         const double PIX_THRESH = 10.0;
         Wpt hit_pt = nearest_pt_to_line_seg(ray_pt, point(i), point(i+1)); 
         double screen_dist = PIXEL(hit_pt).dist(ray_pt);
         if ((screen_dist < PIX_THRESH) && (d_2d < 0 || screen_dist < d_2d)) {
            d_2d      = screen_dist;
            distance  = ray.point().dist(ray_pt);
            nearpt    = hit_pt;

            // XXX - What should be the "normal"?  For now,
            //       just the vector pointing back to the camera.
            surf_norm = -ray.vec().normalized();
         }
      } 
   }

   // Then call ray.check() passing it all this stuff
   if (distance >= 0)
      ray.check(distance, 1, 0, (GEL*)this, surf_norm, nearpt, nearpt,
                0, XYpt());
   return ray;
}
Exemplo n.º 6
0
void
EdgeStrokePool::put_edge_strip(TAGformat &d) const
{
   ARRAY<Point2i> edge_strip;

   CARRAY<Bvert*> &verts = _strip.verts();
   CARRAY<Bedge*> &edges = _strip.edges();

   assert(verts.num() == edges.num());

   for (int i=0; i<verts.num(); i++) 
      edge_strip += Point2i(verts[i]->index(),edges[i]->index());

   d.id();
   *d << edge_strip;
   d.end_id();

}
Exemplo n.º 7
0
extern "C" void
normal_keyup_callback(unsigned char k, int x, int y)
{
   GLUT_MANAGER *mgr = (GLUT_MANAGER *)FD_MANAGER::mgr(); assert(mgr);
   // XXX - Just block events to the blocking window, or all windows?
   //       Rightnow, we only use one window, so this is academic...
   if (mgr->get_blocker() == GLUT_WINSYS::window()) return;

   GLUT_KBD *kbd = GLUT_KBD::kbd();
   VIEWptr view = GLUT_WINSYS::window()->view();

   VIEWint_list::get(view)->handle_event(Evd(k,KEYU));

   int w, h;
   kbd->winsys()->size(w, h);
   CXYpt curs(PIXEL(x, (double) h - y));

   kbd->update_mods(curs);
}
Exemplo n.º 8
0
using mlib::Wpt;
using mlib::Wvec;

HASH *DATA_ITEM::_hash = 0;
DATA_ITEM* (*DATA_ITEM::_decode_unknown)(STDdstream&, Cstr_ptr&, DATA_ITEM*) = 0;

const str_ptr NAME_INT    ("int");
const str_ptr NAME_DOUBLE ("double");
const str_ptr NAME_VEC3D  ("vec3d");
const str_ptr NAME_COLOR  ("color");
const str_ptr NAME_POINT3D("point3d");
const str_ptr NAME_STR_PTR("str_ptr");

static int im=DATA_ITEM::add_decoder(NAME(0),     new TDI<int>(0), 1);
static int dm=DATA_ITEM::add_decoder(NAME(0.0),   new TDI<double>(0), 1);
static int vm=DATA_ITEM::add_decoder(NAME(Wvec()),new TDI<Wvec>(Wvec(0,1,0)), 1);
static int pm=DATA_ITEM::add_decoder(NAME(Wpt()), new TDI<Wpt>(Wpt()), 1);
static int sm=DATA_ITEM::add_decoder(NAME(str_ptr()),new TDI<str_ptr>(str_ptr()), 1);

// for some odd reason, we can't inline this on the Suns because
// it generates link errors when we create subclasses of DATA_ITEM...
// the odd thing is it doesn't seem to effect subclasses of DATA_ITEM
// that *are* able to define static_name inline...
//
STAT_STR_RET
DATA_ITEM::static_name()
{ 
   RET_STAT_STR("DATA_ITEM"); 
}

DATA_ITEM::~DATA_ITEM() 
Exemplo n.º 9
0
int
TRACE::draw(CVIEWptr&)
{
   if (!valid()) {
      return 0;
   }

   // load identity for model matrix
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();

   // set up to draw in PIXEL coords:
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadMatrixd(VIEW::peek()->xypt_proj().transpose().matrix());
   
   // Set up line drawing attributes
   glPushAttrib(GL_ENABLE_BIT);

   glDisable(GL_LIGHTING);              // GL_ENABLE_BIT
   glEnable(GL_TEXTURE_2D);             // GL_ENABLE_BIT
   glDisable(GL_CULL_FACE);             // GL_ENABLE_BIT
   glDisable(GL_DEPTH_TEST);            // GL_ENABLE_BIT

   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   _texture->apply_texture();           // GL_ENABLE_BIT

   if (_calib_mode_flag) {
      // no transparency if we are in calibration
      glColor4f(1.0,1.0,1.0,0.5);
      if(_cur_calib_pt_index==0){
         WORLD::message("Calibrate trace: click upper left");
      } else if(_cur_calib_pt_index==1){
         WORLD::message("Calibrate trace: click lower right");
      }
   } else {
      glColor4f(1.0, 1.0, 1.0, 0.5);
   }

   // begin drawing
   glBegin(GL_QUAD_STRIP);
   
   XYpt topleft, topright, bottomleft, bottomright;
   
   if (_calibrated) {
      // if we are calibrated, use the corners we got from
      // calibration
                
      if(_cur_calib_pt_index == 4){ 
         topleft     = _samples[_TOP_LEFT];
         topright    = _samples[_TOP_RIGHT];
         bottomleft  = _samples[_BOTTOM_RIGHT];
         bottomright = _samples[_BOTTOM_LEFT];
      } else if(_cur_calib_pt_index == 2){
         topleft     = _samples[0];
         topright    = XYpt( _samples[1][0], _samples[0][1]);
         bottomright = _samples[1];
         bottomleft  = XYpt(_samples[0][0], _samples[1][1]);
      }
   } else {
      // if we aren't calibrated, then draw the image over
      // the whole window
      double tex_dim[2];
      Point2i ts = _texture->get_size();
      tex_dim[0] = ts[0]; tex_dim[1] = ts[1];
      if(tex_dim[1] >= tex_dim[0]){
         tex_dim[0] = (1.0*tex_dim[0])/tex_dim[1];
         tex_dim[1] = 1.0;
      } else {
         tex_dim[1] = (1.0*tex_dim[1])/tex_dim[0];
         tex_dim[0] = 1.0;
      }
          
      topleft     = XYpt(-tex_dim[0],  tex_dim[1]);
      topright    = XYpt( tex_dim[0],  tex_dim[1]);
      bottomleft  = XYpt(-tex_dim[0], -tex_dim[1]);
      bottomright = XYpt( tex_dim[0], -tex_dim[1]);
   }
   
   glTexCoord2f(0.0, 1.0); glVertex2dv(topleft.data());
   glTexCoord2f(0.0, 0.0); glVertex2dv(bottomleft.data());
   glTexCoord2f(1.0, 1.0); glVertex2dv(topright.data());
   glTexCoord2f(1.0, 0.0); glVertex2dv(bottomright.data());
   
   glEnd();
   
   glPopAttrib();
   
   if (_calib_mode_flag) {
      // if we are in calibration mode, draw point or else indicate
      // where the user is supposed to tap next
   }

   glMatrixMode(GL_PROJECTION);
   glPopMatrix(); // unloads our projection matrix
   glMatrixMode(GL_MODELVIEW);
   glPopMatrix(); // unloads model matrix

   return 1;
}