Пример #1
0
static eraser_state *
eraser_init (Display *dpy, Window window)
{
  eraser_state *st = (eraser_state *) calloc (1, sizeof(*st));
  XWindowAttributes xgwa;
  XGCValues gcv;
  unsigned long fg, bg;
  double duration;
  int which;
  char *s;

  st->dpy = dpy;
  st->window = window;

  XGetWindowAttributes (dpy, window, &xgwa);
  st->width = xgwa.width;
  st->height = xgwa.height;

  //bg = get_pixel_resource (dpy, xgwa.colormap, "background", "Background");
  //fg = get_pixel_resource (dpy, xgwa.colormap, "foreground", "Foreground");
  bg = load_color(dpy, xgwa.colormap, background);
  fg = load_color(dpy, xgwa.colormap, foreground);

  gcv.foreground = fg;
  gcv.background = bg;
  st->fg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv);
  gcv.foreground = bg;
  gcv.background = fg;
  st->bg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv);

# ifdef HAVE_COCOA
  /* Pretty much all of these leave turds if AA is on. */
  jwxyz_XSetAntiAliasing (st->dpy, st->fg_gc, False);
  jwxyz_XSetAntiAliasing (st->dpy, st->bg_gc, False);
# endif

  //s = get_string_resource (dpy, "eraseMode", "Integer");
  s = eraseMode;
  if (!s || !*s)
    which = -1;
  else
    //which = get_integer_resource(dpy, "eraseMode", "Integer");
    which = atoi(eraseMode);

  if (which < 0 || which >= countof(erasers))
    which = random() % countof(erasers);
  st->fn = erasers[which];

  //duration = get_float_resource (dpy, "eraseSeconds", "Float");
  duration = eraseSeconds;
  if (duration < 0.1 || duration > 10)
    duration = 1;

  st->start_time = double_time();
  st->stop_time = st->start_time + duration;

  XSync (st->dpy, False);

  return st;
}
Пример #2
0
ENTRYPOINT void
init_slideshow (ModeInfo *mi)
{
  int screen = MI_SCREEN(mi);
  slideshow_state *ss;
  int wire = MI_IS_WIREFRAME(mi);
  
  if (sss == NULL) {
    if ((sss = (slideshow_state *)
         calloc (MI_NUM_SCREENS(mi), sizeof(slideshow_state))) == NULL)
      return;
  }
  ss = &sss[screen];

  if ((ss->glx_context = init_GL(mi)) != NULL) {
    reshape_slideshow (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  } else {
    MI_CLEARWINDOW(mi);
  }

  if (debug_p)
    fprintf (stderr, "%s: pan: %d; fade: %d; img: %d; zoom: %d%%\n",
             blurb(), pan_seconds, fade_seconds, image_seconds, zoom);

  sanity_check(mi);

  if (debug_p)
    fprintf (stderr, "%s: pan: %d; fade: %d; img: %d; zoom: %d%%\n\n",
             blurb(), pan_seconds, fade_seconds, image_seconds, zoom);

  glDisable (GL_LIGHTING);
  glDisable (GL_DEPTH_TEST);
  glDepthMask (GL_FALSE);
  glEnable (GL_CULL_FACE);
  glCullFace (GL_BACK);

  if (! wire)
    {
      glEnable (GL_TEXTURE_2D);
      glShadeModel (GL_SMOOTH);
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

  if (debug_p) glLineWidth (3);

  ss->font_data = load_texture_font (mi->dpy, "titleFont");

  if (debug_p)
    hack_resources();

  ss->now = double_time();
  ss->dawn_of_time = ss->now;
  ss->prev_frame_time = ss->now;

  ss->awaiting_first_image_p = True;
  alloc_image (mi);
}
Пример #3
0
/**
 * \brief Creates a new \ref sc_dp_qc
 * 
 * \param[in] args The args structure as filled from the command line
 * \param[in] recipe The recipe the \ref sc_dp_qc will use for computation 
 */
SC_DP_QC *create_sc_dp_qc(ARGS *args, RECIPE_ADV *recipe) {
	SC_DP_QC *sc_dp_qc;
	QC *qc;
	int i, j, d, n;
	QUBIT ***q_arr;

	sc_dp_qc = (SC_DP_QC *)my_malloc(sizeof(SC_DP_QC));

	sc_dp_qc->d = d = args->d;
	sc_dp_qc->n = n = 2*d - 1;
	sc_dp_qc->ems = args->ems;

	sc_dp_qc->t1 = double_time();

	sc_dp_qc->num_checks = 0;
	sc_dp_qc->last_X_check = 0;
	sc_dp_qc->last_Z_check = 0;
	sc_dp_qc->num_X_changes = 0;
	sc_dp_qc->num_Z_changes = 0;

	// Create a new dp_qc for the sc_dp_qc
	sc_dp_qc->dp_qc = dp_create_dp_qc_adv(args->s0, args->s1, DE_HT_FACTOR * n * n,
		STICK_HT_FACTOR * d * d, args->p, args->t_delete, recipe, args->ems);
	
	// Create an n by n Pauli frame
	sc_dp_qc->frame = (int **)my_2d_calloc(n, n, sizeof(int));

	// Create an n by n array of qubits
	sc_dp_qc->q_arr = q_arr = (QUBIT ***)my_2d_calloc(n, n, sizeof(QUBIT *));
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			q_arr[i][j] = qc_create_and_insert_qubit(sc_dp_qc->dp_qc->qc, i, j, 0, QUBIT_HT_SIZE);
		}
	}
	
	// Allocate space for boundaries, and then create and insert them
	// The location of boundaries is irrelevant, but a sensible choice is good for debugging
	qc = sc_dp_qc->dp_qc->qc;

	sc_dp_qc->boundaries = (BALL **)my_malloc(8 * sizeof(BALL *));
	sc_dp_qc->bdy_s1_pr = create_boundary_set(qc, sc_dp_qc->boundaries, 0, PRIMAL_BOUNDARY, -1, 0, 0);
	sc_dp_qc->bdy_s2_pr = create_boundary_set(qc, sc_dp_qc->boundaries, 1, PRIMAL_BOUNDARY, -2, 0, 0);
	sc_dp_qc->bdy_t1_pr = create_boundary_set(qc, sc_dp_qc->boundaries, 2, PRIMAL_BOUNDARY, -1, 1, 0);
	sc_dp_qc->bdy_t2_pr = create_boundary_set(qc, sc_dp_qc->boundaries, 3, PRIMAL_BOUNDARY, -2, 1, 0);
	sc_dp_qc->bdy_s1_du = create_boundary_set(qc, sc_dp_qc->boundaries, 4, DUAL_BOUNDARY, -1, 0, 0);
	sc_dp_qc->bdy_s2_du = create_boundary_set(qc, sc_dp_qc->boundaries, 5, DUAL_BOUNDARY, -2, 0, 0);
	sc_dp_qc->bdy_t1_du = create_boundary_set(qc, sc_dp_qc->boundaries, 6, DUAL_BOUNDARY, -1, 1, 0);
	sc_dp_qc->bdy_t2_du = create_boundary_set(qc, sc_dp_qc->boundaries, 7, DUAL_BOUNDARY, -2, 1, 0);

	qc->get_boundary = get_boundary;
	qc->boundaries = (void *)sc_dp_qc->boundaries;

	// Create the Primal and Dual syndrome and set arrays 
	create_initial_syndrome_and_set_arrays(sc_dp_qc, PRIMAL, d, d-1, sc_dp_qc->bdy_s1_pr, sc_dp_qc->bdy_s2_pr);
	create_initial_syndrome_and_set_arrays(sc_dp_qc, DUAL, d-1, d, sc_dp_qc->bdy_s1_du, sc_dp_qc->bdy_s2_du);
	
	return sc_dp_qc;
}
Пример #4
0
static void
check_fps (ModeInfo *mi)
{
#ifndef HAVE_JWXYZ  /* always assume Cocoa and mobile are fast enough */

  slideshow_state *ss = &sss[MI_SCREEN(mi)];

  double start_time, end_time, wall_elapsed, frame_duration, fps;
  int i;

  start_time = ss->now;
  end_time = double_time();
  frame_duration = end_time - start_time;   /* time spent drawing this frame */
  ss->time_elapsed += frame_duration;       /* time spent drawing all frames */
  ss->frames_elapsed++;

  wall_elapsed = end_time - ss->dawn_of_time;
  fps = ss->frames_elapsed / ss->time_elapsed;
  ss->theoretical_fps = fps;

  if (ss->checked_fps_p) return;

  if (wall_elapsed <= 8)    /* too early to be sure */
    return;

  ss->checked_fps_p = True;

  if (fps >= fps_cutoff)
    {
      if (debug_p)
        fprintf (stderr,
                 "%s: %.1f fps is fast enough (with %d frames in %.1f secs)\n",
                 blurb(), fps, ss->frames_elapsed, wall_elapsed);
      return;
    }

  fprintf (stderr,
           "%s: only %.1f fps!  Turning off pan/fade to compensate...\n",
           blurb(), fps);
  zoom = 100;
  fade_seconds = 0;

  sanity_check (mi);

  for (i = 0; i < ss->nsprites; i++)
    {
      sprite *sp = ss->sprites[i];
      randomize_sprite (mi, sp);
      sp->state = FULL;
    }

  ss->redisplay_needed_p = True;

  /* Need this in case zoom changed. */
  reshape_slideshow (mi, mi->xgwa.width, mi->xgwa.height);
#endif /* HAVE_JWXYZ */
}
Пример #5
0
static Bool
eraser_draw (eraser_state *st, Bool first_p)
{
  double now = (first_p ? st->start_time : double_time());
  double duration = st->stop_time - st->start_time;

  st->prev_ratio = st->ratio;
  st->ratio = (now - st->start_time) / duration;

  if (st->ratio > 1.0)
    st->ratio = 1.0;

  st->fn (st);
  XSync (st->dpy, False);

  return (st->ratio < 1.0);
}
Пример #6
0
static void
draw_startup_blurb (ModeInfo *mi)
{
  sonar_configuration *sp = &sps[MI_SCREEN(mi)];
  const char *msg = (sp->error ? sp->error : "Resolving hosts...");
  static const GLfloat color[4] = {0, 1, 0, 1};

  if (!sp->error && ping_arg && !strcmp (ping_arg, "simulation"))
    return;  /* don't bother */

  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
  glTranslatef (0, 0, 0.3);
  draw_text (mi, msg, 0, 0, 0, 30.0);

  /* only leave error message up for N seconds */
  if (sp->error &&
      sp->start_time + 4 < double_time())
    {
      free (sp->error);
      sp->error = 0;
    }
}
Пример #7
0
ENTRYPOINT void
draw_bit (ModeInfo *mi)
{
  bit_configuration *bp = &bps[MI_SCREEN(mi)];
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int wire = MI_IS_WIREFRAME(mi);

  if (!bp->glx_context)
    return;

  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if (!wire)
    {
      GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0};
      GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  glPushMatrix ();
  glRotatef(current_device_rotation(), 0, 0, 1);
  glScalef(1.1, 1.1, 1.1);

  {
    double x, y, z;
    get_position (bp->rot, &x, &y, &z, !bp->button_down_p);
    glTranslatef((x - 0.5) * 11,
                 (y - 0.5) * 5,
                 (z - 0.5) * 3);
    gltrackball_rotate (bp->trackball);

    get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p);
    glRotatef (x * 360, 1.0, 0.0, 0.0);
    glRotatef (y * 360, 0.0, 1.0, 0.0);
    glRotatef (z * 360, 0.0, 0.0, 1.0);
  }

  mi->polygon_count = 0;

  glScalef (6, 6, 6);

  {
    int nmodel = bp->history [bp->history_fp];
    int omodel = bp->history [bp->history_fp > 0
                              ? bp->history_fp-1
                              : countof(bp->history)-1];
    double now = double_time();
    double ratio = 1 - ((bp->last_time + bp->frequency) - now) / bp->frequency;
    if (ratio > 1) ratio = 1;
    mi->polygon_count += draw_histogram (mi, ratio);
    mi->polygon_count += animate_bits (mi, omodel, nmodel, ratio);
    tick_bit (mi, now);
  }
  glPopMatrix ();

  if (mi->fps_p) do_fps (mi);
  glFinish();

  glXSwapBuffers(dpy, window);
}
Пример #8
0
static void
state_change (ModeInfo *mi)
{
  voronoi_configuration *vp = &vps[MI_SCREEN(mi)];
  double now = double_time();

  if (vp->dragging)
    {
      vp->last_time = now;
      vp->adding = 0;
      vp->zooming = 0;
      return;
    }

  switch (vp->mode)
    {
    case MODE_WAITING:
      if (vp->last_time + zoom_delay <= now)
        {
          node *tn = vp->nodes;
          vp->zoom_toward[0] = (tn ? tn->x : 0.5);
          vp->zoom_toward[1] = (tn ? tn->y : 0.5);

          vp->mode = MODE_ZOOMING;
          vp->zooming = 1;

          vp->last_time = now;
        }
      break;

    case MODE_ADDING:
      if (vp->last_time + point_delay <= now)
        {
          add_node (vp, 
                    BELLRAND(0.5) + 0.25, 
                    BELLRAND(0.5) + 0.25);
          vp->last_time = now;
          vp->adding--;
          if (vp->adding <= 0)
            {
              vp->adding = 0;
              vp->mode = MODE_WAITING;
              vp->last_time = now;
            }
        }
      break;

    case MODE_ZOOMING:
      {
        zoom_points (vp);
        if (vp->zooming <= 0)
          {
            vp->mode = MODE_ADDING;
            vp->adding = npoints;
            vp->last_time = now;
          }
      }
      break;

    default:
      abort();
    }
}
Пример #9
0
ENTRYPOINT void
draw_slideshow (ModeInfo *mi)
{
  slideshow_state *ss = &sss[MI_SCREEN(mi)];
  int i;

  if (!ss->glx_context)
    return;

  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(ss->glx_context));

  if (ss->awaiting_first_image_p)
    {
      image *img = ss->images[0];
      if (!img) abort();
      if (!img->loaded_p)
        return;

      ss->awaiting_first_image_p = False;
      ss->dawn_of_time = double_time();

      /* start the very first sprite fading in */
      new_sprite (mi);
    }

  ss->now = double_time();

  /* Each sprite has three states: fading in, full, fading out.
     The in/out states overlap like this:

     iiiiiiFFFFFFFFFFFFoooooo  . . . . . . . . . . . . . . . . . 
     . . . . . . . . . iiiiiiFFFFFFFFFFFFoooooo  . . . . . . . .
     . . . . . . . . . . . . . . . . . . iiiiiiFFFFFFFFFFFFooooo

     So as soon as a sprite goes into the "out" state, we create
     a new sprite (in the "in" state.)
   */

  if (ss->nsprites > 2) abort();

  /* If a sprite is just entering the fade-out state,
     then add a new sprite in the fade-in state.
   */
  for (i = 0; i < ss->nsprites; i++)
    {
      sprite *sp = ss->sprites[i];
      if (sp->state != sp->prev_state &&
          sp->state == (fade_seconds == 0 ? DEAD : OUT))
        new_sprite (mi);
    }

  tick_sprites (mi);

  /* Now garbage collect the dead sprites.
   */
  for (i = 0; i < ss->nsprites; i++)
    {
      sprite *sp = ss->sprites[i];
      if (sp->state == DEAD)
        {
          destroy_sprite (mi, sp);
          i--;
        }
    }

  /* We can only ever end up with no sprites at all if the machine is
     being really slow and we hopped states directly from FULL to DEAD
     without passing OUT... */
  if (ss->nsprites == 0)
    new_sprite (mi);

  if (!ss->redisplay_needed_p)
    return;

  if (debug_p && ss->now - ss->prev_frame_time > 1)
    fprintf (stderr, "%s: static screen for %.1f secs\n",
             blurb(), ss->now - ss->prev_frame_time);

  draw_sprites (mi);

  if (mi->fps_p) do_fps (mi);

  glFinish();
  glXSwapBuffers (MI_DISPLAY (mi), MI_WINDOW(mi));
  ss->prev_frame_time = ss->now;
  ss->redisplay_needed_p = False;
  check_fps (mi);
}
Пример #10
0
int
write_moos_file( char *filename, logtools_log_data_t *rec )
{
  FILE          * iop;
  struct tm     * actual_date;
  int             i, k, stop;
  double          starttime = 0, time;
  long            ticks;

  fprintf( stderr, "# write moos file %s ...\n", filename );
  if ((iop = fopen( extended_filename(filename), "w")) == 0){
    fprintf(stderr, "# WARNING: can't write moos file %s\n", filename );
    return(-1);
  }

  stop = FALSE;
  for (i=0; i<rec->numentries && !stop; i++) {
    switch( rec->entry[i].type ) {
    case LASER_VALUES:
      starttime = double_time(rec->lsens[rec->entry[i].index].laser.time);
      stop = TRUE;
      break;
    case POSITION:
      starttime = double_time(rec->psens[rec->entry[i].index].time);
      stop = TRUE;
      break;
    default:
      break;
    }
  }

  fprintf( iop, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" );
  fprintf( iop, "%%%% LOG FILE:       %s\n", filename );
  if (starttime>0) {
    ticks = (long) starttime;
    actual_date = localtime( &ticks );
    fprintf( iop, "%%%% FILE WRITTEN:   %s%d.%s%d.%d %s%d:%s%d %s\n",
	     (actual_date->tm_mday<10)?"0":"",
	     actual_date->tm_mday,
	     (actual_date->tm_mon<10)?"0":"",
	     actual_date->tm_mon,
	     1900+actual_date->tm_year,
	     (actual_date->tm_hour<10)?"0":"",
	     actual_date->tm_hour,
	     (actual_date->tm_min<10)?"0":"",
	     actual_date->tm_min,
	     actual_date->tm_isdst?"(DST)":"" );
    fprintf( iop, "%%%% LOGSTART        %.8f\n", starttime );
  }
  fprintf( iop, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" );

  for (i=0; i<rec->numentries; i++) {
    switch( rec->entry[i].type ) {
    case LASER_VALUES:
      time = double_time( rec->lsens[rec->entry[i].index].laser.time );
      fprintf( iop, "%.3f \tLASER_RANGE \t\t%s \ttime=%.6f,range[%d]{",
	       time-starttime,
	       "iLMS",
	       time,
	       rec->lsens[rec->entry[i].index].laser.numvalues );
      for (k=0;k<rec->lsens[rec->entry[i].index].laser.numvalues;k++) {
	fprintf(iop, "  %.3f%s",
		rec->lsens[rec->entry[i].index].laser.val[k]/100.0,
		k<rec->lsens[rec->entry[i].index].laser.numvalues-1?",":" " );
      }
      fprintf(iop, "}\n" );
      break;
    case POSITION:
      time = double_time(rec->psens[rec->entry[i].index].time);
      fprintf( iop, "%.3f \tROBOT_POSITION \t\t%s \t"
	       "timestamp=%.6f,x=%.6f,y=%.6f,theta=%.6f\n",
	       time-starttime,
	       "iRobot",
	       time,
	       (float) (rec->psens[rec->entry[i].index].rpos.x/100.0),
	       (float) (rec->psens[rec->entry[i].index].rpos.y/100.0),
	       (float) (rad2deg(rec->psens[rec->entry[i].index].rpos.o)-90.0) );
      break;
    default:
      break;
    }
  }
  return(0);
}
Пример #11
0
int
write_carmen_file( char *filename, logtools_log_data_t *rec )
{
  double    time, starttime = 0.0;
  int       i, k, stop;
  FILE    * iop;

  fprintf( stderr, "# write carmen file %s ...\n", filename );
  if ((iop = fopen( filename, "w")) == 0){
    fprintf(stderr, "# WARNING: can't write carmen file %s\n", filename );
    return(-1);
  }

  stop = FALSE;
  for (i=0; i<rec->numentries && !stop; i++) {
    switch( rec->entry[i].type ) {
    case LASER_VALUES:
      starttime = double_time(rec->lsens[rec->entry[i].index].laser.time);
      stop = TRUE;
      break;
    case POSITION:
      starttime = double_time(rec->psens[rec->entry[i].index].time);
      stop = TRUE;
      break;
    default:
      break;
    }
  }

  fprintf( iop, "# message_name [message contents] ipc_timestamp ipc_hostname logger_timestamp\n" );
  fprintf( iop, "# message formats defined: PARAM SYNC ODOM FLASER RLASER TRUEPOS \n" );
  fprintf( iop, "# PARAM param_name param_value\n" );
  fprintf( iop, "# SYNC tagname\n" );
  fprintf( iop, "# ODOM x y theta tv rv accel\n" );
  fprintf( iop, "# FLASER num_readings [range_readings] x y theta odom_x odom_y odom_theta\n" );
  fprintf( iop, "# RLASER num_readings [range_readings] x y theta odom_x odom_y odom_theta\n" );
  fprintf( iop, "# TRUEPOS true_x true_y true_theta odom_x odom_y odom_theta\n");
  fprintf( iop, "# NMEA-GGA utc latitude lat_orient longitude long_orient gps_quality num_sattelites hdop sea_level alitude geo_sea_level geo_sep data_age\n");

  for (i=0; i<rec->numentries; i++) {
    switch( rec->entry[i].type ) {
    case LASER_VALUES:
      time = double_time( rec->lsens[rec->entry[i].index].laser.time);
      switch( rec->lsens[rec->entry[i].index].id ) {
      case 0:
	fprintf( iop, "FLASER" );
	break;
      case 1:
	fprintf( iop, "RLASER" );
	break;
      case 2:
	fprintf( iop, "LASER2" );
	break;
      case 3:
	fprintf( iop, "LASER3" );
	break;
      default:
	fprintf( iop, "FLASER" );
	break;
      }
      fprintf( iop, " %d", rec->lsens[rec->entry[i].index].laser.numvalues );
      for (k=0;k<rec->lsens[rec->entry[i].index].laser.numvalues;k++) {
	fprintf(iop, " %.3f", rec->lsens[rec->entry[i].index].laser.val[k]/100.0 );
      }
      fprintf( iop, " %f %f %f %f %f %f %f %s %f\n",
	       (float) (rec->lsens[rec->entry[i].index].estpos.x/100.0),
	       (float) (rec->lsens[rec->entry[i].index].estpos.y/100.0),
	       (float) (carmen_normalize_theta(rec->lsens[rec->entry[i].index].estpos.o)),
	       (float) (rec->lsens[rec->entry[i].index].estpos.x/100.0),
	       (float) (rec->lsens[rec->entry[i].index].estpos.y/100.0),
	       (float) (carmen_normalize_theta(rec->lsens[rec->entry[i].index].estpos.o)),
	       time, "nohost", time-starttime );

      break;
    case POSITION:
      time = double_time(rec->psens[rec->entry[i].index].time);
      fprintf( iop, "ODOM %f %f %f %f %f %f %f %s %f\n",
	       (float) (rec->psens[rec->entry[i].index].rpos.x/100.0),
	       (float) (rec->psens[rec->entry[i].index].rpos.y/100.0),
	       (float) (carmen_normalize_theta(rec->psens[rec->entry[i].index].rpos.o)),
	       (float) (rec->psens[rec->entry[i].index].rvel.tv/100.0),
	       (float) (rec->psens[rec->entry[i].index].rvel.rv/100.0),
	       0.0, /* acceleration */
	       time, "nohost", time-starttime );
      break;
    default:
      break;
    }
  }
  return(0);
}
Пример #12
0
ENTRYPOINT void 
init_sonar (ModeInfo *mi)
{
  sonar_configuration *sp;
  int wire = MI_IS_WIREFRAME(mi);

  if (!sps) {
    sps = (sonar_configuration *)
      calloc (MI_NUM_SCREENS(mi), sizeof (sonar_configuration));
    if (!sps) {
      fprintf(stderr, "%s: out of memory\n", progname);
      exit(1);
    }
  }
  sp = &sps[MI_SCREEN(mi)];
  sp->glx_context = init_GL(mi);

  reshape_sonar (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  clear_gl_error(); /* WTF? sometimes "invalid op" from glViewport! */

  if (!wire)
    {
      GLfloat pos[4] = {0.05, 0.07, 1.00, 0.0};
      GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0};
      GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
      GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};

      glEnable(GL_TEXTURE_2D);
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_CULL_FACE);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_NORMALIZE);
      glEnable(GL_LINE_SMOOTH);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
      glShadeModel(GL_SMOOTH);

      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glLightfv(GL_LIGHT0, GL_AMBIENT,  amb);
      glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
      glLightfv(GL_LIGHT0, GL_SPECULAR, spc);
    }

  sp->trackball = gltrackball_init ();
  sp->rot = make_rotator (0, 0, 0, 0, speed * 0.003, True);

  sp->texfont = load_texture_font (MI_DISPLAY(mi), "font");
  check_gl_error ("loading font");

  sp->table_list = glGenLists (1);
  glNewList (sp->table_list, GL_COMPILE);
  sp->table_polys = draw_table (mi);
  glEndList ();

  sp->screen_list = glGenLists (1);
  glNewList (sp->screen_list, GL_COMPILE);
  sp->screen_polys = draw_screen (mi, False, False);
  glEndList ();

  sp->grid_list = glGenLists (1);
  glNewList (sp->grid_list, GL_COMPILE);
  sp->grid_polys = draw_screen (mi, True,  False);
  glEndList ();

  sp->sweep_list = glGenLists (1);
  glNewList (sp->sweep_list, GL_COMPILE);
  sp->sweep_polys = draw_screen (mi, False, True);
  glEndList ();

  sp->start_time = double_time ();
  sp->sweep_offset = random() % 60;
  sp->sweep_th = -1;
}
Пример #13
0
static void
sweep (sonar_configuration *sp)
{
  sonar_bogie *b;

  /* Move the sweep forward (clockwise).
   */
  GLfloat prev_sweep, this_sweep, tick;
  GLfloat cycle_secs = 30 / speed;  /* default to one cycle every N seconds */
  this_sweep = ((cycle_secs - fmod (double_time() - sp->start_time +
                                    sp->sweep_offset,
                                    cycle_secs))
                / cycle_secs
                * M_PI * 2);
  prev_sweep = sp->sweep_th;
  tick = prev_sweep - this_sweep;
  while (tick < 0) tick += M_PI*2;

  sp->sweep_th = this_sweep;

  if (this_sweep < 0 || this_sweep >= M_PI*2) abort();
  if (prev_sweep < 0)  /* skip first time */
    return;

  if (tick < 0 || tick >= M_PI*2) abort();


  /* Go through the 'pending' sensor data, find those bogies who are
     just now being swept, and move them from 'pending' to 'displayed'.
     (Leave bogies that have not yet been swept alone: we'll get to
     them when the sweep moves forward.)
   */
  b = sp->pending;
  while (b)
    {
      sonar_bogie *next = b->next;
      if (point_in_wedge (b->th, this_sweep, prev_sweep))
        {
          if (debug_p > 1) {
            time_t t = time((time_t *) 0);
            fprintf (stderr,
                     "%s: sweep hit: %02d:%02d: %s: (%5.2f %5.2f %5.2f;"
                     " th=[%.2f < %.2f <= %.2f])\n", 
                     progname,
                     (int) (t / 60) % 60, (int) t % 60,
                     b->name, b->r, b->th, b->ttl,
                     this_sweep, b->th, prev_sweep);
          }
          b->ttl = M_PI * 2.1;
          copy_and_insert_bogie (sp->ssd, b, &sp->displayed);
          delete_bogie (sp->ssd, b, &sp->pending);
        }
      b = next;
    }


  /* Update TTL on all currently-displayed bogies; delete the dead.

     Request sensor updates on the ones just now being swept.

     Any updates go into 'pending' and might not show up until
     the next time the sweep comes around.  This is to prevent
     already-drawn bogies from jumping to a new position without
     having faded out first.
  */
  b = sp->displayed;
  while (b)
    {
      sonar_bogie *next = b->next;
      b->ttl -= tick;

      if (b->ttl <= 0)
        {
          if (debug_p > 1)
            fprintf (stderr, "%s: TTL expired: %s (%5.2f %5.2f %5.2f)\n",
                     progname, b->name, b->r, b->th, b->ttl);
          delete_bogie (sp->ssd, b, &sp->displayed);
        }
      b = next;
    }

  update_sensor_data (sp);
}
Пример #14
0
void
screenhack_record_anim (record_anim_state *st)
{
  int bytes_per_line = st->xgwa.width * 3;
  double start_time = double_time();

# ifndef USE_GL

  Display *dpy = DisplayOfScreen (st->screen);
  char *data = (char *) st->img->data;

  /* Under XQuartz we can't just do XGetImage on the Window, we have to
     go through an intermediate Pixmap first.  I don't understand why.
     Also, the f*****g resize handle shows up as black.  God dammit.
     A workaround for that is to temporarily remove /opt/X11/bin/quartz-wm
   */
  XCopyArea (dpy, st->window, st->p, st->gc, 0, 0,
             st->xgwa.width, st->xgwa.height, 0, 0);
  XGetSubImage (dpy, st->p, 0, 0, st->xgwa.width, st->xgwa.height,
                ~0L, ZPixmap, st->img, 0, 0);

  /* Convert BGRA to RGB */
  {
    const char *in = st->img->data;
    char *out = st->img->data;
    int x, y;
    int w = st->img->width;
    int h = st->img->height;
    for (y = 0; y < h; y++)
      {
        const char *in2 = in;
        for (x = 0; x < w; x++)
          {
            *out++ = in2[2];
            *out++ = in2[1];
            *out++ = in2[0];
            in2 += 4;
          }
        in += st->img->bytes_per_line;
      }
  }
# else  /* USE_GL */

  char *data = st->data2;
  int y;

# ifdef HAVE_JWZGLES
#  undef glReadPixels /* Kludge -- unimplemented in the GLES compat layer */
# endif

  /* First OpenGL frame tends to be random data like a shot of my desktop,
     since it is the front buffer when we were drawing in the back buffer.
     Leave it black. */
  /* glDrawBuffer (GL_BACK); */
  if (st->frame_count != 0)
    glReadPixels (0, 0, st->xgwa.width, st->xgwa.height,
                  GL_RGB, GL_UNSIGNED_BYTE, st->data);

  /* Flip vertically */
  for (y = 0; y < st->xgwa.height; y++)
    memcpy (data      + bytes_per_line * y,
            st->data  + bytes_per_line * (st->xgwa.height - y - 1),
            bytes_per_line);

# endif /* USE_GL */


  if (st->frame_count < st->fade_frames)
    fade_frame (st, (unsigned char *) data,
                (double) st->frame_count / st->fade_frames);
  else if (st->frame_count >= st->target_frames - st->fade_frames)
    fade_frame (st, (unsigned char *) data,
                (double) (st->target_frames - st->frame_count - 1) /
                st->fade_frames);

# ifdef HAVE_GDK_PIXBUF
  {
    const char *type = "png";
    char fn[1024];
    GError *error = 0;
    GdkPixbuf *pixbuf;

    pixbuf = gdk_pixbuf_new_from_data ((guchar *) data,
                                       GDK_COLORSPACE_RGB, False, /* alpha */
                                       8, /* bits per sample */
                                       st->xgwa.width, st->xgwa.height,
                                       bytes_per_line,
                                       0, 0);

    sprintf (fn, "%s-%06d.%s", progname, st->frame_count, type);
    gdk_pixbuf_save (pixbuf, fn, type, &error, NULL);

    if (error)
      {
        fprintf (stderr, "%s: %s: %s\n", progname, fn, error->message);
        exit (1);
      }

    g_object_unref (pixbuf);
  }
# else  /* !HAVE_GDK_PIXBUF */
#  error GDK_PIXBUF is required
# endif /* !HAVE_GDK_PIXBUF */

# ifndef HAVE_JWXYZ
  {  /* Put percent done in window title */
    int pct = 100 * (st->frame_count + 1) / st->target_frames;
    if (pct != st->pct && st->title)
      {
        double end   = st->target_frames / (double) st->fps;
        double secs0 = double_time() - st->start_time;
        double secs  = double_timewarp() - st->start_time;
        double rate  = secs / secs0;
        double secs2 = (end - secs) / rate;
        Display *dpy = DisplayOfScreen (st->screen);
        char *t2 = (char *) malloc (strlen(st->title) + 100);
        if (secs2 < 0) secs2 = 0;

        sprintf (t2, "%s: %3d%% done,"
                 " %d:%02d:%02d in"
                 " %d:%02d:%02d;"
                 " %d%% speed,"
                 " %d:%02d:%02d remaining",
                 st->title, pct,

                 ((int) secs) / (60*60),
                 (((int) secs) / 60) % 60,
                 ((int) secs) % 60,

                 ((int) secs0) / (60*60),
                 (((int) secs0) / 60) % 60,
                 ((int) secs0) % 60,

                 (int) (100 * rate),

                 ((int) secs2) / (60*60),
                 (((int) secs2) / 60) % 60,
                 ((int) secs2) % 60
                 );
        XStoreName (dpy, st->window, t2);
        XSync (dpy, 0);
        free (t2);
        st->pct = pct;
      }
  }
# endif /* !HAVE_JWXYZ */

  if (++st->frame_count >= st->target_frames)
    screenhack_record_anim_free (st);

  recanim_time_warp += double_time() - start_time;
}
Пример #15
0
record_anim_state *
screenhack_record_anim_init (Screen *screen, Window window, int target_frames)
{
  Display *dpy = DisplayOfScreen (screen);
  record_anim_state *st;

# ifndef USE_GL
  XGCValues gcv;
# endif /* !USE_GL */

  if (target_frames <= 0) return 0;

  st = (record_anim_state *) calloc (1, sizeof(*st));

  st->fps = 30;
  st->screen = screen;
  st->window = window;
  st->target_frames = target_frames;
  st->start_time = double_time();
  st->frame_count = 0;
  st->fade_frames = st->fps * 1.5;

  if (st->fade_frames >= (st->target_frames / 2) - st->fps)
    st->fade_frames = 0;

# ifdef HAVE_GDK_PIXBUF
  {
    Window root;
    int x, y;
    unsigned int w, h, d, bw;
    XGetGeometry (dpy, window, &root, &x, &y, &w, &h, &bw, &d);
    gdk_pixbuf_xlib_init_with_depth (dpy, screen_number (screen), d);

#  ifdef HAVE_GTK2
#   if !GLIB_CHECK_VERSION(2, 36 ,0)
    g_type_init();
#   endif
#  else  /* !HAVE_GTK2 */
    xlib_rgb_init (dpy, screen);
#  endif /* !HAVE_GTK2 */
  }
# else  /* !HAVE_GDK_PIXBUF */
#  error GDK_PIXBUF is required
# endif /* !HAVE_GDK_PIXBUF */

  XGetWindowAttributes (dpy, st->window, &st->xgwa);

# ifdef USE_GL

  st->data  = (char *) calloc (st->xgwa.width, st->xgwa.height * 3);
  st->data2 = (char *) calloc (st->xgwa.width, st->xgwa.height * 3);

# else    /* !USE_GL */

  st->gc = XCreateGC (dpy, st->window, 0, &gcv);
  st->p = XCreatePixmap (dpy, st->window,
                         st->xgwa.width, st->xgwa.height, st->xgwa.depth);
  st->img = XCreateImage (dpy, st->xgwa.visual, st->xgwa.depth, ZPixmap,
                          0, 0, st->xgwa.width, st->xgwa.height, 8, 0);
  st->img->data = (char *) calloc (st->img->height, st->img->bytes_per_line);
# endif /* !USE_GL */


# ifndef HAVE_JWXYZ
  XFetchName (dpy, st->window, &st->title);
  {
    char *s = strchr(st->title, ':');
    if (s) *s = 0;
  }
# endif /* !HAVE_JWXYZ */

  return st;
}