Constraint Class Reference

A base abstract class for Frame constraints. More...

#include <constraint.h>

Inherited by AxisPlaneConstraint.

List of all members.

Public Member Functions

virtual ~Constraint ()
virtual void constrainTranslation (Vec &, Frame *const)
virtual void constrainRotation (Quaternion &, Frame *const)


Detailed Description

A base abstract class for Frame constraints.

The different constraints that can be applied to a Frame to limit its motion must all derive from this class. A Frame can have its constraint defined with Frame::setConstraint().

constrainTranslation() and constrainRotation() can be overloaded to specify the constraint behavior. They take the desired displacement (translation or rotation) and the applied frame as parameters. The translation (resp. rotation) is then modified according to the constraint.

The Frame::translate() and Frame::rotate() functions filter their input with the current Frame constraint (if any):

Frame::translate(Vec& T) { if (constraint()) constraint()->constrainTranslation(T, this); t += T; } Frame::rotate(Quaternion& Q) { if (constraint()) constraint()->constrainRotation(Q, this); q *= Q; }

Default behavior (Constraint base class) implements no constraint : constrainTranslation() and constrainRotation() are identity functions.

Try the constrainedFrame and constrainedCamera examples for an illustration.

Implemented constraints

Classical constraints are provided for convenience : see the LocalConstraint, WorldConstraint and CameraConstraint classes for axial and plane constraints. The TriangleSetConstraint is very useful for walk through applications, in order to force the camera to remain on a given path.

Defining new constraints

The implementation of a new Constraint class simply consists in overloading the filtering functions:

class myConstraint : public Constraint { public: virtual void constrainTranslation(Vec& t, Frame * const fr) { // The frame cannot have a negative z world coordinate. if (fr->position().z + t.z < 0.0) // check the new fr z coordinate t.z = -fr->position().z; // t.z is clamped so that next z position is 0.0 } }; myFrame->setConstraint(new myConstraint());

Combining constraints

Combining constraints can easily be achieved by creating a new class that will apply the different constraint filters:

myConstraint::constrainTranslation(Vec& v, Frame* const fr) { const1->constrainTranslation(v, fr); const2->constrainTranslation(v, fr); // and so on, with possible branches, tests, loops... }
Much more complex constraint composition classes can be created in the same way.

Attention:
Frame::setTranslation(), Frame::setRotation() and similar functions will actually set the frame position and orientation, without taking the constraint into consideration. Use the WithConstraint versions of these functions to enforce the constraint.


Constructor & Destructor Documentation

virtual ~Constraint  )  [inline, virtual]
 

Virtual empty destructor.


Member Function Documentation

virtual void constrainRotation Quaternion ,
Frame const
[inline, virtual]
 

Default un-constrained rotation function. Desired rotation is expressed in local frame coordinate system.

Overload this function in your own Constraint class to define a new rotational constraint. The frame which is applied a constrained rotation is given as a parameter. It is not defined const, but you should refrain from directly changing its value in the constraint.

Reimplemented in AxisPlaneConstraint, LocalConstraint, WorldConstraint, and CameraConstraint.

virtual void constrainTranslation Vec ,
Frame const
[inline, virtual]
 

Default un-constrained translation function. Desired translation is expressed in local frame coordinate system.

Overload this function in your own Constraint class to define a new translation constraint. The frame which is applied a constrained translation is given as a parameter. It is not defined const, but you should refrain from directly changing its value in the constraint.

Reimplemented in AxisPlaneConstraint, LocalConstraint, WorldConstraint, and CameraConstraint.


Generated on Wed Dec 1 12:41:26 2004 for libQGLViewer by doxygen 1.3.7