~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/Extras/glui/arcball.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 
 
3
  arcball.h
 
4
 
 
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
 
9
 
 
10
 
 
11
  WWW:    http://sourceforge.net/projects/glui/
 
12
  Forums: http://sourceforge.net/forum/?group_id=92496
 
13
 
 
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.
 
18
 
 
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.
 
23
 
 
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
 
27
 
 
28
 ---------------------------------------------------------------------
 
29
 
 
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.  
 
35
  
 
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()
 
46
 
 
47
  Axis constraints can also be explicitly set with the 
 
48
  set_constraints() function.
 
49
 
 
50
  The current rotation is stored in the 4x4 float matrix 'rot'.
 
51
  It is also stored in the quaternion 'q_now'.  
 
52
 
 
53
**********************************************************************/
 
54
 
 
55
#ifndef GLUI_ARCBALL_H
 
56
#define GLUI_ARCBALL_H
 
57
 
 
58
#include "glui_internal.h"
 
59
#include "algebra3.h"
 
60
#include "quaternion.h"
 
61
 
 
62
class Arcball 
 
63
{
 
64
public:
 
65
    Arcball();
 
66
    Arcball(mat4 *mtx);
 
67
    Arcball(const vec2 &center, float radius);
 
68
 
 
69
    void  set_damping(float d);
 
70
    void  idle();
 
71
    void  mouse_down(int x, int y);
 
72
    void  mouse_up();
 
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 &center, float radius);  
 
77
    void  reset_mouse();
 
78
    void  init();
 
79
 
 
80
    vec3  constrain_vector(const vec3 &vector, const vec3 &axis);
 
81
    vec3  mouse_to_sphere(const vec2 &p);
 
82
 
 
83
  //public:
 
84
    int   is_mouse_down;  /* true for down, false for up */
 
85
    int   is_spinning;
 
86
    quat  q_now, q_down, q_drag, q_increment;
 
87
    vec2  down_pt;
 
88
    mat4  rot, rot_increment;
 
89
    mat4  *rot_ptr;
 
90
 
 
91
    bool  constraint_x, constraint_y;
 
92
    vec2  center;
 
93
    float radius, damp_factor;
 
94
    int   zero_increment;
 
95
};
 
96
 
 
97
#endif