Esempio n. 1
0
int
INFLATE::stroke_cb(CGESTUREptr& gest, DrawState*& s)
{
   err_adv(debug, "INFLATE::stroke_cb");

   reset_timeout();

   // Verify that we have a starting face
   if ( _orig_face ) {
      Bface* face = 0;

      // Check that the stroke is straight enough to represent a line
      if (!(gest->straightness() > 0.8)) {
         err_adv(debug, "INFLATE::stroke_cb: gesture not straight");
         return false;
      }

      // Check that the gesture starts on the mesh
      Bsurface::hit_ctrl_surface(gest->start(), 1, &face);
      if (!(face)) {
         err_adv(debug, "INFLATE::stroke_cb: can't get hit face");
         return false;
      }

      // create VEXELs for the gesture and the face normal
      VEXEL fvec  = VEXEL(face->v1()->loc(), face->norm());
      VEXEL fgest = gest->endpt_vec();

      // If gesture nearly parallel to normal:
      double a = rad2deg(line_angle(fvec,fgest));
      err_adv(debug, "INFLATE::stroke_cb: angle: %f %s",
              a, (a > 15) ? "(bad)" : "(good)");
      if (a > 15) {
         // Fail if angle is too extreme
         WORLD::message("Bad angle");
         return 0;
      }

      // calculate extrude width
      double dist = fgest.length()/fvec.length();

      err_adv(debug, "INFLATE::stroke_cb: strong_edge_len: %f, gest_len: %f, \
fvect_len: %f", avg_strong_edge_len(face), fgest.length(), fvec.length() );

      // Convert to relative to local edge length
      dist /= avg_strong_edge_len(face);
      if (fvec*fgest<0)
         dist=-dist; // Get the sign right

      // Store the new inflate distance
      _preview_dist = dist;
   }

   return 1;    // we used up the gesture...
}
Esempio n. 2
0
int
INFLATE::line_cb(CGESTUREptr& gest, DrawState*& s)
{
   // Activity occurred to extend the deadline for fading away:
   reset_timeout();

   err_adv(debug, "INFLATE::line_cb");

   // Verify that we have a starting face
   if ( _orig_face ) {
      // Check that the stroke is straight enough to represent a line
      Bface* face = 0;
      if (!(gest->straightness() > 0.8)) {
         err_adv(debug, "INFLATE::line_cb: gesture not straight");
         return false;
      }

      // Check that the gesture starts on the mesh
      Bsurface::hit_ctrl_surface(gest->start(), 1, &face);
      if (!(face)) {
         err_adv(debug, "INFLATE::line_cb: can't get hit face");
         return false;
      }

      // create VEXELs for the gesture and the face normal
      VEXEL fvec  = VEXEL(face->v1()->loc(), face->norm());
      VEXEL fgest = gest->endpt_vec();

      // If gesture nearly parallel to normal:
      double a = rad2deg(line_angle(fvec,fgest));
      err_adv(debug, "INFLATE::line_cb: angle: %f %s",
              a, (a > 15) ? "(bad)" : "(good)");
      if (a > 15) {
         return false;
      }

      // calculate extrude width
      double dist = fgest.length()/fvec.length();
      if (fvec*fgest<0)
         dist=-dist; // Get the sign right

      _preview_dist = dist;
   }

   // get here if nothing happened...
   // don't cancel (which would deactivate the widget),
   // just return 1 to indicate that we used up the gesture:
   return 1;
}