-static void clamp(vec3_t v)
-{
- int i;
-
- for (i = 0; i < 3; i ++)
- if (v[i] > 360 || v[i] < -360)
- v[i] = 0;
-}
-
-/* track the mouse in a joystick manner : not perfect but it works */
-static void trackmouse(ModeInfo * mi)
-{
- sballsstruct *sb = &sballs[MI_SCREEN(mi)];
- /* we keep static values (not per screen) for the mouse stuff: in general you have only one mouse :-> */
- static int max[2] = { 0, 0 };
- static int min[2] = { 0x7fffffff, 0x7fffffff }, center[2];
- Window r, c;
- int rx, ry, cx, cy;
- unsigned int m;
-
- (void) XQueryPointer(MI_DISPLAY(mi), MI_WINDOW(mi),
- &r, &c, &rx, &ry, &cx, &cy, &m);
-
- if (max[0] < cx)
- max[0] = cx;
- if (min[0] > cx)
- min[0] = cx;
- center[0] = (max[0] + min[0]) / 2;
-
- if (max[1] < cy)
- max[1] = cy;
- if (min[1] > cy)
- min[1] = cy;
- center[1] = (max[1] + min[1]) / 2;
-
- if (fabs(center[0] - (float) cx) > 0.1 * (max[0] - min[0]))
- sb->rot[0] -= ((center[0] - (float) cx) / (max[0] - min[0]) * 180.0f) / 200.0f;
- if (fabs(center[1] - (float) cy) > 0.1 * (max[1] - min[1]))
- sb->rot[1] -= ((center[1] - (float) cy) / (max[1] - min[1]) * 180.0f) / 200.0f;;
- clamp(sb->rot);
-
- /* oops: can't get those buttons */
- if (m & Button4Mask)
- sb->speed++;
- if (m & Button5Mask)
- sb->speed--;
-
-}