00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
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
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
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
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
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
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
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
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
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
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
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 unsigned int undo_path_index;
01018
01019 };
01020
01021
01022
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;
01037 float enda, endb;
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
01050 void Reset();
01051
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();
01060
01061 void SetTopSpeedsAndAcc(float speed_h, float speed_v, float acc=0.0);
01062
01063
01064 void SetStepOnWalk(float width, float height);
01065
01066 void Apply (Trackball * trackball, float WheelNotch);
01067
01068 private:
01069 float alpha, beta;
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;
01077 };
01078
01079 }
01080
01081 #endif