Debian Codegraph @

vcg/wrap/gui/trackball.h

raw symbols SCIP
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23 /****************************************************************************
24 History
25
26 $Log: trackball.h,v $
27 Revision 1.17 2007/12/21 12:29:34 tarini
28 *** empty log message ***
29
30 Revision 1.16 2007/07/14 12:43:44 benedetti
31 Added Doxygen documentation.
32
33 Revision 1.15 2007/06/13 17:15:08 benedetti
34 Added one-level undo system and sticky trackmodes.
35
36 Revision 1.14 2007/05/15 15:00:47 benedetti
37 Moved the drawing code to trackmodes, some other minor changes
38
39 Revision 1.13 2007/02/26 01:30:02 cignoni
40 Added reflection Name
41
42 Revision 1.12 2007/01/15 15:04:15 tarini
43 added "ToAscii" and "SetFromAscii" methods to load/store current trackball status from/to ascii strings
44 (intended uses: clipboard operations and comments inside png snapshots!)
45
46 Revision 1.11 2006/08/23 15:40:57 marfr960
47 *** empty log message ***
48
49 Revision 1.10 2006/02/13 13:15:52 cignoni
50 Added Scale and Translate methods.
51 Added many drawing hints and raised the default num. of steps when drawing circles.
52 Added MouseDown without coords (for remembering changes of keys modifiers)
53 Added ZMode to the default modes under Alt+left
54 Added DrawPostApply (to be completed)
55
56 Revision 1.9 2005/10/17 01:29:46 cignoni
57 Main restructuring. Removed the Draw function and slightly changed the meaning of the trackball itself.
58 See the notes at the beginning of trackball.h
59
60 Revision 1.8 2004/07/11 22:06:56 cignoni
61 Added scaling by wheel
62
63 Revision 1.7 2004/06/09 14:01:13 cignoni
64 Heavily restructured. To be completed only rotation works...
65
66 Revision 1.6 2004/05/14 03:15:09 ponchio
67 Redesigned partial version.
68
69 Revision 1.5 2004/05/12 20:55:18 ponchio
70 *** empty log message ***
71
72 Revision 1.4 2004/05/07 12:46:08 cignoni
73 Restructured and adapted in a better way to opengl
74
75 Revision 1.3 2004/04/07 10:54:10 cignoni
76 Commented out unused parameter names and other minor warning related issues
77
78 Revision 1.2 2004/03/25 14:55:25 ponchio
79 Adding copyright.
80
81
82 ****************************************************************************/
83 #ifndef TRACKBALL_H
84 #define TRACKBALL_Hcxx . . $ `vcg/wrap/gui/trackball.h:84:9`!
85
86 #include <vcg/math/similarity.h>cxx . . $ `<file>/vcg/vcg/math/similarity.h`/
87 #include <vcg/space/color4.h>cxx . . $ `<file>/vcg/vcg/space/color4.h`/
88 #include <wrap/gui/view.h>cxx . . $ `<file>/vcg/wrap/gui/view.h`/
89 #include <wrap/gui/trackmode.h>cxx . . $ `<file>/vcg/wrap/gui/trackmode.h`/
90 #include <list>
91 #include <vector>
92 #include <map>
93
94 namespace vcgcxx . . $ vcg/ {
95 /*!
96 @brief The base class for Trackball.
97
98 This class is useful for using a Trackball instance in a scene graph,
99 as a sort of interactive transform.
100 */
101 class Transformcxx . . $ vcg/Transform# {
102 public:
103 /*!
104 @brief The constructor.
105
106 Initialize:
107 - track to the identity transform.
108 - center to origin 0,0,0.
109 - radius to unit size.
110 */
111 Transformcxx . . $ vcg/Transform#Transform(49f6e7a06ebc5aa8).();
112 /// A trackball stores a transformation called 'track' that effectively rototranslate the object.
113 Similarityfcxx . . $ vcg/Similarityf# trackcxx . . $ vcg/Transform#track.;
114 /// track position in model space.
115 Point3fcxx . . $ vcg/Point3f# centercxx . . $ vcg/Transform#center.;
116 /// size of the widget in model space.
117 float radiuscxx . . $ vcg/Transform#radius.;
118 };
119
120 /*!
121 @brief Computes the linear interpolation between 2 transforms.
122
123 @param a The first transform.
124 @param b The second transform.
125 @param t The interpolation value (0: just a, 0.5: middle from a to b, 1: just b).
126 @return The linear interpolation.
127 */
128 Transformcxx . . $ vcg/Transform# interpolatecxx . . $ vcg/interpolate(754fd34742c2d32d).(const Transformcxx . . $ vcg/Transform# &a, const Transformcxx . . $ vcg/Transform# &b, float t);
129
130 class TrackModecxx . . $ vcg/TrackMode#;
131
132 /*!
133 @brief The manipulator manager system.
134
135 <em>Short usage note:</em>
136
137 - Center specify the center of rotation and scaling of the trackball and usually is set by the program and do not interactively change
138 - Radius specify the radius of the interactive ball shaped icon to specify rotation. It is in absolute unit.
139 - Like the previous one it is not changed during interaction.
140
141 When you specify a translation with the trackball the trackball center remain \b unchanged, in other words it means that the object move out of the trackball icon. Similarly when you apply a scaling the size of the manipulator icon do not change.
142
143 Typical use:
144 <pre>
145 glMatrixMode(GL_PROJECTION);
146 glLoadIdentity();
147 gluPerspective(60, float(width())/float(height()), 1, 100);
148 glMatrixMode(GL_MODELVIEW);
149 glLoadIdentity();
150 gluLookAt(0,0,3, 0,0,0, 0,1,0)
151
152 trackball.center=Point3f(0, 0, 0);
153 trackball.radius= 1;
154
155 trackball.GetView();
156 trackball.Apply(true); //false if you want an invisible trackball
157
158 float d=1.0f/mesh.bbox.Diag();
159 glScale(d);
160 glTranslate(-mesh.bbox.Center());
161 mesh->Render();
162 </pre>
163
164 Note on the typical use:
165 - Perspective and glulookat are choosed to frame the origin centered 1-radius trackball.
166 - The final scale and translate are just to fit a generic mesh to the 1sized origin centered where the trackball stays box.
167 - The trackball works also on Orthographic projections \b but that are not centered around origin (just move it back along the Z)
168 */
169 class Trackballcxx . . $ vcg/Trackball#: public Transformcxx . . $ vcg/Transform# {
170 public:
171 // the drawing code has been moved to the trackmodes
172 // class DrawingHint {
173
174 // DrawingHint DH;
175
176 /// The componibile states of the manipulator system.
177 enum Buttoncxx . . $ vcg/Trackball#Button# { BUTTON_NONEcxx . . $ vcg/Trackball#BUTTON_NONE. = 0x0000, ///< No mouse button pressed.
178 BUTTON_LEFTcxx . . $ vcg/Trackball#BUTTON_LEFT. = 0x0001, ///< Left mouse button pressed.
179 BUTTON_MIDDLEcxx . . $ vcg/Trackball#BUTTON_MIDDLE. = 0x0002, ///< Middle mouse button pressed.
180 BUTTON_RIGHTcxx . . $ vcg/Trackball#BUTTON_RIGHT. = 0x0004, ///< Right mouse button pressed.
181 WHEELcxx . . $ vcg/Trackball#WHEEL. = 0x0008, ///< Mouse wheel activated.
182 KEY_SHIFTcxx . . $ vcg/Trackball#KEY_SHIFT. = 0x0010, ///< Shift key pressed.
183 KEY_CTRLcxx . . $ vcg/Trackball#KEY_CTRL. = 0x0020, ///< Ctrl key pressed.
184 KEY_ALTcxx . . $ vcg/Trackball#KEY_ALT. = 0x0040, ///< Alt key pressed.
185 HANDLEcxx . . $ vcg/Trackball#HANDLE. = 0x0080 ///< Application-defined state activated.
186 };
187
188 /*!
189 @brief The constructor.
190
191 Initialize the internal state with default values
192 and call setDefaultMapping().
193 */
194 Trackballcxx . . $ vcg/Trackball#Trackball(49f6e7a06ebc5aa8).();
195 /*!
196 @brief The destructor.
197
198 @warning The destructor <b>does not</b> deallocate the memory allocated by setDefaultMapping(), because the application can change the modes map. This can lead to small memory leaks, so please explicitally delete any manipulator in the modes map if you are going to repeatly allocate and deallocate Trackball instances.
199 */
200 ~cxx . . $ vcg/Trackball#`~Trackball`(ced63f7c635d850d).Trackballcxx . . $ vcg/Trackball#();
201 /*!
202 @brief Reset the trackball.
203
204 Equivalent to Reset().
205 */
206 void SetIdentitycxx . . $ vcg/Trackball#SetIdentity(49f6e7a06ebc5aa8).();
207 /*!
208 @brief Set the position of the trackball.
209
210 @param c The new position of the trackball.
211 @param millisec Currently not in use.
212 */
213 void SetPositioncxx . . $ vcg/Trackball#SetPosition(c0b2a1bb3b4e9f55).(const Point3fcxx . . $ vcg/Point3f# &c, int millisec = 0);
214 /*!
215 @brief Currently not in use.
216
217 @param s Currently not in use.
218 */
219 void SetScalecxx . . $ vcg/Trackball#SetScale(9364e6e7bff7660).(const float s) {radiuscxx . . $ vcg/Transform#radius.=s;};
220 /*!
221 @brief Currently not in use.
222
223 @param transform Currently not in use.
224 @param millisec Currently not in use.
225 */
226 void SetTransformcxx . . $ vcg/Trackball#SetTransform(20a0984dbe6f447e).(const Transformcxx . . $ vcg/Transform# &transform, int millisec = 0);
227 /*!
228 @brief Apply a translation on the current transformation.
229
230 @param tr The translation vector.
231 */
232 void Translatecxx . . $ vcg/Trackball#Translate(8c9d966b9d6d20d).(Point3fcxx . . $ vcg/Point3f# tr);
233 /*!
234 @brief Apply a scaling on the current transformation.
235
236 @param f The scale factor.
237 */
238 void Scalecxx . . $ vcg/Trackball#Scale(9364e6e7bff7660).(const float f);
239
240 //operating
241 /*!
242 @brief Initialize the camera instance.
243 */
244 void GetViewcxx . . $ vcg/Trackball#GetView(49f6e7a06ebc5aa8).();
245 /*!
246 @brief Apply the current transformation on the OpenGL modelview matrix.
247
248 @param Draw true if has to call DrawPostApply() after the application.
249 */
250 void Applycxx . . $ vcg/Trackball#Apply(b45ddcbc8423892c).(bool Draw);
251 /*!
252 @brief Old application of the transformation.
253
254 @warning This function does \b not call DrawPostApply() after the application.
255 */
256 void Applycxx . . $ vcg/Trackball#Apply(49f6e7a06ebc5aa8). ();
257 /*!
258 @brief Draw the current manipulator.
259
260 Call the draw function of the current manipulator.
261 If no manipulator is selected call the draw function of the manipulator associated to inactive_mode.
262
263 @warning This function assumes that the OpenGL modelview matrix has been initialized with Apply ().
264 */
265 void DrawPostApplycxx . . $ vcg/Trackball#DrawPostApply(49f6e7a06ebc5aa8).();
266 /*!
267 @brief Apply the \b inverse of current transformation on the OpenGL modelview matrix.
268 */
269 void ApplyInversecxx . . $ vcg/Trackball#ApplyInverse(49f6e7a06ebc5aa8).();
270 // DrawIcon() has been moved to trackutils.h
271 //void DrawIcon();
272 /*!
273 @brief Reset the transformation and every mapped manipulator.
274 */
275 void Resetcxx . . $ vcg/Trackball#Reset(49f6e7a06ebc5aa8).();
276
277 // DrawCircle (), DrawPlane(), DrawPlaneHandle() has been moved to trackutils.h
278 // the drawing code has been moved to the trackmodes
279 // void DrawCircle ();
280 // void DrawPlane();
281 // void DrawPlaneHandle();
282
283 //interface
284 /*!
285 @brief Interface function relative to mouse down event in QT/SDL.
286
287 @param button The new state.
288 */
289 void MouseDowncxx . . $ vcg/Trackball#MouseDown(d4f767463ce0a6b3).(/*Button*/ int button);
290 /*!
291 @brief Interface function relative to mouse down event in QT/SDL.
292
293 @param x The horizontal coordinate of the mouse pointer.
294 @param y The vertical coordinate of the mouse pointer.
295 @param button The new state.
296 */
297 void MouseDowncxx . . $ vcg/Trackball#MouseDown(b1146eedae1e1d0b).(int x, int y, /*Button*/ int button);
298 /*!
299 @brief Interface function relative to mouse down event in QT/SDL.
300
301 @param x The horizontal coordinate of the mouse pointer.
302 @param y The vertical coordinate of the mouse pointer.
303 */
304 void MouseMovecxx . . $ vcg/Trackball#MouseMove(3e454b8ccf442868).(int x, int y);
305 /*!
306 @brief Interface function relative to mouse down event in QT/SDL.
307
308 @param x The horizontal coordinate of the mouse pointer.
309 @param y The vertical coordinate of the mouse pointer.
310 @param button The new state.
311 */
312 void MouseUpcxx . . $ vcg/Trackball#MouseUp(b1146eedae1e1d0b).(int x, int y, /*Button */ int button);
313 /*!
314 @brief Old interface function relative to mouse down event in QT/SDL.
315
316 @param notch The mouse wheel notch (1: one forward step, -1: one backward step).
317 */
318 void MouseWheelcxx . . $ vcg/Trackball#MouseWheel(9364e6e7bff7660).(float notch);
319 /*!
320 @brief Interface function relative to mouse down event in QT/SDL.
321
322 @param notch The mouse wheel notch (1: one forward step, -1: one backward step).
323 @param button The new state.
324 */
325 void MouseWheelcxx . . $ vcg/Trackball#MouseWheel(1746e8aa98ca1bc0). (float notch, /*Button */ int button);
326 /*!
327 @brief Interface function relative to key down event in QT/SDL.
328
329 @param button the new state.
330 */
331 void ButtonUpcxx . . $ vcg/Trackball#ButtonUp(8a427f6384c0f7e5).(Buttoncxx . . $ vcg/Trackball#Button# button);
332 /*!
333 @brief Interface function relative to key up event in QT/SDL.
334
335 @param button the new state.
336 */
337 void ButtonDowncxx . . $ vcg/Trackball#ButtonDown(8a427f6384c0f7e5).(Buttoncxx . . $ vcg/Trackball#Button# button);
338 /*!
339 @brief Undo function for manipulator system.
340
341 A call of this function restores the state before last user action.
342 This function calls %Undo() on every mapped manipulator.
343 */
344 void Undocxx . . $ vcg/Trackball#Undo(49f6e7a06ebc5aa8).();
345
346 //default sensitivity 1
347 /*!
348 @brief Currently not in use.
349
350 @param s Currently not in use.
351 */
352 void SetSensitivitycxx . . $ vcg/Trackball#SetSensitivity(9364e6e7bff7660).(float s);
353
354 //spinning interface
355 /*!
356 @brief Currently not in use.
357
358 @param on Currently not in use.
359 */
360 void SetSpinnablecxx . . $ vcg/Trackball#SetSpinnable(b45ddcbc8423892c).(bool on);
361 /*!
362 @brief Currently not in use.
363
364 @return A meaningless boolean value.
365 */
366 bool IsSpinnablecxx . . $ vcg/Trackball#IsSpinnable(c9857a73d68e59ba).();
367 /*!
368 @brief Currently not in use.
369
370 @param spin Currently not in use.
371 */
372 void SetSpinningcxx . . $ vcg/Trackball#SetSpinning(5feed1d272678cca).(Quaternionfcxx . . $ vcg/Quaternionf# &spin);
373 /*!
374 @brief Currently not in use.
375 */
376 void StopSpinningcxx . . $ vcg/Trackball#StopSpinning(49f6e7a06ebc5aa8).();
377 /*!
378 @brief Currently not in use.
379
380 @return A meaningless boolean value.
381 */
382 bool IsSpinningcxx . . $ vcg/Trackball#IsSpinning(c9857a73d68e59ba).();
383
384 //interfaccia navigation:
385 /*!
386 @brief Currently not in use.
387 */
388 void Backcxx . . $ vcg/Trackball#Back(49f6e7a06ebc5aa8).();
389 /*!
390 @brief Currently not in use.
391 */
392 void Forwardcxx . . $ vcg/Trackball#Forward(49f6e7a06ebc5aa8).();
393 /*!
394 @brief Currently not in use.
395 */
396 void Homecxx . . $ vcg/Trackball#Home(49f6e7a06ebc5aa8).();
397 /*!
398 @brief Currently not in use.
399 */
400 void Storecxx . . $ vcg/Trackball#Store(49f6e7a06ebc5aa8).();
401 /*!
402 @brief Currently not in use.
403 */
404 void HistorySizecxx . . $ vcg/Trackball#HistorySize(d4f767463ce0a6b3).(int lenght);
405
406 /* //internals // commented out no more used this stuff!
407 enum Action { NONE = 0,
408 VIEW_ROTATE = 1,
409 // Axis Constrained Rotation
410 TRACK_ROTATE_X = 3, TRACK_ROTATE_Y = 4, TRACK_ROTATE_Z = 5,
411 // Drag constrained to an axis (trackball axis)
412 DRAG_X = 6, DRAG_Y = 7, DRAG_Z = 8,
413 // Drag constrained to a plane
414 DRAG_XY = 9, DRAG_YZ = 10, DRAG_XZ = 11,
415 //scale model respect to center of trackball
416 VIEW_SCALE = 12,
417 //scale trackball and model
418 TRACK_SCALE = 13
419 };
420 */
421 // loads stores current status from/to ascii stings
422 /*!
423 @brief Stores current status into an ascii stings
424
425 Stores current status into an ascii stings. This is useful for example to implement cut-and-paste operations of trackball status, or to embed used trackball into a comment inside a screenshot, etc.
426 @param st The string where to export (must be allocated).
427 */
428 void ToAsciicxx . . $ vcg/Trackball#ToAscii(fda57c8427c60377).(char * st);
429 /*!
430 @brief Loads current status from an ascii stings
431
432 Loads current status from an ascii stings. This is useful for example to implement cut-and-paste operations of trackball status, or to embed used trackball into a comment inside a screenshot, etc.
433 @param st The string where to read from (must be allocated). Use ToAscii() method to set it.
434 @return True iff the trackball was successfully recovered.
435 */
436 bool SetFromAsciicxx . . $ vcg/Trackball#SetFromAscii(c5f7da30cbc0f4e9).(const char * st);
437
438 //protected:
439 /// The reference for point projection and unprojection from screen space to modelspace.
440 Viewcxx . . $ vcg/View#<float> cameracxx . . $ vcg/Trackball#camera.;
441 /*!
442 @brief Prepare Trackball and every mapped TrackMode for an user action.
443
444 This function is called automatically when an user action begins.
445 */
446 void SetCurrentActioncxx . . $ vcg/Trackball#SetCurrentAction(49f6e7a06ebc5aa8).();
447 /// Current state composition.
448 int current_buttoncxx . . $ vcg/Trackball#current_button.;
449 /// The selected manipulator.
450 TrackModecxx . . $ vcg/TrackMode# *current_modecxx . . $ vcg/Trackball#current_mode.;
451
452 /// The inactive manipulator. It is drawed when Trackball is inactive.
453 TrackModecxx . . $ vcg/TrackMode# *inactive_modecxx . . $ vcg/Trackball#inactive_mode.;
454
455 /*!
456 @brief Reset modes to default mapping.
457
458 Set the default modes mapping.
459 The default mapping is:
460 - \b LEFT : SphereMode.
461 - \b LEFT+CTRL or \b MIDDLE : PanMode.
462 - \b LEFT+SHIFT or \b WHEEL : ScaleMode.
463 - \b LEFT+ALT : ZMode.
464
465 @warning The memory allocated by this function <b>is not</b> automatically deallocated. see ~Trackball().
466 */
467 void setDefaultMappingcxx . . $ vcg/Trackball#setDefaultMapping(49f6e7a06ebc5aa8). ();
468
469 /// The manipulator mapping. Needs to be explicitally managed for custom mappings.
470 stdcxx . . $ std/::mapcxx . . $ std/map#<int, TrackModecxx . . $ vcg/TrackMode# *> modescxx . . $ vcg/Trackball#modes.;
471
472 // undo_track and last_track have different meanings..
473 /// Transformation before current user action.
474 Similarityfcxx . . $ vcg/Similarityf# last_trackcxx . . $ vcg/Trackball#last_track.;
475 /// track after an Undo() call.
476 Similarityfcxx . . $ vcg/Similarityf# undo_trackcxx . . $ vcg/Trackball#undo_track.;
477 /// Currently not in use.
478 Similarityfcxx . . $ vcg/Similarityf# last_viewcxx . . $ vcg/Trackball#last_view.;
479 /// Mouse cursor coordinates before current action.
480 Point3fcxx . . $ vcg/Point3f# last_pointcxx . . $ vcg/Trackball#last_point.;
481 /// Currently not in use.
482 stdcxx . . $ std/::vectorcxx . . $ std/vector#<Point3fcxx . . $ vcg/Point3f#> Hitscxx . . $ vcg/Trackball#Hits.;
483 /// Currently not in use.
484 bool draggingcxx . . $ vcg/Trackball#dragging.;
485 /// Currently not in use.
486 int button_maskcxx . . $ vcg/Trackball#button_mask.;
487
488 /// Currently not in use.
489 Quaternionfcxx . . $ vcg/Quaternionf# spincxx . . $ vcg/Trackball#spin.;
490 /// Currently not in use.
491 bool spinnablecxx . . $ vcg/Trackball#spinnable.;
492 /// Currently not in use.
493 bool spinningcxx . . $ vcg/Trackball#spinning.;
494
495 /// Currently not in use.
496 stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<Transformcxx . . $ vcg/Transform#> historycxx . . $ vcg/Trackball#history.;
497 /// Currently not in use.
498 int history_sizecxx . . $ vcg/Trackball#history_size.;
499
500 /// Manipulators needs full access to this class.
501 friend class TrackModecxx . . $ vcg/TrackMode#;
502 };
503
504
505 }//namespace
506
507 #endif