/* gflux - creates a fluctuating 3D grid
* requires OpenGL or MesaGL
*
- * Copyright (c) Josiah Pease, 2000
+ * Copyright (c) Josiah Pease, 2000, 2003
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
# define HACK_INIT init_gflux
# define HACK_DRAW draw_gflux
# define HACK_RESHAPE reshape_gflux
+# define HACK_HANDLE_EVENT gflux_handle_event
+# define EVENT_MASK PointerMotionMask
# define gflux_opts xlockmore_opts
#define DEFAULTS "*delay: 20000 \n" \
"*showFPS: False \n" \
#include <math.h>
#include "grab-ximage.h"
+#include "gltrackball.h"
static enum {wire=0,solid,light,checker,textured,grab} _draw; /* draw style */
static float _waveHeight = 1.0;
static float _waveFreq = 3.0;
+static trackball_state *trackball;
+static Bool button_down_p = False;
+
#define WIDTH 320
#define HEIGHT 240
int imageMax;
GLubyte *image;
#endif
- GLint texName;
+ GLuint texName;
GLfloat tex_xscale;
GLfloat tex_yscale;
void (*drawFunc)(void);
/* BEGINNING OF FUNCTIONS */
+Bool
+gflux_handle_event (ModeInfo *mi, XEvent *event)
+{
+ if (event->xany.type == ButtonPress &&
+ event->xbutton.button & Button1)
+ {
+ button_down_p = True;
+ gltrackball_start (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)
+ {
+ button_down_p = False;
+ return True;
+ }
+ else if (event->xany.type == MotionNotify &&
+ button_down_p)
+ {
+ gltrackball_track (trackball,
+ event->xmotion.x, event->xmotion.y,
+ MI_WIDTH (mi), MI_HEIGHT (mi));
+ return True;
+ }
+
+ return False;
+}
+
+
+static void
+userRot(void)
+{
+ gltrackball_rotate (trackball);
+}
+
/* draw the gflux once */
void draw_gflux(ModeInfo * mi)
{
}
gp = &gflux[screen];
+ trackball = gltrackball_init ();
+
{
char *s = get_string_resource ("mode", "Mode");
if (!s || !*s) _draw = wire;
int real_width = gflux->modeinfo->xgwa.width;
int real_height = gflux->modeinfo->xgwa.height;
XImage *ximage = screen_to_ximage (gflux->modeinfo->xgwa.screen,
- gflux->window);
+ gflux->window,
+ NULL);
Bool bigimage = False;
int size = 0;
gflux->imageWidth = ximage->width;
gflux->imageHeight = ximage->height;
- gflux->image = ximage->data;
+ gflux->image = (GLubyte *) ximage->data;
if (bigimage) /* don't scale really large images */
{
glRotatef(anglex,1,0,0);
glRotatef(angley,0,1,0);
glRotatef(anglez,0,0,1);
+ userRot();
glScalef(1,1,(GLfloat)_waveHeight);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glEnd();
}
- time -= _speed;
- anglex -= _rotationx;
- angley -= _rotationy;
- anglez -= _rotationz;
+ if (! button_down_p) {
+ time -= _speed;
+ anglex -= _rotationx;
+ angley -= _rotationy;
+ anglez -= _rotationz;
+ }
}
void displaySolid(void)
{
glRotatef(anglex,1,0,0);
glRotatef(angley,0,1,0);
glRotatef(anglez,0,0,1);
+ userRot();
glScalef(1,1,(GLfloat)_waveHeight);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnd();
}
- time -= _speed;
- anglex -= _rotationx;
- angley -= _rotationy;
- anglez -= _rotationz;
+ if (! button_down_p) {
+ time -= _speed;
+ anglex -= _rotationx;
+ angley -= _rotationy;
+ anglez -= _rotationz;
+ }
}
glRotatef(anglex,1,0,0);
glRotatef(angley,0,1,0);
glRotatef(anglez,0,0,1);
+ userRot();
glScalef(1,1,(GLfloat)_waveHeight);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnd();
}
- time -= _speed;
- anglex -= _rotationx;
- angley -= _rotationy;
- anglez -= _rotationz;
+ if (! button_down_p) {
+ time -= _speed;
+ anglex -= _rotationx;
+ angley -= _rotationy;
+ anglez -= _rotationz;
+ }
}
void displayWire(void)
glRotatef(anglex,1,0,0);
glRotatef(angley,0,1,0);
glRotatef(anglez,0,0,1);
+ userRot();
glScalef(1,1,(GLfloat)_waveHeight);
glClear(GL_COLOR_BUFFER_BIT);
glEnd();
}
- time -= _speed;
- anglex -= _rotationx;
- angley -= _rotationy;
- anglez -= _rotationz;
+ if (! button_down_p) {
+ time -= _speed;
+ anglex -= _rotationx;
+ angley -= _rotationy;
+ anglez -= _rotationz;
+ }
}
/* generates new ripples */
double tmp;
static int newWave;
+ if (button_down_p) return;
+
tmp = 1.0/((double)_waveChange);
if(!(counter%_waveChange)) {
newWave = ((int)(counter*tmp))%_waves;