Developer Documentation
TranslationManipulatorNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // CLASS TranslationManipulatorNode
50 //
51 //=============================================================================
52 
53 
54 #ifndef ACG_TRANSLATIONMANIPULATOR_NODE_HH
55 #define ACG_TRANSLATIONMANIPULATOR_NODE_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 // GMU
61 #include "BaseNode.hh"
62 #include "TransformNode.hh"
63 
64 // Qt
65 #include <QEvent>
66 #include <QMouseEvent>
67 
68 
69 
70 
71 //== NAMESPACES ===============================================================
72 
73 namespace ACG {
74 
75 class GLCone;
76 class GLDisk;
77 class GLSphere;
78 
79 
80 namespace SceneGraph {
81 
82 //== CLASS DEFINITION =========================================================
83 
84 
89 class ACGDLLEXPORT TranslationManipulatorNode : public TransformNode
90 {
91 public:
92 
93  enum AutoSizeMode {
94  Never,
95  Once,
96  Always
97  };
98 
108  Rotation,
109  TranslationRotation,
110  LocalRotation,
111  Resize,
112  Place
113  };
114 
121  X_AXIS = 1,
122  Y_AXIS = 1 << 1,
123  Z_AXIS = 1 << 2,
124  ALL_AXIS = X_AXIS | Y_AXIS | Z_AXIS
125  };
126 
129  const std::string& _name="<TranslationTranslationManipulatorNode>" );
130 
133 
134 
136  ACG_CLASSNAME(TranslationManipulatorNode);
137 
138 
139  //
140  // METHODS
141  //
142 
143  virtual void setIdentity() override;
144 
146  void set_draw_cylinder(bool _b) { draw_manipulator_ = _b; }
147 
149  bool draw_manipulator() const { return draw_manipulator_; }
150 
152  void set_direction(const Vec3d& _directionX, const Vec3d& _directionY);
153 
155  Vec3d directionX() const;
157  Vec3d directionY() const;
159  Vec3d directionZ() const;
160 
162  void set_size( double _size) {
163  if (_size > 0.0)
164  {
165  set_manipulator_height_ = _size;
166  set_manipulator_radius_ = _size/10.0;
167  setDirty ();
168  }
169  }
170 
172  double size() const { return set_manipulator_height_; }
173 
175  void set_autosize (AutoSizeMode _mode) { auto_size_ = _mode; }
176 
178  AutoSizeMode autosize () const { return auto_size_; }
179 
188  activeRotations_ = _active;
189  }
190 
197  return activeRotations_;
198  }
199 
200  void rotate (double _angle, Vec3d _axis)
201  {
202  TransformNode::rotate(_angle, _axis);
203  }
204 
206  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
207 
209  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat) override;
210 
212  GLMatrixd computeWorldMatrix();
213 
215  // void leave(GLState& _state, const DrawModes::DrawMode& _drawMode);
216 
218  void pick(GLState& _state, PickTarget _target) override;
219 
221  virtual void mouseEvent(GLState& _state, QMouseEvent* _event) override;
222 
224  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
225 
227  void setMode (ManipulatorMode _mode);
228 
230  ManipulatorMode getMode () const { return mode_; };
231 
232 
233 protected:
235  bool touched_;
236 
237 private:
238 
239  enum StateUpdates {
240  None,
241  Over,
242  Click
243  };
244 
245  enum Elements {
246  Origin = 0,
247  XTop,
248  YTop,
249  ZTop,
250  XAxis,
251  YAxis,
252  ZAxis,
253  XRing,
254  YRing,
255  ZRing,
256  NumElements
257  };
258 
259  class Element {
260  public:
261  Element ();
262 
263  Vec4f active_target_color_;
264  Vec4f active_current_color_;
265  Vec4f inactive_target_color_;
266  Vec4f inactive_current_color_;
267 
268  bool clicked_;
269  bool over_;
270  };
271 
273  void update_manipulator_system(GLState& _state);
274 
276  void update_rotation(GLState& _state);
277 
278  bool hitSphere(GLState& _state, const Vec2i& _v2);
279  bool hitOuterSphere(GLState& _state, const Vec2i& _v2);
280 
281  void drawManipulator (GLState& _state, bool _active);
282 
283  void addManipulatorToRenderer (IRenderer* _renderer, RenderObject* _baseRO, bool _active);
284  void addAxisToRenderer (IRenderer* _renderer, RenderObject* _baseRO, bool _active, int _axis);
285 
286 
287  bool mapToCylinder (GLState& _state, const Vec2i& _v2, StateUpdates _updateStates = None);
288  bool mapToCylinderTop (GLState& _state, const Vec2i& _v2, StateUpdates _updateStates = None);
289 
290  bool mapToSphere (GLState& _state, const Vec2i& _v2, Vec3d& _v3, StateUpdates _updateStates = None);
291 
292  void updateTargetColors ();
293  bool updateCurrentColors (GLState& _state);
294 
295  double get_screen_length (GLState& _state, Vec3d& _point) const;
296 
297  void updateSize (GLState& _state);
298 
299  // ELEMENTS
300  bool draw_manipulator_;
301 
302  Vec3d dirX_;
303  Vec3d dirY_;
304  Vec3d dirZ_;
305 
306  ACG::GLCone* axisBottom_; // axis split up for deferred draw call rendering,
307  ACG::GLCone* axisCenter_; // cone vbo data must be consistent within one frame
308  ACG::GLCone* axisTop_;
309  ACG::GLDisk* circle_;
310  ACG::GLSphere* sphere_;
311 
312  double manipulator_radius_;
313  double manipulator_height_;
314  double set_manipulator_radius_;
315  double set_manipulator_height_;
316  int manipulator_slices_;
317  int manipulator_stacks_;
318 
319  bool any_axis_clicked_;
320  bool any_top_clicked_;
321  bool outer_ring_clicked_;
322 
323  bool any_axis_over_;
324  bool any_top_over_;
325  bool outer_ring_over_;
326 
327 
328  Element element_[NumElements];
329  float resize_current_;
330 
331  ManipulatorMode mode_;
332  bool ignoreTime_;
333 
334  Vec2i oldPoint2D_;
335  Vec3d draggingOrigin3D_;
336  bool dragging_;
337 
338  Vec3d currentScale_;
339 
340  GLMatrixd localTransformation_;
341 
342  AutoSizeMode auto_size_;
343  double auto_size_length_;
344 
345  ActiveRotations activeRotations_;
346 };
347 
348 
349 //=============================================================================
350 } // namespace SceneGraph
351 } // namespace ACG
352 //=============================================================================
353 #endif // ACG_TRANSLATIONMANIPULATOR_NODE_HH defined
354 //=============================================================================
355 
void enable_rotations(ActiveRotations _active)
Enable or disable manipulator handles for specific orientations.
Namespace providing different geometric functions concerning angles.
ActiveRotations
enum to define which rotation axis should be enabled
void set_autosize(AutoSizeMode _mode)
set auto size mode
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
ActiveRotations enabled_rotations() const
Get the current setting, which rotation handles are active.
ManipulatorMode
enum to define the manipulator mode
AutoSizeMode autosize() const
get autosize mode
void rotate(double _angle, const Vec3d &_axis)
void set_size(double _size)
set cylindersize (height + radius). _size parameter has to be greater than zero
bool touched_
stores if this manipulator was used in order to avoid emitting manipulatorMoved unnecessarily ...
Clear all attribute bits.
Definition: Attributes.hh:81
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98