35
34
* been fixed in MesaGL 2.2 and later releases.
39
* due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
40
* otherwise caddr_t is not defined correctly
43
#include <X11/Intrinsic.h>
46
38
# define PROGCLASS "Gears"
47
39
# define HACK_INIT init_gears
48
40
# define HACK_DRAW draw_gears
49
41
# define HACK_RESHAPE reshape_gears
42
# define HACK_HANDLE_EVENT gears_handle_event
43
# define EVENT_MASK PointerMotionMask
50
44
# define gears_opts xlockmore_opts
51
45
# define DEFAULTS "*count: 1 \n" \
53
47
"*delay: 20000 \n" \
54
"*planetary: False \n" \
55
48
"*showFPS: False \n" \
56
49
"*wireframe: False \n"
57
50
# include "xlockmore.h" /* from the xscreensaver distribution */
69
65
static int planetary;
71
67
static XrmOptionDescRec opts[] = {
72
{"-planetary", ".gears.planetary", XrmoptionNoArg, (caddr_t) "true" },
73
{"+planetary", ".gears.planetary", XrmoptionNoArg, (caddr_t) "false" },
68
{"-planetary", ".gears.planetary", XrmoptionNoArg, "true" },
69
{"+planetary", ".gears.planetary", XrmoptionNoArg, "false" },
76
72
static argtype vars[] = {
77
{(caddr_t *) &planetary, "planetary", "Planetary", DEF_PLANETARY, t_Bool},
73
{&planetary, "planetary", "Planetary", DEF_PLANETARY, t_Bool},
80
76
ModeSpecOpt gears_opts = {countof(opts), opts, countof(vars), vars, NULL};
102
GLfloat rotx, roty, rotz; /* current object rotation */
103
GLfloat dx, dy, dz; /* current rotational velocity */
104
GLfloat ddx, ddy, ddz; /* current rotational acceleration */
105
GLfloat d_max; /* max velocity */
107
97
GLuint gear1, gear2, gear3;
108
98
GLuint gear_inner, gear_outer;
111
101
GLXContext *glx_context;
104
trackball_state *trackball;
115
108
static gearsstruct *gears = NULL;
536
gltrackball_rotate (gp->trackball);
544
GLfloat x = gp->rotx;
545
GLfloat y = gp->roty;
546
GLfloat z = gp->rotz;
547
if (x < 0) x = 1 - (x + 1);
548
if (y < 0) y = 1 - (y + 1);
549
if (z < 0) z = 1 - (z + 1);
550
glRotatef(x * 360, 1.0, 0.0, 0.0);
551
glRotatef(y * 360, 0.0, 1.0, 0.0);
552
glRotatef(z * 360, 0.0, 0.0, 1.0);
540
get_rotation (gp->rot, &x, &y, &z, !gp->button_down_p);
541
glRotatef (x * 360, 1.0, 0.0, 0.0);
542
glRotatef (y * 360, 0.0, 1.0, 0.0);
543
glRotatef (z * 360, 0.0, 0.0, 1.0);
555
546
if (!planetary) {
924
/* lifted from lament.c */
925
#define RAND(n) ((long) ((random() & 0x7fffffff) % ((long) (n))))
926
#define RANDSIGN() ((random() & 1) ? 1 : -1)
929
rotate(GLfloat *pos, GLfloat *v, GLfloat *dv, GLfloat max_v)
916
gears_handle_event (ModeInfo *mi, XEvent *event)
944
if (ppos < 0) abort();
945
if (ppos > 1.0) abort();
946
*pos = (*pos > 0 ? ppos : -ppos);
952
if (*v > max_v || *v < -max_v)
956
/* If it stops, start it going in the other direction. */
963
/* keep going in the same direction */
978
/* Alter direction of rotational acceleration randomly. */
979
if (! (random() % 120))
982
/* Change acceleration very occasionally. */
983
if (! (random() % 200))
987
else if (random() & 1)
918
gearsstruct *gp = &gears[MI_SCREEN(mi)];
920
if (event->xany.type == ButtonPress &&
921
event->xbutton.button == Button1)
923
gp->button_down_p = True;
924
gltrackball_start (gp->trackball,
925
event->xbutton.x, event->xbutton.y,
926
MI_WIDTH (mi), MI_HEIGHT (mi));
929
else if (event->xany.type == ButtonRelease &&
930
event->xbutton.button == Button1)
932
gp->button_down_p = False;
935
else if (event->xany.type == ButtonPress &&
936
(event->xbutton.button == Button4 ||
937
event->xbutton.button == Button5))
939
gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10,
940
!!event->xbutton.state);
943
else if (event->xany.type == MotionNotify &&
946
gltrackball_track (gp->trackball,
947
event->xmotion.x, event->xmotion.y,
948
MI_WIDTH (mi), MI_HEIGHT (mi));
1011
972
gp->window = MI_WINDOW(mi);
1013
gp->rotx = frand(1.0) * RANDSIGN();
1014
gp->roty = frand(1.0) * RANDSIGN();
1015
gp->rotz = frand(1.0) * RANDSIGN();
1017
/* bell curve from 0-1.5 degrees, avg 0.75 */
1018
gp->dx = (frand(1) + frand(1) + frand(1)) / (360*2);
1019
gp->dy = (frand(1) + frand(1) + frand(1)) / (360*2);
1020
gp->dz = (frand(1) + frand(1) + frand(1)) / (360*2);
1022
gp->d_max = gp->dx * 2;
1024
gp->ddx = 0.00006 + frand(0.00003);
1025
gp->ddy = 0.00006 + frand(0.00003);
1026
gp->ddz = 0.00006 + frand(0.00003);
974
gp->rot = make_rotator (1, 1, 1, 1, 0, True);
975
gp->trackball = gltrackball_init ();
1028
977
if ((gp->glx_context = init_GL(mi)) != NULL) {
1029
978
reshape_gears(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
1055
1004
/* let's do something so we don't get bored */
1056
1005
gp->angle = (int) (gp->angle + angle_incr) % 360;
1058
rotate(&gp->rotx, &gp->dx, &gp->ddx, gp->d_max);
1059
rotate(&gp->roty, &gp->dy, &gp->ddy, gp->d_max);
1060
rotate(&gp->rotz, &gp->dz, &gp->ddz, gp->d_max);
1062
1007
if (mi->fps_p) do_fps (mi);
1064
1009
glXSwapBuffers(display, window);