ENTRYPOINT Bool
stairs_handle_event (ModeInfo *mi, XEvent *event)
{
  stairsstruct *sp = &stairs[MI_SCREEN(mi)];

  if (event->xany.type == ButtonPress &&
      event->xbutton.button == Button1)
    {
      sp->button_down_p = True;
      gltrackball_start (sp->trackball,
                         event->xbutton.x, event->xbutton.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == ButtonRelease &&
           event->xbutton.button == Button1)
    {
      sp->button_down_p = False;
      return True;
    }
  else if (event->xany.type == ButtonPress &&
           (event->xbutton.button == Button4 ||
            event->xbutton.button == Button5 ||
            event->xbutton.button == Button6 ||
            event->xbutton.button == Button7))
    {
      gltrackball_mousewheel (sp->trackball, event->xbutton.button, 10,
                              !!event->xbutton.state);
      return True;
    }
  else if (event->xany.type == MotionNotify &&
           sp->button_down_p)
    {
      gltrackball_track (sp->trackball,
                         event->xmotion.x, event->xmotion.y,
                         MI_WIDTH (mi), MI_HEIGHT (mi));
      return True;
    }
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ')
        {
          gltrackball_reset (sp->trackball);
          return True;
        }
    }

  return False;
}
Beispiel #2
0
ENTRYPOINT void 
init_hexstrut (ModeInfo *mi)
{
  hexstrut_configuration *bp;

  MI_INIT (mi, bps, free_hexstrut);

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_hexstrut (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  {
    double spin_speed   = 0.002;
    double wander_speed = 0.003;
    double spin_accel   = 1.0;

    bp->rot = make_rotator (do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            do_spin ? spin_speed : 0,
                            spin_accel,
                            do_wander ? wander_speed : 0,
                            False);
    bp->trackball = gltrackball_init (True);
  }


  /* Let's tilt the scene a little. */
  gltrackball_reset (bp->trackball,
                     -0.4 + frand(0.8),
                     -0.4 + frand(0.8));

  if (thickness < 0.05) thickness = 0.05;
  if (thickness < 0.05) MI_IS_WIREFRAME(mi) = True;
  if (thickness > 1.7) thickness = 1.7;
  if (speed > 2) speed = 2;

  bp->ncolors = 64;
  bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
  make_smooth_colormap (0, 0, 0,
                        bp->colors, &bp->ncolors,
                        False, 0, False);

  make_plane (mi);
}
Beispiel #3
0
ENTRYPOINT Bool
cube_handle_event (ModeInfo *mi, XEvent *event)
{
  cube_configuration *cc = &ccs[MI_SCREEN(mi)];

  /* Neutralize any vertical motion */
  GLfloat rot = current_device_rotation();
  Bool rotp = ((rot >  45 && rot <  135) ||
               (rot < -45 && rot > -135));
               
  if (event->xany.type == ButtonPress ||
      event->xany.type == ButtonRelease)
    {
      if (rotp)
        event->xbutton.x = MI_WIDTH(mi) / 2;
      else
        event->xbutton.y = MI_HEIGHT(mi) / 2;
    }
  else if (event->xany.type == MotionNotify)
    {
      if (rotp)
        event->xmotion.x = MI_WIDTH(mi) / 2;
      else
        event->xmotion.y = MI_HEIGHT(mi) / 2;
    }

  if (gltrackball_event_handler (event, cc->trackball,
                                 MI_WIDTH (mi), MI_HEIGHT (mi),
                                 &cc->button_down_p))
    return True;
  else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
    {
      reset_colors (mi);
      tweak_cubes (mi);
      gltrackball_reset (cc->trackball, 0, 0);
      return True;
    }

  return False;
}
Beispiel #4
0
ENTRYPOINT Bool
stairs_handle_event (ModeInfo *mi, XEvent *event)
{
  stairsstruct *sp = &stairs[MI_SCREEN(mi)];

  if (gltrackball_event_handler (event, sp->trackball,
                                 MI_WIDTH (mi), MI_HEIGHT (mi),
                                 &sp->button_down_p))
    return True;
  else if (event->xany.type == KeyPress)
    {
      KeySym keysym;
      char c = 0;
      XLookupString (&event->xkey, &c, 1, &keysym, 0);
      if (c == ' ' || c == '\t')
        {
          gltrackball_reset (sp->trackball);
          return True;
        }
    }

  return False;
}
Beispiel #5
0
ENTRYPOINT Bool
tentacles_handle_event (ModeInfo *mi, XEvent *event)
{
    tentacles_configuration *tc = &tcs[MI_SCREEN(mi)];

    if (gltrackball_event_handler (event, tc->trackball,
                                   MI_WIDTH (mi), MI_HEIGHT (mi),
                                   &tc->button_down_p))
        return True;
    else if (event->xany.type == KeyPress)
    {
        KeySym keysym;
        char c = 0;
        XLookupString (&event->xkey, &c, 1, &keysym, 0);
        if (c == ' ')
        {
            gltrackball_reset (tc->trackball);
            return True;
        }
    }

    return False;
}
Beispiel #6
0
ENTRYPOINT void 
init_camera (ModeInfo *mi)
{
  camera_configuration *bp;
  int wire = MI_IS_WIREFRAME(mi);
  int i;
  MI_INIT (mi, bps, 0);

  bp = &bps[MI_SCREEN(mi)];

  bp->glx_context = init_GL(mi);

  reshape_camera (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

  glShadeModel(GL_SMOOTH);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_CULL_FACE);

  if (!wire)
    {
      GLfloat pos[4] = {0.4, 0.2, 0.4, 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] = {1.0, 1.0, 1.0, 1.0};

      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);

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

  bp->user_trackball = gltrackball_init (False);

  bp->dlists = (GLuint *) calloc (countof(all_objs)+1, sizeof(GLuint));
  for (i = 0; i < countof(all_objs); i++)
    bp->dlists[i] = glGenLists (1);

  for (i = 0; i < countof(all_objs); i++)
    {
      const struct gllist *gll = *all_objs[i];
      char *key = 0;
      GLfloat spec1[4] = {1.00, 1.00, 1.00, 1.0};
      GLfloat spec2[4] = {0.40, 0.40, 0.70, 1.0};
      GLfloat *spec = spec1;
      GLfloat shiny = 20;

      glNewList (bp->dlists[i], GL_COMPILE);

      glMatrixMode(GL_MODELVIEW);
      glPushMatrix();
      glMatrixMode(GL_TEXTURE);
      glPushMatrix();
      glMatrixMode(GL_MODELVIEW);

      glRotatef (-90, 1, 0, 0);
      glRotatef (180, 0, 0, 1);
      glScalef (6, 6, 6);

      glBindTexture (GL_TEXTURE_2D, 0);

      switch (i) {
      case CAMERA_BODY:  key = "bodyColor";   break;
      case CAMERA_CAP:   key = "capColor";    break;
      case CAMERA_HINGE: key = "hingeColor";  break;
      case CAMERA_MOUNT: key = "mountColor";  break;
      case CAMERA_LENS:  key = "lensColor";   spec = spec2; break;
      case GROUND:       key = "groundColor"; spec = spec2; shiny = 128; break;
      default: abort(); break;
      }

      parse_color (mi, key, bp->component_colors[i]);

      glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  spec);
      glMaterialf  (GL_FRONT_AND_BACK, GL_SHININESS, shiny);

      switch (i) {
      case GROUND:
        if (! ground)
          ground = (struct gllist *) calloc (1, sizeof(*ground));
        ground->points = draw_ground (mi, bp->component_colors[i]);
        break;
      default:
        renderList (gll, wire);
        /* glColor3f (1, 1, 1); renderListNormals (gll, 100, True); */
        /* glColor3f (1, 1, 0); renderListNormals (gll, 100, False); */
        break;
      }

      glMatrixMode(GL_TEXTURE);
      glPopMatrix();
      glMatrixMode(GL_MODELVIEW);
      glPopMatrix();

      glEndList ();
    }

  bp->ncameras = MI_COUNT(mi);
  if (bp->ncameras <= 0) bp->ncameras = 1;
  bp->cameras = (camera *) calloc (bp->ncameras, sizeof (camera));

  {
    GLfloat range = (MI_COUNT(mi) <= 2) ? 4 : 5.5;
    GLfloat extent;
    GLfloat spacing = range / bp->ncameras;
    if (spacing < 0.7) spacing = 0.7;
    extent = spacing * (bp->ncameras - 1);
    for (i = 0; i < bp->ncameras; i++)
      {
        camera *c = &bp->cameras[i];
        c->state = IDLE;
        c->pos.x = i*spacing - extent/2;
        c->pos.z += 0.7;
        if (spacing < 1.6)
          c->pos.z = (i & 1 ? 1.1 : -0.3);
        c->focus.x = c->pos.x;
        c->focus.y = c->pos.y + 1;
        c->focus.z = c->pos.z + BEAM_ZOFF;
        c->pitch   = -50;
      }
  }


# ifdef DEBUG
  if (!debug_p)
# endif
    /* Let's tilt the floor a little. */
    gltrackball_reset (bp->user_trackball,
                       -0.70 + frand(1.58),
                       -0.30 + frand(0.40));
}