constraint.h
1 /****************************************************************************
2 
3  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.5.2.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef QGLVIEWER_CONSTRAINT_H
24 #define QGLVIEWER_CONSTRAINT_H
25 
26 #include "vec.h"
27 #include "quaternion.h"
28 
29 namespace qglviewer {
30 class Frame;
31 class Camera;
32 
117 class QGLVIEWER_EXPORT Constraint
118 {
119 public:
121  virtual ~Constraint() {}
122 
133  virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
142  virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
143 };
144 
168 class QGLVIEWER_EXPORT AxisPlaneConstraint : public Constraint
169 {
170 public:
173  virtual ~AxisPlaneConstraint() {}
174 
207  enum Type { FREE, AXIS, PLANE, FORBIDDEN };
208 
212  virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); };
213 
214  void setTranslationConstraint(Type type, const Vec& direction);
216  void setTranslationConstraintType(Type type) { translationConstraintType_ = type; };
217  void setTranslationConstraintDirection(const Vec& direction);
218 
228  Type translationConstraintType() const { return translationConstraintType_; };
238  Vec translationConstraintDirection() const { return translationConstraintDir_; };
240 
244  virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); };
245 
246  void setRotationConstraint(Type type, const Vec& direction);
247  void setRotationConstraintType(Type type);
248  void setRotationConstraintDirection(const Vec& direction);
249 
251  Type rotationConstraintType() const { return rotationConstraintType_; };
259  Vec rotationConstraintDirection() const { return rotationConstraintDir_; };
261 
262 private:
263  // int and not Type to allow for overloading and new types definition.
264  Type translationConstraintType_;
265  Type rotationConstraintType_;
266 
267  Vec translationConstraintDir_;
268  Vec rotationConstraintDir_;
269 };
270 
271 
279 class QGLVIEWER_EXPORT LocalConstraint : public AxisPlaneConstraint
280 {
281 public:
283  virtual ~LocalConstraint() {};
284 
285  virtual void constrainTranslation(Vec& translation, Frame* const frame);
286  virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
287 };
288 
289 
290 
299 class QGLVIEWER_EXPORT WorldConstraint : public AxisPlaneConstraint
300 {
301 public:
303  virtual ~WorldConstraint() {};
304 
305  virtual void constrainTranslation(Vec& translation, Frame* const frame);
306  virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
307 };
308 
309 
310 
319 class QGLVIEWER_EXPORT CameraConstraint : public AxisPlaneConstraint
320 {
321 public:
322  explicit CameraConstraint(const Camera* const camera);
324  virtual ~CameraConstraint() {};
325 
326  virtual void constrainTranslation(Vec& translation, Frame* const frame);
327  virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
328 
330  const Camera* camera() const { return camera_; };
331 
332 private:
333  const Camera* const camera_;
334 };
335 
336 } // namespace qglviewer
337 
338 #endif // QGLVIEWER_CONSTRAINT_H
virtual void constrainRotation(Quaternion &rotation, Frame *const frame)
Overloading of Constraint::constrainRotation().
Definition: constraint.h:244
virtual void constrainTranslation(Vec &translation, Frame *const frame)
Overloading of Constraint::constrainTranslation().
Definition: constraint.h:212
Type translationConstraintType() const
Returns the translation constraint Type().
Definition: constraint.h:228
Type rotationConstraintType() const
Returns the rotation constraint Type().
Definition: constraint.h:251
virtual ~Constraint()
Virtual destructor.
Definition: constraint.h:121
An abstract class for Frame Constraints defined by an axis or a plane.
Definition: constraint.h:168
virtual ~AxisPlaneConstraint()
Virtual destructor.
Definition: constraint.h:173
An AxisPlaneConstraint defined in the Frame local coordinate system.
Definition: constraint.h:279
const Camera * camera() const
Returns the associated Camera.
Definition: constraint.h:330
virtual ~CameraConstraint()
Virtual destructor.
Definition: constraint.h:324
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:65
virtual ~LocalConstraint()
Virtual destructor.
Definition: constraint.h:283
void setTranslationConstraintType(Type type)
Sets the Type() of the translationConstraintType().
Definition: constraint.h:216
Vec rotationConstraintDirection() const
Returns the axis direction used by the rotation constraint.
Definition: constraint.h:259
A perspective or orthographic camera.
Definition: camera.h:84
The Quaternion class represents 3D rotations and orientations.
Definition: quaternion.h:66
virtual void constrainRotation(Quaternion &rotation, Frame *const frame)
Filters the rotation applied to the frame.
Definition: constraint.h:142
Vec translationConstraintDirection() const
Returns the direction used by the translation constraint.
Definition: constraint.h:238
virtual ~WorldConstraint()
Virtual destructor.
Definition: constraint.h:303
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:121
virtual void constrainTranslation(Vec &translation, Frame *const frame)
Filters the translation applied to the frame.
Definition: constraint.h:133
An AxisPlaneConstraint defined in the world coordinate system.
Definition: constraint.h:299
An interface class for Frame constraints.
Definition: constraint.h:117
Type
Type lists the different types of translation and rotation constraints that are available.
Definition: constraint.h:207
An AxisPlaneConstraint defined in the camera coordinate system.
Definition: constraint.h:319