trackball.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                               \/)\/     *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 Revision 1.16  2007/07/14 12:43:44  benedetti
00028 Added Doxygen documentation.
00029 
00030 Revision 1.15  2007/06/13 17:15:08  benedetti
00031 Added one-level undo system and sticky trackmodes.
00032 
00033 Revision 1.14  2007/05/15 15:00:47  benedetti
00034 Moved the drawing code to trackmodes, some other minor changes
00035 
00036 Revision 1.13  2007/02/26 01:30:02  cignoni
00037 Added reflection Name
00038 
00039 Revision 1.12  2007/01/15 15:04:15  tarini
00040 added "ToAscii" and "SetFromAscii" methods to load/store current trackball status from/to ascii strings
00041 (intended uses: clipboard operations and comments inside png snapshots!)
00042 
00043 Revision 1.11  2006/08/23 15:40:57  marfr960
00044 *** empty log message ***
00045 
00046 Revision 1.10  2006/02/13 13:15:52  cignoni
00047 Added Scale and Translate methods.
00048 Added many drawing hints and raised the default num. of steps when drawing circles.
00049 Added MouseDown without coords (for remembering changes of keys modifiers)
00050 Added ZMode to the default modes under Alt+left
00051 Added DrawPostApply (to be completed)
00052 
00053 Revision 1.9  2005/10/17 01:29:46  cignoni
00054 Main restructuring. Removed the Draw function and slightly changed the meaning of the trackball itself.
00055 See the notes at the beginning of trackball.h
00056 
00057 Revision 1.8  2004/07/11 22:06:56  cignoni
00058 Added scaling by wheel
00059 
00060 Revision 1.7  2004/06/09 14:01:13  cignoni
00061 Heavily restructured. To be completed only rotation works...
00062 
00063 Revision 1.6  2004/05/14 03:15:09  ponchio
00064 Redesigned partial version.
00065 
00066 Revision 1.5  2004/05/12 20:55:18  ponchio
00067 *** empty log message ***
00068 
00069 Revision 1.4  2004/05/07 12:46:08  cignoni
00070 Restructured and adapted in a better way to opengl
00071 
00072 Revision 1.3  2004/04/07 10:54:10  cignoni
00073 Commented out unused parameter names and other minor warning related issues
00074 
00075 Revision 1.2  2004/03/25 14:55:25  ponchio
00076 Adding copyright.
00077 
00078 
00079 ****************************************************************************/
00080 #ifndef TRACKBALL_H
00081 #define TRACKBALL_H
00082 
00083 #include <time.h>
00084 #include <vcg/math/similarity.h>
00085 #include <vcg/space/color4.h>
00086 #include <wrap/gui/view.h>
00087 #include <wrap/gui/trackmode.h>
00088 #include <list>
00089 #include <vector>
00090 #include <map>
00091 
00092 namespace vcg {
00099 class Transform {
00100 public:
00109   Transform();
00111   Similarityf track;
00113   Point3f center; 
00115   float radius; 
00116 };
00117 
00126 Transform interpolate(const Transform &a, const Transform &b, float t);
00127 
00128 class TrackMode;
00129 
00167 class Trackball: public Transform {
00168 public:
00169 
00171   enum Button { BUTTON_NONE   = 0x0000, 
00172                 BUTTON_LEFT   = 0x0001, 
00173                 BUTTON_MIDDLE = 0x0002, 
00174                 BUTTON_RIGHT  = 0x0004, 
00175                 WHEEL         = 0x0008, 
00176                 KEY_SHIFT     = 0x0010, 
00177                 KEY_CTRL      = 0x0020, 
00178                 KEY_ALT       = 0x0040, 
00179                 HANDLE        = 0x0080, 
00180                                                                 MODIFIER_MASK = 0x00FF, 
00181                                                                 KEY_UP        = 0x0100, 
00182                                                                 KEY_DOWN      = 0x0200, 
00183                                                                 KEY_LEFT      = 0x0400, 
00184                                                                 KEY_RIGHT     = 0x0800, 
00185                                                                 KEY_PGUP      = 0x1000, 
00186                                                                 KEY_PGDOWN    = 0x2000, 
00187               };
00188 
00195   Trackball();
00201   ~Trackball();
00202         
00203         private:
00204         // Trackball must not be copied. Use Append (see vcg/complex/trimesh/append.h)
00205         Trackball operator =(const Trackball &  /*m*/){ assert(0); return *this; }
00206         public:
00212   void SetIdentity();
00219   void SetPosition(const Point3f &c, int millisec = 0);
00225   void SetScale(const float s) {radius=s;};
00232   void SetTransform(const Transform &transform, int millisec = 0);
00238   void Translate(Point3f tr);
00244   void Scale(const float f);
00245 
00246   //operating
00250   void GetView();
00251 
00258   void Apply ();
00259 
00268   void DrawPostApply();
00269 
00273   void ApplyInverse();
00274   // DrawIcon() has been moved to trackutils.h
00275   //void DrawIcon();
00276   
00277   // T(c) S R T(t) T(-c) => S R T(S^(-1) R^(-1)(c) + t - c)
00278   Matrix44f Matrix() const;
00279   Matrix44f InverseMatrix() const;
00280 
00284   void Reset();
00285 
00289   void ClearModes();
00290 
00291   // DrawCircle (), DrawPlane(), DrawPlaneHandle() has been moved to trackutils.h
00292   // the drawing code has been moved to the trackmodes
00293   // void DrawCircle ();
00294   // void DrawPlane();
00295   // void DrawPlaneHandle();
00296 
00297   //interface
00303   void MouseDown(/*Button*/ int button);
00311   void MouseDown(int x, int y, /*Button*/ int button);
00318   void MouseMove(int x, int y); 
00326   void MouseUp(int x, int y, /*Button */ int button); 
00332   void MouseWheel(float notch);
00339   void MouseWheel (float notch, /*Button */ int button);
00345   void ButtonUp(Button button);
00351   void ButtonDown(Button button, unsigned int msec=0);
00358   void Undo();
00359 
00360   //default sensitivity 1
00366   void SetSensitivity(float s);
00367 
00368   void SetSpinnable(bool on);
00369 
00370         
00371         // returns if it is animating or not
00372         // 
00373         bool IsAnimating(unsigned int msec=0);
00374 
00375         // Animate: either takes an absolute time (if default not specified, then it is automeasured)
00376         // or a fixed delta
00377         void Animate(unsigned int msec=0);
00378 
00384         bool IsSpinnable();
00390   void SetSpinning(Quaternionf &spin);
00394   void StopSpinning();
00400   bool IsSpinning();
00401 
00402   //interfaccia navigation:
00406   void Back();
00410   void Forward();
00414   void Home();
00418   void Store();
00422   void HistorySize(int lenght);
00423 
00424 /*    //internals  // commented out no more used this stuff!
00425     enum Action { NONE = 0,
00426                   VIEW_ROTATE = 1,
00427                   // Axis Constrained Rotation 
00428                   TRACK_ROTATE_X = 3, TRACK_ROTATE_Y = 4, TRACK_ROTATE_Z = 5,
00429                   // Drag constrained to an axis (trackball axis)
00430                   DRAG_X = 6,   DRAG_Y = 7,   DRAG_Z = 8,
00431                   // Drag constrained to a plane
00432                   DRAG_XY = 9,  DRAG_YZ = 10,  DRAG_XZ = 11,
00433                   //scale model respect to center of trackball
00434                   VIEW_SCALE = 12,
00435                   //scale trackball and model
00436                   TRACK_SCALE = 13
00437     };
00438 */
00439   // loads stores current status from/to ascii stings
00446   void ToAscii(char * st);
00454   bool SetFromAscii(const char * st);
00455 
00456   //protected:
00458   View<float> camera;
00464   void SetCurrentAction();
00466   int current_button;
00468   TrackMode *current_mode;
00469 
00471   TrackMode *inactive_mode;
00472   
00473   // The manipulator to deal with timer events and key events
00474   TrackMode *idle_and_keys_mode; 
00487   void setDefaultMapping ();
00488 
00490   std::map<int, TrackMode *> modes;
00491 
00492   // undo_track and last_track have different meanings..
00494   Similarityf last_track;
00496   Similarityf undo_track; 
00498   Similarityf last_view;
00500   Point3f last_point;
00502   std::vector<Point3f> Hits;
00504   bool dragging;
00506   int button_mask;
00507 
00508         unsigned int last_time;
00509 
00511   Quaternionf spin;
00513   bool spinnable;
00515   bool spinning;
00516 
00518   std::list<Transform> history;
00520   int history_size;
00521 
00522 
00523         void SetFixedTimesteps(bool mode){
00524                 fixedTimestepMode=mode;
00525         }
00526 
00528   friend class TrackMode;
00529 private:
00530         void Sync(unsigned int msec);
00531         bool fixedTimestepMode; // if true, animations occurs at fixed time steps
00532 
00533 };
00534 
00535 
00536 }//namespace
00537 
00538 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:37:26