X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fantinspect.c;h=a1ffadd569e3ec760deb17f0b855af657039b65b;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=0d50467146e400b79a98d4e2ac5ea322bf7eb7f7;hpb=9c9d475ff889ed8be02e8ce8c17da28b93278fca;p=xscreensaver diff --git a/hacks/glx/antinspect.c b/hacks/glx/antinspect.c index 0d504671..a1ffadd5 100644 --- a/hacks/glx/antinspect.c +++ b/hacks/glx/antinspect.c @@ -15,26 +15,29 @@ * tennessy@cs.ubc.ca */ -#include - #ifdef STANDALONE -#define PROGCLASS "AntInspect" -#define HACK_INIT init_antinspect -#define HACK_DRAW draw_antinspect -#define HACK_RESHAPE reshape_antinspect -#define HACK_HANDLE_EVENT antinspect_handle_event -#define EVENT_MASK PointerMotionMask -#define antinspect_opts xlockmore_opts #define DEFAULTS "*delay: 20000 \n" \ - "*showFPS: False \n" \ - "*wireframe: False \n" + "*showFPS: False \n" +# define refresh_antinspect 0 #include "xlockmore.h" #else #include "xlock.h" #endif -#include +#ifdef HAVE_JWXYZ +# include "jwxyz.h" +#else +# include +# include +# include +#endif + +#ifdef HAVE_JWZGLES +# include "jwzgles.h" +#endif /* HAVE_JWZGLES */ + +#include "sphere.h" #include "gltrackball.h" #define DEF_SHADOWS "True" @@ -42,24 +45,19 @@ static int shadows; static XrmOptionDescRec opts[] = { - {(char *) "-shadows", - (char *) ".antinspect.shadows", XrmoptionNoArg, (caddr_t) "on"}, - - {(char *) "+shadows", - (char *) ".antinspect.shadows", XrmoptionNoArg, (caddr_t) "off"} + {"-shadows", ".antinspect.shadows", XrmoptionNoArg, "on"}, + {"+shadows", ".antinspect.shadows", XrmoptionNoArg, "off"} }; static argtype vars[] = { - {(caddr_t *) &shadows, - (char *) "shadows", (char *) "Shadows", (char *) DEF_SHADOWS, t_Bool} + {&shadows, "shadows", "Shadows", DEF_SHADOWS, t_Bool} }; static OptionStruct desc[] = { - {(char *) "-/+shadows", - (char *) "turn on/off ant shadows"} + {"-/+shadows", "turn on/off ant shadows"} }; -ModeSpecOpt antinspect_opts = {sizeof opts / sizeof opts[0], +ENTRYPOINT ModeSpecOpt antinspect_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, @@ -95,24 +93,27 @@ typedef struct { GLXContext *glx_context; trackball_state *trackball; Bool button_down_p; + int linewidth; + float ant_step; + } antinspectstruct; -static float front_shininess[] = {60.0}; -static float front_specular[] = {0.7, 0.7, 0.7, 1.0}; -static float ambient[] = {0.0, 0.0, 0.0, 1.0}; -static float diffuse[] = {1.0, 1.0, 1.0, 1.0}; +static const float front_shininess[] = {60.0}; +static const float front_specular[] = {0.7, 0.7, 0.7, 1.0}; +static const float ambient[] = {0.0, 0.0, 0.0, 1.0}; +static const float diffuse[] = {1.0, 1.0, 1.0, 1.0}; static float position0[] = {0.0, 3.0, 0.0, 1.0}; -static float position1[] = {-1.0, -3.0, 1.0, 0.0}; -static float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0}; -static float lmodel_twoside[] = {GL_TRUE}; - -static float MaterialRed[] = {0.6, 0.0, 0.0, 1.0}; -static float MaterialOrange[] = {1.0, 0.69, 0.00, 1.0}; -static float MaterialGray[] = {0.2, 0.2, 0.2, 1.0}; -static float MaterialBlack[] = {0.1, 0.1, 0.1, 0.4}; -static float MaterialShadow[] = {0.3, 0.3, 0.3, 0.3}; -static float MaterialGray5[] = {0.5, 0.5, 0.5, 0.3}; -static float MaterialGray6[] = {0.6, 0.6, 0.6, 1.0}; +static const float position1[] = {-1.0, -3.0, 1.0, 0.0}; +static const float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0}; +static const float lmodel_twoside[] = {GL_TRUE}; + +static const float MaterialRed[] = {0.6, 0.0, 0.0, 1.0}; +static const float MaterialOrange[] = {1.0, 0.69, 0.00, 1.0}; +static const float MaterialGray[] = {0.2, 0.2, 0.2, 1.0}; +static const float MaterialBlack[] = {0.1, 0.1, 0.1, 0.4}; +static const float MaterialShadow[] = {0.3, 0.3, 0.3, 0.3}; +static const float MaterialGray5[] = {0.5, 0.5, 0.5, 0.3}; +static const float MaterialGray6[] = {0.6, 0.6, 0.6, 1.0}; static antinspectstruct *antinspect = (antinspectstruct *) NULL; @@ -122,9 +123,10 @@ enum {X, Y, Z, W}; enum {A, B, C, D}; /* create a matrix that will project the desired shadow */ -void shadowmatrix(GLfloat shadowMat[4][4], - GLfloat groundplane[4], - GLfloat lightpos[4]) { +static void shadowmatrix(GLfloat shadowMat[4][4], + const GLfloat groundplane[4], + const GLfloat lightpos[4]) +{ GLfloat dot; /* find dot product between light position vector and ground plane normal */ @@ -154,10 +156,12 @@ void shadowmatrix(GLfloat shadowMat[4][4], shadowMat[3][3] = dot - lightpos[W] * groundplane[W]; } -GLfloat ground[4] = {0.0, 1.0, 0.0, -0.00001}; +static const GLfloat ground[4] = {0.0, 1.0, 0.0, -0.00001}; /* simple filled sphere */ -static Bool mySphere(float radius) { +static Bool mySphere(float radius) +{ +#if 0 GLUquadricObj *quadObj; if((quadObj = gluNewQuadric()) == 0) @@ -165,12 +169,20 @@ static Bool mySphere(float radius) { gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL); gluSphere(quadObj, radius, 16, 16); gluDeleteQuadric(quadObj); - +#else + glPushMatrix(); + glScalef (radius, radius, radius); + glRotatef (90, 1, 0, 0); + unit_sphere (16, 16, False); + glPopMatrix(); +#endif return True; } /* caged sphere */ -static Bool mySphere2(float radius) { +static Bool mySphere2(float radius) +{ +#if 0 GLUquadricObj *quadObj; if((quadObj = gluNewQuadric()) == 0) @@ -178,27 +190,34 @@ static Bool mySphere2(float radius) { gluQuadricDrawStyle(quadObj, (GLenum) GLU_LINE);/*GLU_SILHOUETTE);*/ gluSphere(quadObj, radius, 16, 8); gluDeleteQuadric(quadObj); +#else + glPushMatrix(); + glScalef (radius, radius, radius); + glRotatef (90, 1, 0, 0); + unit_sphere (16, 8, True); + glPopMatrix(); +#endif return True; } /* null cone */ -static Bool myCone2(float radius) { +static Bool myCone2(float radius) +{ return True; } -int linewidth = 1; -static float ant_step = 0; - /* draw an ant */ -static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono, - Bool (*sphere)(float), Bool (*cone)(float)) { - float cos1 = cos(ant_step); - float cos2 = cos(ant_step + 2 * Pi / 3); - float cos3 = cos(ant_step + 4 * Pi / 3); - float sin1 = sin(ant_step); - float sin2 = sin(ant_step + 2 * Pi / 3); - float sin3 = sin(ant_step + 4 * Pi / 3); +static Bool draw_antinspect_ant(ModeInfo *mi, antinspectstruct * mp, + const float *Material, int mono, + Bool (*sphere)(float), Bool (*cone)(float)) +{ + float cos1 = cos(mp->ant_step); + float cos2 = cos(mp->ant_step + 2 * Pi / 3); + float cos3 = cos(mp->ant_step + 4 * Pi / 3); + float sin1 = sin(mp->ant_step); + float sin2 = sin(mp->ant_step + 2 * Pi / 3); + float sin3 = sin(mp->ant_step + 4 * Pi / 3); if (mono) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray5); @@ -244,6 +263,7 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, 0.40); + mi->polygon_count++; if (mono) glColor3fv(MaterialGray5); else @@ -251,6 +271,7 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, -0.40); + mi->polygon_count++; glEnd(); glBegin(GL_POINTS); if (mono) @@ -258,7 +279,9 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono else glColor3fv(Material); glVertex3f(0.40, 0.70, 0.40); + mi->polygon_count++; glVertex3f(0.40, 0.70, -0.40); + mi->polygon_count++; glEnd(); /* LEFT-FRONT ARM */ @@ -269,8 +292,10 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glColor3fv(Material); glVertex3f(0.00, 0.05, 0.18); glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45); + mi->polygon_count++; glEnd(); /* LEFT-CENTER ARM */ @@ -281,9 +306,12 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glColor3fv(Material); glVertex3f(0.00, 0.00, 0.18); glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45); + mi->polygon_count++; glEnd(); + mi->polygon_count++; /* LEFT-BACK ARM */ glBegin(GL_LINE_STRIP); @@ -293,8 +321,10 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glColor3fv(Material); glVertex3f(0.00, -0.05, 0.18); glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45); + mi->polygon_count++; glEnd(); /* RIGHT-FRONT ARM */ @@ -305,8 +335,10 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glColor3fv(Material); glVertex3f(0.00, 0.05, -0.18); glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45); + mi->polygon_count++; glEnd(); /* RIGHT-CENTER ARM */ @@ -317,8 +349,10 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glColor3fv(Material); glVertex3f(0.00, 0.00, -0.18); glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45); + mi->polygon_count++; glEnd(); /* RIGHT-BACK ARM */ @@ -329,8 +363,10 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono glColor3fv(Material); glVertex3f(0.00, -0.05, -0.18); glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25); + mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45); + mi->polygon_count++; glEnd(); glEnable(GL_LIGHTING); @@ -341,16 +377,16 @@ static Bool draw_antinspect_ant(antinspectstruct * mp, float *Material, int mono /* only works with 3 right now */ #define ANTCOUNT 3 -float MaterialBen[4] = {0.25, 0.30, 0.46, 1.0}; +static const float MaterialBen[4] = {0.25, 0.30, 0.46, 1.0}; -static float* antmaterial[ANTCOUNT] = +static const float* antmaterial[ANTCOUNT] = {MaterialRed, MaterialBen, MaterialOrange}; static double antposition[ANTCOUNT] = {0.0, 120.0, 240.0}; -static double antvelocity[ANTCOUNT] = {0.3, 0.3, 0.3}; -static double antsphere[ANTCOUNT] = {1.2, 1.2, 1.2}; +static const double antvelocity[ANTCOUNT] = {0.3, 0.3, 0.3}; +static const double antsphere[ANTCOUNT] = {1.2, 1.2, 1.2}; /* permutations */ -static double antorder[6][ANTCOUNT] = {{0, 1, 2}, +static const double antorder[6][ANTCOUNT] = {{0, 1, 2}, {0, 2, 1}, {2, 0, 1}, {2, 1, 0}, @@ -358,7 +394,8 @@ static double antorder[6][ANTCOUNT] = {{0, 1, 2}, {1, 0, 2}}; /* draw the scene */ -static Bool draw_antinspect_strip(ModeInfo * mi) { +static Bool draw_antinspect_strip(ModeInfo * mi) +{ antinspectstruct *mp = &antinspect[MI_SCREEN(mi)]; int i, j; int mono = MI_IS_MONO(mi); @@ -385,6 +422,7 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { glVertex3f(0.0, 0.0, -1.0); glVertex3f(-sqrt(3.0)/2.0, 0.0, 0.5); glVertex3f(sqrt(3.0)/2.0, 0.0, 0.5); + mi->polygon_count++; glEnd(); /* rotate */ @@ -394,6 +432,7 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { glVertex3f(0.0, 0.0, 1.0 + 3.0); glVertex3f(sqrt(3.0)/2.0, 0.0, -0.5 + 3.0); glVertex3f(-sqrt(3.0)/2.0, 0.0, -0.5 + 3.0); + mi->polygon_count++; glEnd(); } @@ -437,14 +476,14 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { if(antposition[i] > 360.0) antposition[i] = 0.0; - draw_antinspect_ant(mp, MaterialShadow, mono, mySphere2, myCone2); + draw_antinspect_ant(mi, mp, MaterialShadow, mono, mySphere2, myCone2); glDisable(GL_BLEND); glDisable(GL_LIGHTING); /* draw sphere */ glRotatef(-20.0, 1.0, 0.0, 0.0); - glRotatef(-ant_step*2, 0.0, 0.0, 1.0); + glRotatef(-mp->ant_step*2, 0.0, 0.0, 1.0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow); mySphere2(1.2); @@ -479,13 +518,13 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { if(antposition[i] > 360.0) antposition[i] = 0.0; glEnable(GL_BLEND); - draw_antinspect_ant(mp, antmaterial[i], mono, mySphere2, myCone2); + draw_antinspect_ant(mi, mp, antmaterial[i], mono, mySphere2, myCone2); glDisable(GL_BLEND); glPopMatrix(); /* draw sphere */ glRotatef(-20.0, 1.0, 0.0, 0.0); - glRotatef(-ant_step*2, 0.0, 0.0, 1.0); + glRotatef(-mp->ant_step*2, 0.0, 0.0, 1.0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : antmaterial[i]); mySphere2(1.2); glEnable(GL_BLEND); @@ -500,16 +539,17 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { } /* but the step size is the same! */ - ant_step += 0.2; + mp->ant_step += 0.2; mp->ant_position += 1; return True; } -void reshape_antinspect(ModeInfo * mi, int width, int height) { +ENTRYPOINT void reshape_antinspect(ModeInfo * mi, int width, int height) +{ double h = (GLfloat) height / (GLfloat) width; antinspectstruct *mp = &antinspect[MI_SCREEN(mi)]; - linewidth = (width / 512) + 1; + mp->linewidth = (width / 512) + 1; glViewport(0, 0, mp->WindW = (GLint) width, mp->WindH = (GLint) height); glMatrixMode(GL_PROJECTION); @@ -518,14 +558,13 @@ void reshape_antinspect(ModeInfo * mi, int width, int height) { gluPerspective(45, 1/h, 7.0, 20.0); glMatrixMode(GL_MODELVIEW); - glLineWidth(linewidth); - glPointSize(linewidth); + glLineWidth(mp->linewidth); + glPointSize(mp->linewidth); } -static void pinit(void) { +static void pinit(void) +{ glClearDepth(1.0); - glClearColor(0.0, 0.0, 0.0, 1.0); - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position0); @@ -549,7 +588,8 @@ static void pinit(void) { glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); } -void release_antinspect(ModeInfo * mi) { +ENTRYPOINT void release_antinspect(ModeInfo * mi) +{ if(antinspect) { free((void *) antinspect); antinspect = (antinspectstruct *) NULL; @@ -557,32 +597,20 @@ void release_antinspect(ModeInfo * mi) { FreeAllGL(mi); } -Bool antinspect_handle_event (ModeInfo *mi, XEvent *event) { +ENTRYPOINT Bool antinspect_handle_event (ModeInfo *mi, XEvent *event) +{ antinspectstruct *mp = &antinspect[MI_SCREEN(mi)]; - if(event->xany.type == ButtonPress && event->xbutton.button & Button1) { - mp->button_down_p = True; - gltrackball_start(mp->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) { - mp->button_down_p = False; - return True; - } - else if(event->xany.type == MotionNotify && mp->button_down_p) { - gltrackball_track (mp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } + if (gltrackball_event_handler (event, mp->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &mp->button_down_p)) + return True; return False; } -void init_antinspect(ModeInfo * mi) { +ENTRYPOINT void init_antinspect(ModeInfo * mi) +{ antinspectstruct *mp; if(antinspect == NULL) { @@ -593,7 +621,7 @@ void init_antinspect(ModeInfo * mi) { mp = &antinspect[MI_SCREEN(mi)]; mp->step = NRAND(90); mp->ant_position = NRAND(90); - mp->trackball = gltrackball_init (); + mp->trackball = gltrackball_init (False); if ((mp->glx_context = init_GL(mi)) != NULL) { reshape_antinspect(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); @@ -606,7 +634,8 @@ void init_antinspect(ModeInfo * mi) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } -void draw_antinspect(ModeInfo * mi) { +ENTRYPOINT void draw_antinspect(ModeInfo * mi) +{ antinspectstruct *mp; Display *display = MI_DISPLAY(mi); @@ -627,11 +656,24 @@ void draw_antinspect(ModeInfo * mi) { glPushMatrix(); + mi->polygon_count = 0; + /* position camera --- this works well, we can peer inside the antbubble */ glTranslatef(0.0, 0.0, -10.0); + +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (1/h, 1/h, 1/h); + glRotatef(o, 0, 0, 1); + } +# endif + gltrackball_rotate(mp->trackball); - glRotatef((15.0/2.0 + 15.0*sin(ant_step/100.0)), 1.0, 0.0, 0.0); + glRotatef((15.0/2.0 + 15.0*sin(mp->ant_step/100.0)), 1.0, 0.0, 0.0); glRotatef(30.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); @@ -650,7 +692,9 @@ void draw_antinspect(ModeInfo * mi) { mp->step += 0.025; } -void change_antinspect(ModeInfo * mi) { +#ifndef STANDALONE +ENTRYPOINT void change_antinspect(ModeInfo * mi) +{ antinspectstruct *mp = &antinspect[MI_SCREEN(mi)]; if (!mp->glx_context) @@ -659,4 +703,7 @@ void change_antinspect(ModeInfo * mi) { glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mp->glx_context)); pinit(); } +#endif /* !STANDALONE */ + +XSCREENSAVER_MODULE ("AntInspect", antinspect)