-/* gltrackball, Copyright (c) 2002-2014 Jamie Zawinski <jwz@jwz.org>
+/* gltrackball, Copyright (c) 2002-2017 Jamie Zawinski <jwz@jwz.org>
* GL-flavored wrapper for trackball.c
*
* Permission to use, copy, modify, distribute, and sell this software and its
#include "trackball.h"
#include "gltrackball.h"
+#if defined(USE_IPHONE) || defined(HAVE_ANDROID)
+ /* Surely this should be defined somewhere more centrally... */
+# define HAVE_MOBILE
+#endif
+
/* Bah, copied from ../fps.h */
-#ifdef USE_IPHONE
+#ifdef HAVE_MOBILE
extern double current_device_rotation (void);
#else
# define current_device_rotation() (0)
return ts;
}
-/* Reset the trackball to the default unrotated state.
- */
-void
-gltrackball_reset (trackball_state *ts)
-{
- int bd = ts->button_down_p;
- int ig = ts->ignore_device_rotation_p;
- memset (ts, 0, sizeof(*ts));
- ts->button_down_p = bd;
- ts->ignore_device_rotation_p = ig;
- trackball (ts->q, 0, 0, 0, 0);
-}
-
-
/* Device rotation interacts very strangely with mouse positions.
I'm not entirely sure this is the right fix.
*/
static void
gltrackball_track_1 (trackball_state *ts,
double x, double y,
- int w, int h)
+ int w, int h,
+ int ignore_device_rotation_p)
{
double X = x;
double Y = y;
ts->x = x;
ts->y = y;
- adjust_for_device_rotation (ts, &ox, &oy, &W, &H);
- adjust_for_device_rotation (ts, &X, &Y, &W2, &H2);
-
+ if (! ignore_device_rotation_p)
+ {
+ adjust_for_device_rotation (ts, &ox, &oy, &W, &H);
+ adjust_for_device_rotation (ts, &X, &Y, &W2, &H2);
+ }
trackball (q2,
(2 * ox - W) / W,
(H - 2 * oy) / H,
ts->ddy = ts->dy * dampen;
ts->ow = w;
ts->oh = h;
- gltrackball_track_1 (ts, x, y, w, h);
+ gltrackball_track_1 (ts, x, y, w, h, False);
}
}
+/* Reset the trackball to the default unrotated state,
+ plus an optional initial rotation.
+ */
+void
+gltrackball_reset (trackball_state *ts, float x, float y)
+{
+ int bd = ts->button_down_p;
+ int ig = ts->ignore_device_rotation_p;
+ memset (ts, 0, sizeof(*ts));
+ ts->button_down_p = bd;
+ ts->ignore_device_rotation_p = ig;
+ trackball (ts->q, 0, 0, x, y);
+}
+
+
/* Execute the rotations current encapsulated in the trackball_state:
this does something analagous to glRotatef().
*/
gltrackball_track_1 (ts,
ts->x + ts->dx,
ts->y + ts->dy,
- ts->ow, ts->oh);
+ ts->ow, ts->oh,
+ False);
/* Dampen inertia: gradually stop spinning. */
gltrackball_dampen (&ts->dx, &ts->ddx);
int horizontal_p;
int mx, my, move, scale;
-#ifdef HAVE_COCOA
+#ifdef HAVE_JWXYZ
flip_p = 0; /* MacOS has already handled this. */
#endif