1 | /* |
---|
2 | * Simple trackball-like motion adapted (ripped off) from projtex.c |
---|
3 | * (written by David Yu and David Blythe). See the SIGGRAPH '96 |
---|
4 | * Advanced OpenGL course notes. |
---|
5 | * |
---|
6 | * |
---|
7 | * Usage: |
---|
8 | * |
---|
9 | * o call tbInit() in before any other tb call |
---|
10 | * o call tbReshape() from the reshape callback |
---|
11 | * o call tbMatrix() to get the trackball matrix rotation |
---|
12 | * o call tbStartMotion() to begin trackball movememt |
---|
13 | * o call tbStopMotion() to stop trackball movememt |
---|
14 | * o call tbMotion() from the motion callback |
---|
15 | * o call tbAnimate(GL_TRUE) if you want the trackball to continue |
---|
16 | * spinning after the mouse button has been released |
---|
17 | * o call tbAnimate(GL_FALSE) if you want the trackball to stop |
---|
18 | * spinning after the mouse button has been released |
---|
19 | * |
---|
20 | * Typical setup: |
---|
21 | * |
---|
22 | * |
---|
23 | void |
---|
24 | init(void) |
---|
25 | { |
---|
26 | tbInit(GLUT_MIDDLE_BUTTON); |
---|
27 | tbAnimate(GL_TRUE); |
---|
28 | . . . |
---|
29 | } |
---|
30 | |
---|
31 | void |
---|
32 | reshape(int width, int height) |
---|
33 | { |
---|
34 | tbReshape(width, height); |
---|
35 | . . . |
---|
36 | } |
---|
37 | |
---|
38 | void |
---|
39 | display(void) |
---|
40 | { |
---|
41 | glPushMatrix(); |
---|
42 | |
---|
43 | tbMatrix(); |
---|
44 | . . . draw the scene . . . |
---|
45 | |
---|
46 | glPopMatrix(); |
---|
47 | } |
---|
48 | |
---|
49 | void |
---|
50 | mouse(int button, int state, int x, int y) |
---|
51 | { |
---|
52 | tbMouse(button, state, x, y); |
---|
53 | . . . |
---|
54 | } |
---|
55 | |
---|
56 | void |
---|
57 | motion(int x, int y) |
---|
58 | { |
---|
59 | tbMotion(x, y); |
---|
60 | . . . |
---|
61 | } |
---|
62 | |
---|
63 | int |
---|
64 | main(int argc, char** argv) |
---|
65 | { |
---|
66 | . . . |
---|
67 | init(); |
---|
68 | glutReshapeFunc(reshape); |
---|
69 | glutDisplayFunc(display); |
---|
70 | glutMouseFunc(mouse); |
---|
71 | glutMotionFunc(motion); |
---|
72 | . . . |
---|
73 | } |
---|
74 | * |
---|
75 | * */ |
---|
76 | |
---|
77 | |
---|
78 | /* functions */ |
---|
79 | #ifdef __cplusplus |
---|
80 | extern "C" { |
---|
81 | #endif |
---|
82 | |
---|
83 | void |
---|
84 | tbInit(GLuint button); |
---|
85 | |
---|
86 | void |
---|
87 | tbMatrix(void); |
---|
88 | |
---|
89 | void |
---|
90 | tbReshape(int width, int height); |
---|
91 | |
---|
92 | void |
---|
93 | tbMouse(int button, int state, int x, int y); |
---|
94 | |
---|
95 | void |
---|
96 | tbMotion(int x, int y); |
---|
97 | |
---|
98 | void |
---|
99 | tbAnimate(GLboolean animate); |
---|
100 | |
---|
101 | #ifdef __cplusplus |
---|
102 | } |
---|
103 | #endif |
---|