+ENTRYPOINT Bool
+lament_handle_event (ModeInfo *mi, XEvent *event)
+{
+ lament_configuration *lc = &lcs[MI_SCREEN(mi)];
+
+ if (event->xany.type == ButtonPress &&
+ event->xbutton.button == Button1)
+ {
+ lc->button_down_p = True;
+ gltrackball_start (lc->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)
+ {
+ lc->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 (lc->trackball, event->xbutton.button, 5,
+ !!event->xbutton.state);
+ return True;
+ }
+ else if (event->xany.type == MotionNotify &&
+ lc->button_down_p)
+ {
+ gltrackball_track (lc->trackball,
+ event->xmotion.x, event->xmotion.y,
+ MI_WIDTH (mi), MI_HEIGHT (mi));
+ return True;
+ }
+
+ return False;
+}
+
+
+static void
+check_facing(ModeInfo *mi)
+{
+ lament_configuration *lc = &lcs[MI_SCREEN(mi)];
+
+ GLdouble m[16], p[16], x, y, z;
+ GLint v[4];
+ glGetDoublev (GL_MODELVIEW_MATRIX, m);
+ glGetDoublev (GL_PROJECTION_MATRIX, p);
+ glGetIntegerv (GL_VIEWPORT, v);
+
+ /* See if a coordinate 5 units in front of the door is near the
+ center of the screen. */
+
+ gluProject (-5, 0, 0, m, p, v, &x, &y, &z);
+ x = (x / MI_WIDTH(mi)) - 0.5;
+ y = (y / MI_HEIGHT(mi)) - 0.5;
+ lc->facing_p = (z < 0.9 &&
+ x > -0.02 && x < 0.02 &&
+ y > -0.02 && y < 0.02);
+}
+
+
+
+static void
+scale_for_window(ModeInfo *mi)
+{
+ lament_configuration *lc = &lcs[MI_SCREEN(mi)];
+ int target_size = lc->texture->width * 1.4;
+ int win_size = (MI_WIDTH(mi) > MI_HEIGHT(mi) ? MI_HEIGHT(mi) : MI_WIDTH(mi));
+
+ /* This scale makes the box take up most of the window */
+ glScalef(8, 8, 8);
+
+ /* But if the window is more than a little larger than our target size,
+ scale the object back down, so that the bits drawn on the screen end
+ up rougly target_size across (actually it ends up a little larger.)
+ Note that the image-map bits we have are 128x128. Therefore, if the
+ image is magnified a lot, it looks pretty blocky. So it's better to
+ have a 128x128 animation on a 1280x1024 screen that looks good, than
+ a 1024x1024 animation that looks really pixelated.
+ */
+
+ {
+ int max = 340; /* Let's not go larger than life-sized. */
+ if (target_size > max)
+ target_size = max;
+ }
+
+ if (win_size > 640 &&
+ win_size > target_size * 1.5)
+ {
+ GLfloat ratio = ((GLfloat) target_size / (GLfloat) win_size);
+ ratio *= 2.0;
+ glScalef(ratio, ratio, ratio);
+ }
+}
+
+