Fawkes API  Fawkes Development Version
trackball.h
1 
2 /***************************************************************************
3  * trackball.h - Smooth mouse movements for OpenGL window
4  *
5  * Created: Fri Apr 01 19:56:31 2011
6  * Copyright 2011 Tim Niemueller [www.niemueller.de]
7  *
8  * The code has is based on the OpenGL example "smooth" by Nate Robins
9  * It states:
10  * "Simple trackball-like motion adapted (ripped off) from projtex.c
11  * (written by David Yu and David Blythe). See the SIGGRAPH '96
12  * Advanced OpenGL course notes."
13  *
14  ****************************************************************************/
15 
16 /* This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU Library General Public License for more details.
25  *
26  * Read the full text in the LICENSE.GPL file in the doc directory.
27  */
28 
29 /*
30  * Usage:
31  *
32  * o call tbInit() in before any other tb call
33  * o call tbReshape() from the reshape callback
34  * o call tbMatrix() to get the trackball matrix rotation
35  * o call tbStartMotion() to begin trackball movememt
36  * o call tbStopMotion() to stop trackball movememt
37  * o call tbMotion() from the motion callback
38  * o call tbAnimate(GL_TRUE) if you want the trackball to continue
39  * spinning after the mouse button has been released
40  * o call tbAnimate(GL_FALSE) if you want the trackball to stop
41  * spinning after the mouse button has been released
42  *
43  * Typical setup:
44  *
45  *
46  void
47  init(void)
48  {
49  tbInit(GLUT_MIDDLE_BUTTON);
50  tbAnimate(GL_TRUE);
51  . . .
52  }
53 
54  void
55  reshape(int width, int height)
56  {
57  tbReshape(width, height);
58  . . .
59  }
60 
61  void
62  display(void)
63  {
64  glPushMatrix();
65 
66  tbMatrix();
67  . . . draw the scene . . .
68 
69  glPopMatrix();
70  }
71 
72  void
73  mouse(int button, int state, int x, int y)
74  {
75  tbMouse(button, state, x, y);
76  . . .
77  }
78 
79  void
80  motion(int x, int y)
81  {
82  tbMotion(x, y);
83  . . .
84  }
85 
86  int
87  main(int argc, char** argv)
88  {
89  . . .
90  init();
91  glutReshapeFunc(reshape);
92  glutDisplayFunc(display);
93  glutMouseFunc(mouse);
94  glutMotionFunc(motion);
95  . . .
96  }
97  *
98  * */
99 
100 #include <GL/gl.h>
101 
102 /* functions */
103 void tbInit(GLuint button);
104 void tbMatrix();
105 void tbReshape(int width, int height);
106 void tbMouse(int button, int state, int x, int y);
107 void tbMotion(int x, int y);
108 void tbAnimate(GLboolean animate, void (* idle_func)() = 0);