1
/**********************************************************************
5
GLUI User Interface Toolkit (LGPL)
6
Copyright (c) 1998 Paul Rademacher
7
Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
8
Oct 2003, Nigel Stewart - GLUI Code Cleaning
11
WWW: http://sourceforge.net/projects/glui/
12
Forums: http://sourceforge.net/forum/?group_id=92496
14
This library is free software; you can redistribute it and/or
15
modify it under the terms of the GNU Lesser General Public
16
License as published by the Free Software Foundation; either
17
version 2.1 of the License, or (at your option) any later version.
19
This library is distributed in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
Lesser General Public License for more details.
24
You should have received a copy of the GNU Lesser General Public
25
License along with this library; if not, write to the Free Software
26
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
---------------------------------------------------------------------
30
A C++ class that implements the Arcball, as described by Ken
31
Shoemake in Graphics Gems IV.
32
This class takes as input mouse events (mouse down, mouse drag,
33
mouse up), and creates the appropriate quaternions and 4x4 matrices
34
to represent the rotation given by the mouse.
36
This class is used as follows:
37
- initialize [either in the constructor or with set_params()], the
38
center position (x,y) of the arcball on the screen, and the radius
39
- on mouse down, call mouse_down(x,y) with the mouse position
40
- as the mouse is dragged, repeatedly call mouse_motion() with the
41
current x and y positions. One can optionally pass in the current
42
state of the SHIFT, ALT, and CONTROL keys (passing zero if keys
43
are not pressed, non-zero otherwise), which constrains
44
the rotation to certain axes (X for CONTROL, Y for ALT).
45
- when the mouse button is released, call mouse_up()
47
Axis constraints can also be explicitly set with the
48
set_constraints() function.
50
The current rotation is stored in the 4x4 float matrix 'rot'.
51
It is also stored in the quaternion 'q_now'.
53
**********************************************************************/
55
#ifndef GLUI_ARCBALL_H
56
#define GLUI_ARCBALL_H
58
#include "glui_internal.h"
60
#include "quaternion.h"
67
Arcball(const vec2 ¢er, float radius);
69
void set_damping(float d);
71
void mouse_down(int x, int y);
73
void mouse_motion(int x, int y, int shift, int ctrl, int alt);
74
void mouse_motion(int x, int y);
75
void set_constraints(bool constrain_x, bool constrain_y);
76
void set_params(const vec2 ¢er, float radius);
80
vec3 constrain_vector(const vec3 &vector, const vec3 &axis);
81
vec3 mouse_to_sphere(const vec2 &p);
84
int is_mouse_down; /* true for down, false for up */
86
quat q_now, q_down, q_drag, q_increment;
88
mat4 rot, rot_increment;
91
bool constraint_x, constraint_y;
93
float radius, damp_factor;