X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fboing.c;h=55a05f3d4c67a98c94bdc50b832e9e62a5bdcb46;hb=39809ded547bdbb08207d3e514950425215b4410;hp=979907210a19beacc86b0ad42d38e4c578ba1326;hpb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;p=xscreensaver diff --git a/hacks/glx/boing.c b/hacks/glx/boing.c index 97990721..55a05f3d 100644 --- a/hacks/glx/boing.c +++ b/hacks/glx/boing.c @@ -1,4 +1,4 @@ -/* boing, Copyright (c) 2005-2008 Jamie Zawinski +/* boing, Copyright (c) 2005-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -25,7 +25,7 @@ "*showFPS: False \n" \ "*wireframe: False \n" \ -# define refresh_boing 0 +# define free_boing 0 # define release_boing 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -62,6 +62,8 @@ typedef struct { trackball_state *trackball; Bool button_down_p; + GLfloat speed; + GLuint ball_list; double ball_x, ball_y, ball_z, ball_th; double ball_dx, ball_dy, ball_dz, ball_dth; @@ -429,10 +431,10 @@ tick_physics (ModeInfo *mi) bp->ball_x += bp->ball_dx; if (bp->ball_x < min) bp->ball_x = min, bp->ball_dx = -bp->ball_dx, bp->ball_dth = -bp->ball_dth, - bp->ball_dx += (frand(speed/2) - speed); + bp->ball_dx += (frand(bp->speed/2) - bp->speed); else if (bp->ball_x > max) bp->ball_x = max, bp->ball_dx = -bp->ball_dx, bp->ball_dth = -bp->ball_dth, - bp->ball_dx += (frand(speed/2) - speed); + bp->ball_dx += (frand(bp->speed/2) - bp->speed); bp->ball_dy += bp->ball_ddy; bp->ball_y += bp->ball_dy; @@ -453,14 +455,28 @@ ENTRYPOINT void reshape_boing (ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; + int y = 0; h *= 4.0 / 3.0; /* Back in the caveman days we couldn't even afford square pixels! */ - glViewport (0, 0, (GLint) width, (GLint) height); + if (width > height * 5) { /* tiny window: show middle */ + height = width * 3/4; + y = -height/2; + h = height / (GLfloat) width; + } + + glViewport (0, y, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); + + if (height > width) + { + GLfloat s = width / (GLfloat) height; + glScalef (s, s, s); + } + gluPerspective (8.0, 1/h, 1.0, 10.0); glMatrixMode(GL_MODELVIEW); @@ -478,39 +494,10 @@ boing_handle_event (ModeInfo *mi, XEvent *event) { boing_configuration *bp = &bps[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) - { - bp->button_down_p = True; - gltrackball_start (bp->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) - { - bp->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 (bp->trackball, event->xbutton.button, 10, - !!event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - bp->button_down_p) - { - gltrackball_track (bp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } + if (gltrackball_event_handler (event, bp->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &bp->button_down_p)) + return True; return False; } @@ -522,14 +509,7 @@ init_boing (ModeInfo *mi) boing_configuration *bp; int wire = MI_IS_WIREFRAME(mi); - if (!bps) { - bps = (boing_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (boing_configuration)); - if (!bps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - } + MI_INIT (mi, bps); bp = &bps[MI_SCREEN(mi)]; @@ -590,18 +570,18 @@ init_boing (ModeInfo *mi) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - speed = speed / 800.0; + bp->speed = speed / 800.0; - bp->ball_dth = (spin ? -speed * 7 * 360 : 0); + bp->ball_dth = (spin ? -bp->speed * 7 * 360 : 0); bp->ball_x = 0.5 - ((ball_size/2) + frand(1-ball_size)); bp->ball_y = 0.2; - bp->ball_dx = speed * 6 + frand(speed); - bp->ball_ddy = -speed; + bp->ball_dx = bp->speed * 6 + frand(bp->speed); + bp->ball_ddy = -bp->speed; - bp->ball_dz = speed * 6 + frand(speed); + bp->ball_dz = bp->speed * 6 + frand(bp->speed); - bp->trackball = gltrackball_init (); + bp->trackball = gltrackball_init (False); } @@ -629,8 +609,21 @@ draw_boing (ModeInfo *mi) tick_physics (mi); glPushMatrix (); + + { + double rot = current_device_rotation(); + glRotatef(rot, 0, 0, 1); +/* + if ((rot > 45 && rot < 135) || + (rot < -45 && rot > -135)) + { + GLfloat s = MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi); + glScalef (1/s, s, 1); + } +*/ + } + gltrackball_rotate (bp->trackball); - glRotatef(current_device_rotation(), 0, 0, 1); glLightfv (GL_LIGHT0, GL_POSITION, bp->lightpos);