Go to the documentation of this file.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
00073
00074
00075
00076
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
00205 Trackball operator =(const Trackball & ){ 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
00250 void GetView();
00251
00258 void Apply ();
00259
00268 void DrawPostApply();
00269
00273 void ApplyInverse();
00274
00275
00276
00277
00278 Matrix44f Matrix() const;
00279 Matrix44f InverseMatrix() const;
00280
00284 void Reset();
00285
00289 void ClearModes();
00290
00291
00292
00293
00294
00295
00296
00297
00303 void MouseDown( int button);
00311 void MouseDown(int x, int y, int button);
00318 void MouseMove(int x, int y);
00326 void MouseUp(int x, int y, int button);
00332 void MouseWheel(float notch);
00339 void MouseWheel (float notch, int button);
00345 void ButtonUp(Button button);
00351 void ButtonDown(Button button, unsigned int msec=0);
00358 void Undo();
00359
00360
00366 void SetSensitivity(float s);
00367
00368 void SetSpinnable(bool on);
00369
00370
00371
00372
00373 bool IsAnimating(unsigned int msec=0);
00374
00375
00376
00377 void Animate(unsigned int msec=0);
00378
00384 bool IsSpinnable();
00390 void SetSpinning(Quaternionf &spin);
00394 void StopSpinning();
00400 bool IsSpinning();
00401
00402
00406 void Back();
00410 void Forward();
00414 void Home();
00418 void Store();
00422 void HistorySize(int lenght);
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00446 void ToAscii(char * st);
00454 bool SetFromAscii(const char * st);
00455
00456
00458 View<float> camera;
00464 void SetCurrentAction();
00466 int current_button;
00468 TrackMode *current_mode;
00469
00471 TrackMode *inactive_mode;
00472
00473
00474 TrackMode *idle_and_keys_mode;
00487 void setDefaultMapping ();
00488
00490 std::map<int, TrackMode *> modes;
00491
00492
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;
00532
00533 };
00534
00535
00536 }
00537
00538 #endif