109
109
myConstraint::constrainTranslation(Vec& v, Frame* const fr)
111
constraint1->constrainTranslation(v, fr);
112
constraint2->constrainTranslation(v, fr);
113
// and so on, with possible branches, tests, loops...
111
constraint1->constrainTranslation(v, fr);
112
constraint2->constrainTranslation(v, fr);
113
// and so on, with possible branches, tests, loops...
117
class QGLVIEWER_EXPORT Constraint
120
/*! Virtual destructor. Empty. */
121
virtual ~Constraint() {};
123
/*! Filters the translation applied to the \p frame. This default implementation is empty (no
126
Overload this method in your own Constraint class to define a new translation constraint. \p
127
frame is the Frame to which is applied the translation. It is not defined \c const, but you
128
should refrain from directly changing its value in the constraint. Use its Frame::position() and
129
update the \p translation accordingly instead.
131
\p translation is expressed in local frame coordinate system. Use Frame::inverseTransformOf() to
132
express it in the world coordinate system if needed. */
133
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); };
134
/*! Filters the rotation applied to the \p frame. This default implementation is empty (no
137
Overload this method in your own Constraint class to define a new rotation constraint. See
138
constrainTranslation() for details.
140
Use Frame::inverseTransformOf() on the \p rotation Quaternion::axis() to express \p rotation in
141
the world coordinate system if needed. */
142
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); };
117
class QGLVIEWER_EXPORT Constraint
120
/*! Virtual destructor. Empty. */
121
virtual ~Constraint() {}
123
/*! Filters the translation applied to the \p frame. This default implementation is empty (no
126
Overload this method in your own Constraint class to define a new translation constraint. \p
127
frame is the Frame to which is applied the translation. It is not defined \c const, but you
128
should refrain from directly changing its value in the constraint. Use its Frame::position() and
129
update the \p translation accordingly instead.
131
\p translation is expressed in local frame coordinate system. Use Frame::inverseTransformOf() to
132
express it in the world coordinate system if needed. */
133
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); }
134
/*! Filters the rotation applied to the \p frame. This default implementation is empty (no
137
Overload this method in your own Constraint class to define a new rotation constraint. See
138
constrainTranslation() for details.
140
Use Frame::inverseTransformOf() on the \p rotation Quaternion::axis() to express \p rotation in
141
the world coordinate system if needed. */
142
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); }
146
146
\brief An abstract class for Frame Constraints defined by an axis or a plane.
147
147
\class AxisPlaneConstraint constraint.h QGLViewer/constraint.h
165
165
However, adding an extra pointer to the QGLViewer::camera() in all the AxisPlaneConstraint
166
166
derived classes (which the user would have to update in a multi-viewer application) was judged as
168
class QGLVIEWER_EXPORT AxisPlaneConstraint : public Constraint
171
AxisPlaneConstraint();
172
/*! Virtual destructor. Empty. */
173
virtual ~AxisPlaneConstraint() {};
175
/*! Type lists the different types of translation and rotation constraints that are available.
177
It specifies the meaning of the constraint direction (see translationConstraintDirection() and
178
rotationConstraintDirection()): as an axis direction (AxisPlaneConstraint::AXIS) or a plane
179
normal (AxisPlaneConstraint::PLANE). AxisPlaneConstraint::FREE means no constraint while
180
AxisPlaneConstraint::FORBIDDEN completely forbids the translation and/or the rotation.
182
See translationConstraintType() and rotationConstraintType().
184
\attention The AxisPlaneConstraint::PLANE Type is not valid for rotational constraint.
186
New derived classes can use their own extended enum for specific constraints:
188
class MyAxisPlaneConstraint : public AxisPlaneConstraint
191
enum MyType { FREE, AXIS, PLANE, FORBIDDEN, CUSTOM };
192
virtual void constrainTranslation(Vec &translation, Frame *const frame)
194
// translationConstraintType() is simply an int. CUSTOM Type is handled seamlessly.
195
switch (translationConstraintType())
168
class QGLVIEWER_EXPORT AxisPlaneConstraint : public Constraint
171
AxisPlaneConstraint();
172
/*! Virtual destructor. Empty. */
173
virtual ~AxisPlaneConstraint() {}
175
/*! Type lists the different types of translation and rotation constraints that are available.
177
It specifies the meaning of the constraint direction (see translationConstraintDirection() and
178
rotationConstraintDirection()): as an axis direction (AxisPlaneConstraint::AXIS) or a plane
179
normal (AxisPlaneConstraint::PLANE). AxisPlaneConstraint::FREE means no constraint while
180
AxisPlaneConstraint::FORBIDDEN completely forbids the translation and/or the rotation.
182
See translationConstraintType() and rotationConstraintType().
184
\attention The AxisPlaneConstraint::PLANE Type is not valid for rotational constraint.
186
New derived classes can use their own extended enum for specific constraints:
188
class MyAxisPlaneConstraint : public AxisPlaneConstraint
197
case MyAxisPlaneConstraint::FREE: ... break;
198
case MyAxisPlaneConstraint::CUSTOM: ... break;
202
MyAxisPlaneConstraint* c = new MyAxisPlaneConstraint();
203
// Note the Type conversion
204
c->setTranslationConstraintType(AxisPlaneConstraint::Type(MyAxisPlaneConstraint::CUSTOM));
207
enum Type { FREE, AXIS, PLANE, FORBIDDEN };
209
/*! @name Translation constraint */
211
/*! Overloading of Constraint::constrainTranslation(). Empty */
212
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); };
214
void setTranslationConstraint(Type type, const Vec& direction);
215
/*! Sets the Type() of the translationConstraintType(). Default is AxisPlaneConstraint::FREE. */
216
void setTranslationConstraintType(Type type) { translationConstraintType_ = type; };
217
void setTranslationConstraintDirection(const Vec& direction);
219
/*! Returns the translation constraint Type().
221
Depending on this value, the Frame will freely translate (AxisPlaneConstraint::FREE), will only
222
be able to translate along an axis direction (AxisPlaneConstraint::AXIS), will be forced to stay
223
into a plane (AxisPlaneConstraint::PLANE) or will not able to translate at all
224
(AxisPlaneConstraint::FORBIDDEN).
226
Use Frame::setPosition() to define the position of the constrained Frame before it gets
228
Type translationConstraintType() const { return translationConstraintType_; };
229
/*! Returns the direction used by the translation constraint.
231
It represents the axis direction (AxisPlaneConstraint::AXIS) or the plane normal
232
(AxisPlaneConstraint::PLANE) depending on the translationConstraintType(). It is undefined for
233
AxisPlaneConstraint::FREE or AxisPlaneConstraint::FORBIDDEN.
235
The AxisPlaneConstraint derived classes express this direction in different coordinate system
236
(camera for CameraConstraint, local for LocalConstraint, and world for WorldConstraint). This
237
value can be modified with setTranslationConstraintDirection(). */
238
Vec translationConstraintDirection() const { return translationConstraintDir_; };
241
/*! @name Rotation constraint */
243
/*! Overloading of Constraint::constrainRotation(). Empty. */
244
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); };
246
void setRotationConstraint(Type type, const Vec& direction);
247
void setRotationConstraintType(Type type);
248
void setRotationConstraintDirection(const Vec& direction);
250
/*! Returns the rotation constraint Type(). */
251
Type rotationConstraintType() const { return rotationConstraintType_; };
252
/*! Returns the axis direction used by the rotation constraint.
254
This direction is defined only when rotationConstraintType() is AxisPlaneConstraint::AXIS.
256
The AxisPlaneConstraint derived classes express this direction in different coordinate system
257
(camera for CameraConstraint, local for LocalConstraint, and world for WorldConstraint). This
258
value can be modified with setRotationConstraintDirection(). */
259
Vec rotationConstraintDirection() const { return rotationConstraintDir_; };
263
// int and not Type to allow for overloading and new types definition.
264
Type translationConstraintType_;
265
Type rotationConstraintType_;
267
Vec translationConstraintDir_;
268
Vec rotationConstraintDir_;
272
/*! \brief An AxisPlaneConstraint defined in the Frame local coordinate system.
191
enum MyType { FREE, AXIS, PLANE, FORBIDDEN, CUSTOM };
192
virtual void constrainTranslation(Vec &translation, Frame *const frame)
194
// translationConstraintType() is simply an int. CUSTOM Type is handled seamlessly.
195
switch (translationConstraintType())
197
case MyAxisPlaneConstraint::FREE: ... break;
198
case MyAxisPlaneConstraint::CUSTOM: ... break;
202
MyAxisPlaneConstraint* c = new MyAxisPlaneConstraint();
203
// Note the Type conversion
204
c->setTranslationConstraintType(AxisPlaneConstraint::Type(MyAxisPlaneConstraint::CUSTOM));
207
enum Type { FREE, AXIS, PLANE, FORBIDDEN };
209
/*! @name Translation constraint */
211
/*! Overloading of Constraint::constrainTranslation(). Empty */
212
virtual void constrainTranslation(Vec& translation, Frame* const frame) { Q_UNUSED(translation); Q_UNUSED(frame); };
214
void setTranslationConstraint(Type type, const Vec& direction);
215
/*! Sets the Type() of the translationConstraintType(). Default is AxisPlaneConstraint::FREE. */
216
void setTranslationConstraintType(Type type) { translationConstraintType_ = type; };
217
void setTranslationConstraintDirection(const Vec& direction);
219
/*! Returns the translation constraint Type().
221
Depending on this value, the Frame will freely translate (AxisPlaneConstraint::FREE), will only
222
be able to translate along an axis direction (AxisPlaneConstraint::AXIS), will be forced to stay
223
into a plane (AxisPlaneConstraint::PLANE) or will not able to translate at all
224
(AxisPlaneConstraint::FORBIDDEN).
226
Use Frame::setPosition() to define the position of the constrained Frame before it gets
228
Type translationConstraintType() const { return translationConstraintType_; };
229
/*! Returns the direction used by the translation constraint.
231
It represents the axis direction (AxisPlaneConstraint::AXIS) or the plane normal
232
(AxisPlaneConstraint::PLANE) depending on the translationConstraintType(). It is undefined for
233
AxisPlaneConstraint::FREE or AxisPlaneConstraint::FORBIDDEN.
235
The AxisPlaneConstraint derived classes express this direction in different coordinate system
236
(camera for CameraConstraint, local for LocalConstraint, and world for WorldConstraint). This
237
value can be modified with setTranslationConstraintDirection(). */
238
Vec translationConstraintDirection() const { return translationConstraintDir_; };
241
/*! @name Rotation constraint */
243
/*! Overloading of Constraint::constrainRotation(). Empty. */
244
virtual void constrainRotation(Quaternion& rotation, Frame* const frame) { Q_UNUSED(rotation); Q_UNUSED(frame); };
246
void setRotationConstraint(Type type, const Vec& direction);
247
void setRotationConstraintType(Type type);
248
void setRotationConstraintDirection(const Vec& direction);
250
/*! Returns the rotation constraint Type(). */
251
Type rotationConstraintType() const { return rotationConstraintType_; };
252
/*! Returns the axis direction used by the rotation constraint.
254
This direction is defined only when rotationConstraintType() is AxisPlaneConstraint::AXIS.
256
The AxisPlaneConstraint derived classes express this direction in different coordinate system
257
(camera for CameraConstraint, local for LocalConstraint, and world for WorldConstraint). This
258
value can be modified with setRotationConstraintDirection(). */
259
Vec rotationConstraintDirection() const { return rotationConstraintDir_; };
263
// int and not Type to allow for overloading and new types definition.
264
Type translationConstraintType_;
265
Type rotationConstraintType_;
267
Vec translationConstraintDir_;
268
Vec rotationConstraintDir_;
272
/*! \brief An AxisPlaneConstraint defined in the Frame local coordinate system.
273
273
\class LocalConstraint constraint.h QGLViewer/constraint.h
275
275
The translationConstraintDirection() and rotationConstraintDirection() are expressed in the Frame
276
276
local coordinate system (see Frame::referenceFrame()).
278
278
See the <a href="../examples/constrainedFrame.html">constrainedFrame</a> example for an illustration. */
279
class QGLVIEWER_EXPORT LocalConstraint : public AxisPlaneConstraint
282
/*! Virtual destructor. Empty. */
283
virtual ~LocalConstraint() {};
285
virtual void constrainTranslation(Vec& translation, Frame* const frame);
286
virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
291
/*! \brief An AxisPlaneConstraint defined in the world coordinate system.
292
\class WorldConstraint constraint.h QGLViewer/constraint.h
279
class QGLVIEWER_EXPORT LocalConstraint : public AxisPlaneConstraint
282
/*! Virtual destructor. Empty. */
283
virtual ~LocalConstraint() {};
285
virtual void constrainTranslation(Vec& translation, Frame* const frame);
286
virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
291
/*! \brief An AxisPlaneConstraint defined in the world coordinate system.
292
\class WorldConstraint constraint.h QGLViewer/constraint.h
294
294
The translationConstraintDirection() and rotationConstraintDirection() are expressed in world
295
295
coordinate system.
297
297
See the <a href="../examples/constrainedFrame.html">constrainedFrame</a> and <a
298
298
href="../examples/multiView.html">multiView</a> examples for an illustration. */
299
class QGLVIEWER_EXPORT WorldConstraint : public AxisPlaneConstraint
302
/*! Virtual destructor. Empty. */
303
virtual ~WorldConstraint() {};
305
virtual void constrainTranslation(Vec& translation, Frame* const frame);
306
virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
311
/*! \brief An AxisPlaneConstraint defined in the camera coordinate system.
299
class QGLVIEWER_EXPORT WorldConstraint : public AxisPlaneConstraint
302
/*! Virtual destructor. Empty. */
303
virtual ~WorldConstraint() {};
305
virtual void constrainTranslation(Vec& translation, Frame* const frame);
306
virtual void constrainRotation (Quaternion& rotation, Frame* const frame);
311
/*! \brief An AxisPlaneConstraint defined in the camera coordinate system.
312
312
\class CameraConstraint constraint.h QGLViewer/constraint.h
314
314
The translationConstraintDirection() and rotationConstraintDirection() are expressed in the