http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.05.tar.gz
[xscreensaver] / hacks / glx / gltrackball.h
1 /* gltrackball, Copyright (c) 2002-2008 Jamie Zawinski <jwz@jwz.org>
2  * GL-flavored wrapper for trackball.c
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 #ifndef __GLTRACKBALL_H__
14 #define __GLTRACKBALL_H__
15
16 typedef struct trackball_state trackball_state;
17
18 /* Returns a trackball_state object, which encapsulates the stuff necessary
19    to make dragging the mouse on the window of a GL program do the right thing.
20  */
21 extern trackball_state *gltrackball_init (void);
22
23 /* Begin tracking the mouse: Call this when the mouse button goes down.
24    x and y are the mouse position relative to the window.
25    w and h are the size of the window.
26  */
27 extern void gltrackball_start (trackball_state *, int x, int y, int w, int h);
28
29 /* Track the mouse: Call this each time the mouse moves with the button down.
30    x and y are the new mouse position relative to the window.
31    w and h are the size of the window.
32  */
33 extern void gltrackball_track (trackball_state *, int x, int y, int w, int h);
34
35 /* Execute the rotations current encapsulated in the trackball_state:
36    this does something analagous to glRotatef().
37  */
38 extern void gltrackball_rotate (trackball_state *);
39
40 /* Call this when a mouse-wheel click is detected.
41    Clicks act like horizontal or vertical drags.
42    Percent is the length of the drag as a percentage of the screen size.
43    Button is 'Button4' or 'Button5' (for the vertical wheel)
44    or 'Button5' or 'Button6' (for the horizontal wheel).
45    If `flip_p' is true, swap the horizontal and vertical axes.
46  */
47 void gltrackball_mousewheel (trackball_state *ts,
48                              int button, int percent, int flip_p);
49
50 /* Return the quaternion encapsulated by the trackball state.
51  */
52 extern void gltrackball_get_quaternion (trackball_state *ts, float q[4]);
53
54 #endif /* __GLTRACKBALL_H__ */
55