GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/GLGraphics/SimpleTrackBall.h
00001 #ifndef __GLGRAPHICS_SIMPLETRACKBALL_H__
00002 #define __GLGRAPHICS_SIMPLETRACKBALL_H__
00003 
00004 #include "CGLA/CGLA.h"
00005 #include "CGLA/Vec3f.h"
00006 
00007 
00008 namespace GLGraphics
00009 {
00010 
00024                 class SimpleTrackBall
00025                 {
00026                                 CGLA::Vec3f center;
00027         
00028                                 float r;     // Distance to center (origin)
00029                                 float theta; // Horizontal angle (azimuth)
00030                                 float phi;   // vertical angle (zenith)
00031         
00032                                 float da;    // angle increment
00033                                 float dr;    // zoom increment
00034 
00035                                 bool firsttime;   // used by the roll function
00036                                 float oldx, oldy;
00037 
00038                                 int X,Y,Z;
00039 
00040                                 void roll_x(float dx);
00041                                 void roll_y(float dy);
00042 
00043                 public:
00044 
00046                                 SimpleTrackBall(const CGLA::Vec3f& _center, float _r): 
00047                                                 center(_center),
00048                                                 r(_r), theta(static_cast<float>(M_PI_2)), phi(0.0f), 
00049                                                 da(static_cast<float>(M_PI/100.0)), dr(r/100.0f), firsttime(true),
00050                                                 X(0), Y(1), Z(2)
00051                                                 {} 
00052 
00055                                 void gl_view() const;
00056 
00057                                 void get_view(CGLA::Vec3f& c, CGLA::Vec3f& e, CGLA::Vec3f& u)
00058                                                 {
00059                                                                 const CGLA::Vec3f up(0,1,0);
00060                                                                 float x = r * sin(theta) * cos(phi);
00061                                                                 float y = r * cos(theta);
00062                                                                 float z = r * sin(theta) * sin(phi);
00063                                                                 CGLA::Vec3f dir(x,y,z);
00064                                                                 CGLA::Vec3f eye = center + CGLA::Vec3f(dir[X], dir[Y], dir[Z]);
00065                                                                 c = center;
00066                                                                 e = eye;
00067                                                                 u = CGLA::Vec3f(up[X], up[Y], up[Z]);
00068                                                 }
00069 
00070                                 void up_axis(char up);
00071 
00073                                 void farther()
00074                                                 {
00075                                                                 r += dr;
00076                                                 }
00077                 
00079                                 void closer()
00080                                                 {
00081                                                                 r = CGLA::s_max(0.0f, r - dr);
00082                                                 }
00083 
00086                                 void roll(int x, int y);
00087 
00088                                 void set_center(const CGLA::Vec3f& _center)
00089                                                 {
00090                                                                 center = _center;
00091                                                 }
00092                 };
00093 
00094 }
00095 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations