constraint.h
1 /****************************************************************************
2 
3  Copyright (C) 2002-2008 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.3.10.
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