X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fantinspect.c;h=fb19cb081a44578077cd2413f0711dad43ace8a3;hp=0d50467146e400b79a98d4e2ac5ea322bf7eb7f7;hb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b;hpb=9c9d475ff889ed8be02e8ce8c17da28b93278fca diff --git a/hacks/glx/antinspect.c b/hacks/glx/antinspect.c index 0d504671..fb19cb08 100644 --- a/hacks/glx/antinspect.c +++ b/hacks/glx/antinspect.c @@ -15,26 +15,16 @@ * 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 #include "gltrackball.h" #define DEF_SHADOWS "True" @@ -42,24 +32,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 +80,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 +110,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 +143,11 @@ 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) +{ GLUquadricObj *quadObj; if((quadObj = gluNewQuadric()) == 0) @@ -170,7 +160,8 @@ static Bool mySphere(float radius) { } /* caged sphere */ -static Bool mySphere2(float radius) { +static Bool mySphere2(float radius) +{ GLUquadricObj *quadObj; if((quadObj = gluNewQuadric()) == 0) @@ -183,22 +174,22 @@ static Bool mySphere2(float radius) { } /* 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(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); @@ -341,16 +332,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 +349,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); @@ -444,7 +436,7 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { /* 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); @@ -485,7 +477,7 @@ static Bool draw_antinspect_strip(ModeInfo * mi) { /* 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 +492,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,11 +511,12 @@ 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); @@ -549,7 +543,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,10 +552,11 @@ 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) { + if(event->xany.type == ButtonPress && event->xbutton.button == Button1) { mp->button_down_p = True; gltrackball_start(mp->trackball, event->xbutton.x, event->xbutton.y, @@ -568,10 +564,20 @@ Bool antinspect_handle_event (ModeInfo *mi, XEvent *event) { return True; } else if(event->xany.type == ButtonRelease && - event->xbutton.button & Button1) { + event->xbutton.button == Button1) { mp->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 (mp->trackball, event->xbutton.button, 5, + !event->xbutton.state); + return True; + } else if(event->xany.type == MotionNotify && mp->button_down_p) { gltrackball_track (mp->trackball, event->xmotion.x, event->xmotion.y, @@ -582,7 +588,8 @@ Bool antinspect_handle_event (ModeInfo *mi, XEvent *event) { return False; } -void init_antinspect(ModeInfo * mi) { +ENTRYPOINT void init_antinspect(ModeInfo * mi) +{ antinspectstruct *mp; if(antinspect == NULL) { @@ -606,7 +613,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); @@ -631,7 +639,7 @@ void draw_antinspect(ModeInfo * mi) { the antbubble */ glTranslatef(0.0, 0.0, -10.0); 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 +658,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 +669,7 @@ void change_antinspect(ModeInfo * mi) { glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(mp->glx_context)); pinit(); } +#endif /* !STANDALONE */ + +XSCREENSAVER_MODULE ("AntInspect", antinspect)