trackmode.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.15  2007/07/14 12:43:44  benedetti
00028 Added Doxygen documentation.
00029 
00030 Revision 1.14  2007/07/09 22:47:18  benedetti
00031 Removed using namespace std and modified accordingly.
00032 
00033 Revision 1.13  2007/06/25 10:21:38  fiorin
00034 Added some std:: here and there
00035 
00036 Revision 1.12  2007/06/13 17:15:09  benedetti
00037 Added one-level undo system and sticky trackmodes.
00038 
00039 Revision 1.11  2007/05/15 14:59:10  benedetti
00040 Main restructuring. added many new modes
00041 
00042 Revision 1.10  2007/02/26 01:30:02  cignoni
00043 Added reflection Name
00044 
00045 Revision 1.9  2006/02/13 13:10:27  cignoni
00046 Added Zmode for moving objects along the perpendicular to the viewplane
00047 
00048 Revision 1.8  2004/07/18 06:54:08  cignoni
00049 Added Scaling
00050 
00051 Revision 1.7  2004/07/11 22:06:56  cignoni
00052 Added scaling by wheel
00053 
00054 Revision 1.6  2004/06/09 14:01:13  cignoni
00055 Heavily restructured. To be completed only rotation works...
00056 
00057 Revision 1.5  2004/05/14 03:15:09  ponchio
00058 Redesigned partial version.
00059 
00060 Revision 1.4  2004/05/07 12:46:08  cignoni
00061 Restructured and adapted in a better way to opengl
00062 
00063 Revision 1.3  2004/04/07 10:54:11  cignoni
00064 Commented out unused parameter names and other minor warning related issues
00065 
00066 Revision 1.2  2004/03/25 14:55:25  ponchio
00067 Adding copyright.
00068 
00069 
00070 ****************************************************************************/
00071 
00072 #ifndef TRACKMODE_H
00073 #define TRACKMODE_H
00074 
00075 #include <vcg/space/line3.h>
00076 #include <vcg/space/plane3.h>
00077 #include <vcg/space/segment3.h>
00078 #include <vcg/space/ray3.h>
00079 #include <wrap/gui/view.h>
00080 
00081 namespace vcg {
00082 
00083 class Trackball;
00084 
00093 class TrackMode {
00094 public:
00098   virtual ~TrackMode () {
00099   }
00108   virtual void Apply (Trackball * trackball, Point3f new_point);
00117   virtual void Apply (Trackball * trackball, float WheelNotch);
00123   virtual void SetAction ();
00129   virtual void Reset ();
00135   virtual const char *Name (){
00136     return "TrackMode";
00137   };
00143   virtual void Draw (Trackball * trackball);
00157   virtual bool isSticky();
00166   virtual void Undo();
00167 
00168         virtual bool IsAnimating(const Trackball *tb);
00169         virtual void Animate(unsigned int msec, Trackball *tb);
00170 }; 
00171 
00178 class InactiveMode:public TrackMode {
00179 public:
00185   const char *Name () {
00186     return "InactiveMode";
00187   };
00193  void Draw (Trackball * trackball);
00194 };
00195 
00196 /* View space modes */
00197 
00198 // old interfaces
00199 /*
00200 class SphereMode: public TrackMode {
00201 }
00202 class CylinderMode: public TrackMode {
00203 }
00204 class PlaneMode: public TrackMode {
00205 }
00206 class ZMode: public TrackMode {
00207 }
00208 class LineMode: public TrackMode {
00209 }
00210 class LineMode: public TrackMode {
00211 }
00212 class ScaleMode: public TrackMode {
00213 
00214 */
00215 
00216 // Sphere mode.
00226 class SphereMode:public TrackMode {
00227 public:
00238   void Apply (Trackball * trackball, Point3f new_point);
00244   const char *Name () {
00245     return "SphereMode";
00246   };
00252   void Draw (Trackball * trackball);
00253 };
00254 
00255 // Panning mode.
00265 class PanMode:public TrackMode {
00266 public:
00275   void Apply (Trackball * trackball, Point3f new_point);
00281   const char *Name () {
00282     return "PanMode";
00283   };
00289  void Draw (Trackball * trackball);
00290 };
00291 
00292 // Z mode.
00305 class ZMode:public TrackMode {
00306 public:
00312   const char *Name () {
00313     return "ZMode";
00314   };
00325   void Apply (Trackball * trackball, Point3f new_point);
00336   void Apply (Trackball * trackball, float WheelNotch);
00342   void Draw (Trackball * trackball);
00343 };
00344 
00345 // Scale Mode.
00357 class ScaleMode:public TrackMode {
00358 public:
00364   const char *Name () {
00365     return "ScaleMode";
00366   };
00377   void Apply (Trackball * trackball, Point3f new_point);
00388   void Apply (Trackball * trackball, float WheelNotch);
00394   void Draw (Trackball * trackball);
00395 };
00396 
00397 // Axis mode.
00410 class AxisMode:public TrackMode {
00411 public:
00421   AxisMode (const Line3f & ln)
00422     : axis (ln) {
00423   }
00434   AxisMode (const Point3f & origin, const Point3f & direction)
00435     : axis(Line3fN (origin, direction)) {
00436   }
00442   const char *Name () {
00443     return "AxisMode";
00444   };
00456   void Apply (Trackball * trackball, Point3f new_point);
00465   void Apply (Trackball * trackball, float WheelNotch);
00471   void Draw (Trackball * trackball);
00472 private:
00474   Line3fN axis;
00475 };
00476 
00477 // Plane mode.
00487 class PlaneMode:public TrackMode {
00488 public:
00501   PlaneMode (float a, float b, float c, float d)
00502     : plane(Plane3f(d,Point3f(a,b,c))){
00503   }
00512   PlaneMode (Plane3f & pl)
00513     : plane(pl) {
00514   }
00520  const char *Name () {
00521     return "PlaneMode";
00522   };
00534   void Apply (Trackball * trackball, Point3f new_point);
00540   void Draw (Trackball * trackball);
00541 private:
00543   Plane3f plane;
00544 };
00545 
00546 // Cylinder mode.
00560 class CylinderMode:public TrackMode {
00561 public:
00572   CylinderMode (Line3fN & ln,float s=0.0f)
00573     : axis (ln), snap(s){
00574     assert(snap>=0.0);
00575   }
00587   CylinderMode (const Point3f & origin, const Point3f & direction,float s=0.0f)
00588     : axis (Line3fN(origin,direction)), snap(s){
00589     assert(snap>=0.0);
00590   }
00596   const char *Name () {
00597     return "CylinderMode";
00598   };
00610   void Apply (Trackball * trackball, Point3f new_point);
00619   void Apply (Trackball * trackball, float WheelNotch);
00625   void Draw (Trackball * trackball);
00626 private:
00628   Line3fN axis;
00630   float snap;
00631 };
00632 
00633 // Path mode.
00649 class PathMode:public TrackMode {
00650 public:
00663   PathMode ( const std::vector < Point3f > &pts, bool w = false)
00664     : points(), wrap(w), current_state(0), initial_state(0), old_hitpoint()
00665   {
00666     Init(pts);
00667     assert(min_seg_length > 0.0f);
00668   }
00677   PathMode ( const Point3f &start, const Point3f &end )
00678     : points(), wrap(false), current_state(0), initial_state(0), old_hitpoint()
00679   {
00680     points.push_back(start);    
00681     points.push_back(end); 
00682     path_length=Distance(start,end);
00683     min_seg_length=path_length;
00684     assert(min_seg_length > 0.0f);
00685   }
00691   const char *Name () {
00692     return "PathMode";
00693   };
00705   void Apply (Trackball * trackball, Point3f new_point);
00717   void Apply (Trackball * trackball, float WheelNotch);
00723   void Draw (Trackball * trackball);
00729   void SetAction ();
00735   void Reset (); 
00746   Point3f SetStartNear(Point3f p);
00755   bool isSticky();
00761   void Undo();
00762 private:
00770   void Init(const std::vector < Point3f > &points);
00783   void GetPoints(float state, Point3f & point, Point3f & prev_point, Point3f & next_point);
00793   float Normalize(float state);
00806   float HitPoint(float state, Ray3fN ray, Point3f &hit_point);
00820   int Verse(Point3f reference_point,Point3f current_point,Point3f prev_point,Point3f next_point);
00821 
00823   std::vector < Point3f > points;
00825   bool wrap;
00827   float current_state;
00829   float initial_state;
00831   float path_length;
00833   float min_seg_length;
00835   Point3f old_hitpoint;
00837   float undo_current_state;
00839   Point3f undo_old_hitpoint;
00840 };
00841 
00842 // Area mode.
00861 class AreaMode:public TrackMode {
00862 public:
00876   AreaMode (const std::vector < Point3f > &pts)
00877   {
00878     Init(pts);
00879     assert(min_side_length > 0.0f);
00880   }
00886   const char *Name () {
00887     return "AreaMode";
00888   };
00899   void Apply (Trackball * trackball, Point3f new_point);
00905   void Draw (Trackball * trackball);
00911   void SetAction ();
00917   void Reset (); 
00928   Point3f SetStartNear(Point3f p);
00937   bool isSticky();
00943   void Undo();
00944 private:
00952   void Init(const std::vector < Point3f > &pts);
00963   bool Inside(Point3f point);
00980   Point3f Move(Point3f start,Point3f end);
00981 
00983   std::vector < Point3f > points;
00985   bool begin_action;
00987   int first_coord_kept;
00989   int second_coord_kept;
00991   float min_side_length;
00993   Point3f status;
00995   Point3f delta_mouse;
00997   Point3f old_status;
00999   Point3f initial_status;
01001   Plane3f plane;
01003   Point3f rubberband_handle ;
01005   std::vector < Point3f > path;
01007   bool undo_begin_action;
01009   Point3f undo_status;
01011   Point3f undo_delta_mouse;
01013   Point3f undo_old_status;
01015   Point3f undo_rubberband_handle;
01017   size_t undo_path_index;
01018 
01019 };
01020 
01021 // Polar mode.
01022 /* WARNING this mode is not compatible with the other rotation modes */
01023 
01024 class PolarMode:public TrackMode {
01025 public:
01026   PolarMode(): alpha(0), beta(0), enda(0), endb(0) {}
01027    void Apply (Trackball * trackball, Point3f new_point);
01028 
01029   const char *Name () {
01030     return "PolarMode";
01031   };
01032   void SetAction();
01033   void Reset(); 
01034  void Draw (Trackball * trackball);
01035 private:
01036  float alpha, beta; //rotation in y and x axis
01037  float enda, endb;  //store intermediate values of alpha and beta
01038 };
01039 
01040 class NavigatorWasdMode:public TrackMode {
01041 public:
01042   NavigatorWasdMode();
01043   
01044         void Apply (Trackball * trackball, Point3f new_point);
01045 
01046   const char *Name () {
01047     return "NavigatorWasdMode";
01048   };
01049   //void SetAction();
01050   void Reset(); 
01051   //void Draw (Trackball * trackball);  
01052         
01053         bool isSticky();
01054         bool IsAnimating(const Trackball *tb);
01055         void Animate(unsigned int msec, Trackball *tb);
01056         void SetAction ();
01057         
01059         void FlipH(), FlipV(); // flips mouse controls
01060         
01061         void SetTopSpeedsAndAcc(float speed_h, float speed_v, float acc=0.0); // (top) speed is in units on sec
01062                              // Acc is in units on sec^2, if 0 then no-inertia
01063                              
01064         void SetStepOnWalk(float width, float height); // optionally, set step-on-walk effects
01065 
01066   void Apply (Trackball * trackball, float WheelNotch);
01067 
01068 private:
01069   float alpha, beta; //rotation in y and x axis
01070         Point3f current_speed;
01071         float step_current, step_last, step_x;
01072 
01073         int _flipH, _flipV;
01074         
01075         float accX, accY, accZ, dumping, topSpeedH, topSpeedV;
01076         float step_height, step_length; // height of steps
01077 };
01078 
01079 }//namespace 
01080 
01081 #endif


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