X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fqueens.c;h=cd3867cf9af87498d8367146ff71aeb490aafef3;hp=b0df56686e401e34f816f0d09e77511b27152c81;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hpb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe diff --git a/hacks/glx/queens.c b/hacks/glx/queens.c index b0df5668..cd3867cf 100644 --- a/hacks/glx/queens.c +++ b/hacks/glx/queens.c @@ -29,7 +29,7 @@ # include "xlock.h" #endif -#ifdef HAVE_COCOA +#ifdef HAVE_JWXYZ # include "jwxyz.h" #else # include @@ -67,7 +67,7 @@ ENTRYPOINT ModeSpecOpt queens_opts = {countof(opts), opts, countof(vars), vars, #ifdef USE_MODULES ModStruct queens_description = -{"queens", "init_queens", "draw_queens", "release_queens", +{"queens", "init_queens", "draw_queens", NULL, "draw_queens", "init_queens", NULL, &queens_opts, 1000, 1, 2, 1, 4, 1.0, "", "Queens", 0, NULL}; @@ -111,37 +111,13 @@ queens_handle_event (ModeInfo *mi, XEvent *event) { Queenscreen *qs = &qss[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) + if (gltrackball_event_handler (event, qs->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &qs->button_down_p)) + return True; + else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) { - qs->button_down_p = True; - gltrackball_start (qs->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) - { - qs->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 (qs->trackball, event->xbutton.button, 5, - !event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - qs->button_down_p) - { - gltrackball_track (qs->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); + qs->steps = 1024 - 1; return True; } @@ -352,11 +328,93 @@ static int drawBoard(Queenscreen *qs) } glEnd(); + + { + GLfloat off = 0.01; + GLfloat w = qs->BOARDSIZE; + GLfloat h = 0.1; + + /* Give the board a slight lip. */ + /* #### oops, normals are wrong here, but you can't tell */ + + glColor3f(0.3, 0.3, 0.3); + glBegin (GL_QUADS); + glVertex3f (0, 0, 0); + glVertex3f (0, -h, 0); + glVertex3f (0, -h, w); + glVertex3f (0, 0, w); + + glVertex3f (0, 0, w); + glVertex3f (0, -h, w); + glVertex3f (w, -h, w); + glVertex3f (w, 0, w); + + glVertex3f (w, 0, w); + glVertex3f (w, -h, w); + glVertex3f (w, -h, 0); + glVertex3f (w, 0, 0); + + glVertex3f (w, 0, 0); + glVertex3f (w, -h, 0); + glVertex3f (0, -h, 0); + glVertex3f (0, 0, 0); + + glVertex3f (0, -h, 0); + glVertex3f (w, -h, 0); + glVertex3f (w, -h, w); + glVertex3f (0, -h, w); + glEnd(); + polys += 4; + + /* Fill in the underside of the board with an invisible black box + to hide the reflections that are not on tiles. Probably there's + a way to do this with stencils instead. + */ + w -= off*2; + h = 5; + + glPushMatrix(); + glTranslatef (off, 0, off); + glDisable(GL_LIGHTING); + glColor3f(0,0,0); + glBegin (GL_QUADS); + glVertex3f (0, 0, 0); + glVertex3f (0, -h, 0); + glVertex3f (0, -h, w); + glVertex3f (0, 0, w); + + glVertex3f (0, 0, w); + glVertex3f (0, -h, w); + glVertex3f (w, -h, w); + glVertex3f (w, 0, w); + + glVertex3f (w, 0, w); + glVertex3f (w, -h, w); + glVertex3f (w, -h, 0); + glVertex3f (w, 0, 0); + + glVertex3f (w, 0, 0); + glVertex3f (w, -h, 0); + glVertex3f (0, -h, 0); + glVertex3f (0, 0, 0); + + glVertex3f (0, -h, 0); + glVertex3f (w, -h, 0); + glVertex3f (w, -h, w); + glVertex3f (0, -h, w); + glEnd(); + polys += 4; + glPopMatrix(); + if (!wire) + glEnable(GL_LIGHTING); + } + return polys; } -static int display(Queenscreen *qs) +static int display(ModeInfo *mi, Queenscreen *qs) { + int max = 1024; int polys = 0; glClear(clearbits); @@ -366,6 +424,7 @@ static int display(Queenscreen *qs) glRotatef(current_device_rotation(), 0, 0, 1); /* setup light attenuation */ + /* #### apparently this does nothing */ glEnable(GL_COLOR_MATERIAL); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.8/(0.01+findAlpha(qs))); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.06); @@ -373,9 +432,7 @@ static int display(Queenscreen *qs) /** setup perspective */ glTranslatef(0.0, 0.0, -1.5*qs->BOARDSIZE); glRotatef(30.0, 1.0, 0.0, 0.0); - glRotatef(-current_device_rotation(), 0, 0, 1); gltrackball_rotate (qs->trackball); - glRotatef(current_device_rotation(), 0, 0, 1); glRotatef(qs->theta*100, 0.0, 1.0, 0.0); glTranslatef(-0.5*qs->BOARDSIZE, 0.0, -0.5*qs->BOARDSIZE); @@ -390,6 +447,18 @@ static int display(Queenscreen *qs) glEnable(GL_LIGHT0); } + /* Since the lighting attenuation trick up there doesn't seem to be working, + let's drop the old board down and drop the new board in. */ + if (qs->steps < (max/8.0)) { + GLfloat y = qs->steps / (max/8.0); + y = sin (M_PI/2 * y); + glTranslatef (0, 10 - (y * 10), 0); + } else if (qs->steps > max-(max/8.0)) { + GLfloat y = (qs->steps - (max-(max/8.0))) / (GLfloat) (max/8.0); + y = 1 - sin (M_PI/2 * (1-y)); + glTranslatef (0, -y * 15, 0); + } + /* draw reflections */ if(!wire) { polys += draw_reflections(qs); @@ -409,7 +478,7 @@ static int display(Queenscreen *qs) qs->theta += .002; /* zero out board, find new solution of size MINBOARD <= i <= MAXBOARD */ - if(++qs->steps == 1024) { + if(++qs->steps == max) { qs->steps = 0; blank(qs); qs->BOARDSIZE = MINBOARD + (random() % (MAXBOARD - MINBOARD + 1)); @@ -419,26 +488,6 @@ static int display(Queenscreen *qs) return polys; } -static const GLfloat spidermodel[][3] = - { - {0.48, 0.48, 0.22}, - {0.48, 0.34, 0.18}, - {0.34, 0.34, 0.10}, - {0.34, 0.18, 0.30}, - {0.18, 0.14, 0.38}, - {0.14, 0.29, 0.01}, - {0.29, 0.18, 0.18}, - {0.18, 0.18, 0.16}, - {0.18, 0.20, 0.26}, - {0.20, 0.27, 0.14}, - {0.27, 0.24, 0.08}, - {0.24, 0.17, 0.00}, - {0.17, 0.095, 0.08}, - {0.095, 0.07, 0.00}, - {0.07, 0.00, 0.12}, - }; - - #define EPSILON 0.001 #if 0 @@ -484,9 +533,11 @@ ENTRYPOINT void init_queens(ModeInfo *mi) int poly_counts[PIECES]; wire = MI_IS_WIREFRAME(mi); - if(!qss && - !(qss = (Queenscreen *) calloc(MI_NUM_SCREENS(mi), sizeof(Queenscreen)))) - return; +# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */ + wire = 0; +# endif + + MI_INIT (mi, qss, NULL); qs = &qss[screen]; qs->window = MI_WINDOW(mi); @@ -496,11 +547,11 @@ ENTRYPOINT void init_queens(ModeInfo *mi) else MI_CLEARWINDOW(mi); - qs->trackball = gltrackball_init (); + qs->trackball = gltrackball_init (False); qs->BOARDSIZE = 8; /* 8 cuz its classic */ - gen_model_lists(-1, poly_counts); + chessmodels_gen_lists(-1, poly_counts); qs->queen_list = QUEEN; qs->queen_polys = poly_counts[QUEEN]; @@ -538,7 +589,7 @@ ENTRYPOINT void draw_queens(ModeInfo *mi) else glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - mi->polygon_count = display(qs); + mi->polygon_count = display(mi, qs); mi->recursion_depth = qs->BOARDSIZE; if(mi->fps_p) do_fps(mi);