4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
5 Copyright (c) 1998 Paul Rademacher
6 Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
7 Oct 2003, Nigel Stewart - GLUI Code Cleaning
9 This file is part of simavr.
11 simavr is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 simavr is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with simavr. If not, see <http://www.gnu.org/licenses/>.
26 Arcball, as described by Ken
27 Shoemake in Graphics Gems IV.
28 This class takes as input mouse events (mouse down, mouse drag,
29 mouse up), and creates the appropriate quaternions and 4x4 matrices
30 to represent the rotation given by the mouse.
32 This class is used as follows:
33 - initialize [either in the constructor or with set_params()], the
34 center position (x,y) of the arcball on the screen, and the radius
35 - on mouse down, call mouse_down(x,y) with the mouse position
36 - as the mouse is dragged, repeatedly call mouse_motion() with the
37 current x and y positions. One can optionally pass in the current
38 state of the SHIFT, ALT, and CONTROL keys (passing zero if keys
39 are not pressed, non-zero otherwise), which constrains
40 the rotation to certain axes (X for CONTROL, Y for ALT).
41 - when the mouse button is released, call mouse_up()
43 Axis constraints can also be explicitly set with the
44 set_constraints() function.
46 The current rotation is stored in the 4x4 float matrix 'rot'.
47 It is also stored in the quaternion 'q_now'.
50 #ifndef __C3ARCBALL_H___
51 #define __C3ARCBALL_H___
53 #include "c3/c3quaternion.h"
55 typedef struct c3arcball {
56 int is_mouse_down : 1, /* true for down, false for up */
61 c3quat q_now, q_down, q_drag, q_increment;
63 c3mat4 rot, rot_increment;
67 c3f radius, damp_factor;
68 } c3arcball, *c3arcballp;
78 c3arcball_init_center(
88 c3arcball_mouse_to_sphere(
92 c3arcball_constrain_vector(
105 c3arcball_mouse_motion(
113 c3arcball_set_constraints(
121 c3arcball_set_damping(
125 #endif /* __C3ARCBALL_H___ */