Inherited by AxisPlaneConstraint, and TriangleSetConstraint.
Public Member Functions | |
virtual | ~Constraint () |
virtual void | constrainTranslation (Vec &, Frame *const) |
virtual void | constrainRotation (Quaternion &, Frame *const) |
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 constrain 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.
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.
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) // new fr z coordinate t.z = fr->position().z; // t.z is clamped } }; myFrame->setConstraint(new myConstraint());
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... }
|
Virtual empty destructor. |
|
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 Reimplemented in AxisPlaneConstraint, LocalConstraint, WorldConstraint, and CameraConstraint. |
|
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 Reimplemented in AxisPlaneConstraint, LocalConstraint, WorldConstraint, CameraConstraint, and TriangleSetConstraint. |