Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

arcball.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 
00003   arcball.h
00004 
00005   GLUI User Interface Toolkit (LGPL)
00006   Copyright (c) 1998 Paul Rademacher
00007      Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
00008      Oct 2003, Nigel Stewart - GLUI Code Cleaning
00009 
00010 
00011   WWW:    http://sourceforge.net/projects/glui/
00012   Forums: http://sourceforge.net/forum/?group_id=92496
00013 
00014   This library is free software; you can redistribute it and/or
00015   modify it under the terms of the GNU Lesser General Public
00016   License as published by the Free Software Foundation; either
00017   version 2.1 of the License, or (at your option) any later version.
00018 
00019   This library is distributed in the hope that it will be useful,
00020   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022   Lesser General Public License for more details.
00023 
00024   You should have received a copy of the GNU Lesser General Public
00025   License along with this library; if not, write to the Free Software
00026   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 
00028  ---------------------------------------------------------------------
00029 
00030   A C++ class that implements the Arcball, as described by Ken
00031   Shoemake in Graphics Gems IV.  
00032   This class takes as input mouse events (mouse down, mouse drag,
00033   mouse up), and creates the appropriate quaternions and 4x4 matrices
00034   to represent the rotation given by the mouse.  
00035   
00036   This class is used as follows:
00037   - initialize [either in the constructor or with set_params()], the
00038     center position (x,y) of the arcball on the screen, and the radius
00039   - on mouse down, call mouse_down(x,y) with the mouse position
00040   - as the mouse is dragged, repeatedly call mouse_motion() with the
00041     current x and y positions.  One can optionally pass in the current
00042     state of the SHIFT, ALT, and CONTROL keys (passing zero if keys
00043     are not pressed, non-zero otherwise), which constrains
00044     the rotation to certain axes (X for CONTROL, Y for ALT).
00045   - when the mouse button is released, call mouse_up()
00046 
00047   Axis constraints can also be explicitly set with the 
00048   set_constraints() function.
00049 
00050   The current rotation is stored in the 4x4 float matrix 'rot'.
00051   It is also stored in the quaternion 'q_now'.  
00052 
00053 **********************************************************************/
00054 
00055 #ifndef GLUI_ARCBALL_H
00056 #define GLUI_ARCBALL_H
00057 
00058 #include "glui_internal.h"
00059 #include "algebra3.h"
00060 #include "quaternion.h"
00061 
00062 class Arcball 
00063 {
00064 public:
00065     Arcball();
00066     Arcball(mat4 *mtx);
00067     Arcball(const vec2 &center, float radius);
00068 
00069     void  set_damping(float d);
00070     void  idle();
00071     void  mouse_down(int x, int y);
00072     void  mouse_up();
00073     void  mouse_motion(int x, int y, int shift, int ctrl, int alt);
00074     void  mouse_motion(int x, int y);
00075     void  set_constraints(bool constrain_x, bool constrain_y);
00076     void  set_params(const vec2 &center, float radius);  
00077     void  reset_mouse();
00078     void  init();
00079 
00080     vec3  constrain_vector(const vec3 &vector, const vec3 &axis);
00081     vec3  mouse_to_sphere(const vec2 &p);
00082  
00083   //public:
00084     int   is_mouse_down;  /* true for down, false for up */
00085     int   is_spinning;
00086     quat  q_now, q_down, q_drag, q_increment;
00087     vec2  down_pt;
00088     mat4  rot, rot_increment;
00089     mat4  *rot_ptr;
00090 
00091     bool  constraint_x, constraint_y;
00092     vec2  center;
00093     float radius, damp_factor;
00094     int   zero_increment;
00095 };
00096 
00097 #endif

Generated on Fri Sep 15 17:51:57 2006 for GLUI by doxygen 1.3.6