Example #1
0
static void
pick_new_molecule (ModeInfo *mi, time_t last)
{
  molecule_configuration *mc = &mcs[MI_SCREEN(mi)];

  if (mc->nmolecules == 1)
    {
      if (last != 0) return;
      mc->which = 0;
    }
  else if (last == 0)
    {
      mc->which = random() % mc->nmolecules;
    }
  else
    {
      int n = mc->which;
      while (n == mc->which)
        n = random() % mc->nmolecules;
      mc->which = n;
    }
          
  if (verbose_p)
    {
      char *name = strdup (mc->molecules[mc->which].label);
      char *s = strpbrk (name, "\r\n");
      if (s) *s = 0;
      fprintf (stderr, "%s: drawing %s (%d)\n", progname, name, mc->which);
      free (name);
    }

  mc->polygon_count = 0;

  glNewList (mc->molecule_dlist, GL_COMPILE);
  ensure_bounding_box_visible (mi);

  do_labels = orig_do_labels;
  do_atoms  = orig_do_atoms;
  do_bonds  = orig_do_bonds;
  do_shells = orig_do_shells;
  MI_IS_WIREFRAME(mi) = orig_wire;

  if (mc->molecule_size > mc->no_label_threshold)
    do_labels = 0;
  if (mc->molecule_size > mc->wireframe_threshold)
    MI_IS_WIREFRAME(mi) = 1;

  if (MI_IS_WIREFRAME(mi))
    do_bonds = 1, do_shells = 0;

  if (!do_bonds)
    do_shells = 0;

  if (! (do_bonds || do_atoms || do_labels))
    {
      /* Make sure *something* shows up! */
      MI_IS_WIREFRAME(mi) = 1;
      do_bonds = 1;
    }

  build_molecule (mi, False);
  glEndList();

  if (do_shells)
    {
      glNewList (mc->shell_dlist, GL_COMPILE);
      ensure_bounding_box_visible (mi);

      do_labels = 0;
      do_atoms  = 1;
      do_bonds  = 0;

      build_molecule (mi, True);

      glEndList();
      do_bonds  = orig_do_bonds;
      do_atoms  = orig_do_atoms;
      do_labels = orig_do_labels;
    }
}
Example #2
0
void
draw_molecule (ModeInfo *mi)
{
/*  static time_t last = 0; */
  time_t now = time ((time_t *) 0);
  molecule_configuration *mc;
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);

  if (mcs == NULL)
	return;
  mc = &mcs[MI_SCREEN(mi)];
  if (!mc->glx_context)
    return;

  MI_IS_DRAWN(mi) = True;

  if (last + timeout <= now)   /* randomize molecules every -timeout seconds */
    {
      if (mc->nmolecules == 1)
        {
          if (last != 0) goto SKIP;
          mc->which = 0;
        }
      else if (last == 0)
        {
          mc->which = NRAND(mc->nmolecules);
        }
      else
        {
          int n = mc->which;
          while (n == mc->which)
            n = NRAND(mc->nmolecules);
          mc->which = n;
        }

      last = now;


      glNewList (mc->molecule_dlist, GL_COMPILE);
      ensure_bounding_box_visible (mi);
      if (MI_IS_ICONIC(mi))
        {do_labels = False;
	 do_bonds  = True;
         do_titles = False;
	}
      else
        {
      do_labels = orig_do_labels;
      do_bonds = orig_do_bonds;
      do_titles = orig_do_titles;
        }
      cur_wire = orig_wire;

      if (mc->molecule_size > mc->no_label_threshold)
        do_labels = 0;
      if (mc->molecule_size > mc->wireframe_threshold)
        cur_wire = 1;

      if (cur_wire)
        do_bonds = 1;

      build_molecule (mi);

      glEndList();
    }
 SKIP:

  glPushMatrix ();
  glScalef(1.1, 1.1, 1.1);

  {
    GLfloat x, y, z;

    if (do_wander)
      {
        static int frame = 0;

#       define SINOID(SCALE,SIZE) \
        ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)

        x = SINOID(0.031, 9.0);
        y = SINOID(0.023, 9.0);
        z = SINOID(0.017, 9.0);
        frame++;
        glTranslatef(x, y, z);
      }

    if (mc->spin_x || mc->spin_y || mc->spin_z)
      {
        x = mc->rotx;
        y = mc->roty;
        z = mc->rotz;
        if (x < 0) x = 1 - (x + 1);
        if (y < 0) y = 1 - (y + 1);
        if (z < 0) z = 1 - (z + 1);

        if (mc->spin_x) glRotatef(x * 360, 1.0, 0.0, 0.0);
        if (mc->spin_y) glRotatef(y * 360, 0.0, 1.0, 0.0);
        if (mc->spin_z) glRotatef(z * 360, 0.0, 0.0, 1.0);

        rotate(&mc->rotx, &mc->dx, &mc->ddx, mc->d_max, MI_IS_VERBOSE(mi));
        rotate(&mc->roty, &mc->dy, &mc->ddy, mc->d_max, MI_IS_VERBOSE(mi));
        rotate(&mc->rotz, &mc->dz, &mc->ddz, mc->d_max, MI_IS_VERBOSE(mi));
      }
  }

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glCallList (mc->molecule_dlist);
  glPopMatrix ();

  if (MI_IS_FPS(mi)) do_fps (mi);
  glFinish();

  glXSwapBuffers(dpy, window);
}