AxisPlaneConstraint Class Reference

An abstract class for Frame Constraints defined by an axis or a plane. More...

Inheritance diagram for AxisPlaneConstraint:

Public Types

enum  Type { FREE, AXIS, PLANE, FORBIDDEN }
 Type lists the different types of translation and rotation constraints that are available. More...
 

Public Member Functions

 AxisPlaneConstraint ()
 Default constructor.
 
virtual ~AxisPlaneConstraint ()
 Virtual destructor.
 
Translation constraint
virtual void constrainTranslation (Vec &translation, Frame *const frame)
 Overloading of Constraint::constrainTranslation().
 
void setTranslationConstraint (Type type, const Vec &direction)
 Simply calls setTranslationConstraintType() and setTranslationConstraintDirection().
 
void setTranslationConstraintType (Type type)
 Sets the Type() of the translationConstraintType().
 
void setTranslationConstraintDirection (const Vec &direction)
 Defines the translationConstraintDirection().
 
Type translationConstraintType () const
 Returns the translation constraint Type().
 
Vec translationConstraintDirection () const
 Returns the direction used by the translation constraint.
 
Rotation constraint
virtual void constrainRotation (Quaternion &rotation, Frame *const frame)
 Overloading of Constraint::constrainRotation().
 
void setRotationConstraint (Type type, const Vec &direction)
 Simply calls setRotationConstraintType() and setRotationConstraintDirection().
 
void setRotationConstraintType (Type type)
 Set the Type() of the rotationConstraintType().
 
void setRotationConstraintDirection (const Vec &direction)
 Defines the rotationConstraintDirection().
 
Type rotationConstraintType () const
 Returns the rotation constraint Type().
 
Vec rotationConstraintDirection () const
 Returns the axis direction used by the rotation constraint.
 
- Public Member Functions inherited from Constraint
virtual ~Constraint ()
 Virtual destructor.
 

Detailed Description

An abstract class for Frame Constraints defined by an axis or a plane.

AxisPlaneConstraint is an interface for (translation and/or rotation) Constraint that are defined by a direction. translationConstraintType() and rotationConstraintType() define how this direction should be interpreted: as an axis (AxisPlaneConstraint::AXIS) or as a plane normal (AxisPlaneConstraint::PLANE). See the Type() documentation for details.

The three implementations of this class: LocalConstraint, WorldConstraint and CameraConstraint differ by the coordinate system in which this direction is expressed.

Different implementations of this class are illustrated in the contrainedCamera and constrainedFrame examples.

Attention
When applied, the rotational Constraint may not intuitively follow the mouse displacement. A solution would be to directly measure the rotation angle in screen coordinates, but that would imply to know the QGLViewer::camera(), so that we can compute the projected coordinates of the rotation center (as is done with the QGLViewer::SCREEN_ROTATE binding). However, adding an extra pointer to the QGLViewer::camera() in all the AxisPlaneConstraint derived classes (which the user would have to update in a multi-viewer application) was judged as an overkill.

Definition at line 168 of file constraint.h.

Member Enumeration Documentation

enum Type

Type lists the different types of translation and rotation constraints that are available.

It specifies the meaning of the constraint direction (see translationConstraintDirection() and rotationConstraintDirection()): as an axis direction (AxisPlaneConstraint::AXIS) or a plane normal (AxisPlaneConstraint::PLANE). AxisPlaneConstraint::FREE means no constraint while AxisPlaneConstraint::FORBIDDEN completely forbids the translation and/or the rotation.

See translationConstraintType() and rotationConstraintType().

Attention
The AxisPlaneConstraint::PLANE Type is not valid for rotational constraint.

New derived classes can use their own extended enum for specific constraints:

class MyAxisPlaneConstraint : public AxisPlaneConstraint
{
public:
enum MyType { FREE, AXIS, PLANE, FORBIDDEN, CUSTOM };
virtual void constrainTranslation(Vec &translation, Frame *const frame)
{
// translationConstraintType() is simply an int. CUSTOM Type is handled seamlessly.
{
case MyAxisPlaneConstraint::FREE: ... break;
case MyAxisPlaneConstraint::CUSTOM: ... break;
}
};
MyAxisPlaneConstraint* c = new MyAxisPlaneConstraint();
// Note the Type conversion
c->setTranslationConstraintType(AxisPlaneConstraint::Type(MyAxisPlaneConstraint::CUSTOM));
};

Definition at line 207 of file constraint.h.

Constructor & Destructor Documentation

Default constructor.

translationConstraintType() and rotationConstraintType() are set to AxisPlaneConstraint::FREE. translationConstraintDirection() and rotationConstraintDirection() are set to (0,0,0).

Definition at line 38 of file constraint.cpp.

virtual ~AxisPlaneConstraint ( )
inlinevirtual

Virtual destructor.

Empty.

Definition at line 173 of file constraint.h.

Member Function Documentation

virtual void constrainRotation ( Quaternion rotation,
Frame *const  frame 
)
inlinevirtual

Overloading of Constraint::constrainRotation().

Empty.

Reimplemented from Constraint.

Reimplemented in CameraConstraint, WorldConstraint, and LocalConstraint.

Definition at line 244 of file constraint.h.

virtual void constrainTranslation ( Vec translation,
Frame *const  frame 
)
inlinevirtual

Overloading of Constraint::constrainTranslation().

Empty

Reimplemented from Constraint.

Reimplemented in CameraConstraint, WorldConstraint, and LocalConstraint.

Definition at line 212 of file constraint.h.

Vec rotationConstraintDirection ( ) const
inline

Returns the axis direction used by the rotation constraint.

This direction is defined only when rotationConstraintType() is AxisPlaneConstraint::AXIS.

The AxisPlaneConstraint derived classes express this direction in different coordinate system (camera for CameraConstraint, local for LocalConstraint, and world for WorldConstraint). This value can be modified with setRotationConstraintDirection().

Definition at line 259 of file constraint.h.

Referenced by LocalConstraint::constrainRotation(), WorldConstraint::constrainRotation(), and CameraConstraint::constrainRotation().

void setRotationConstraint ( Type  type,
const Vec direction 
)
void setRotationConstraintDirection ( const Vec direction)

Defines the rotationConstraintDirection().

The coordinate system where direction is expressed depends on your class implementation.

Definition at line 75 of file constraint.cpp.

References Vec::norm(), and AxisPlaneConstraint::rotationConstraintType().

Referenced by AxisPlaneConstraint::setRotationConstraint().

void setRotationConstraintType ( Type  type)

Set the Type() of the rotationConstraintType().

Default is AxisPlaneConstraint::FREE.

Depending on this value, the Frame will freely rotate (AxisPlaneConstraint::FREE), will only be able to rotate around an axis (AxisPlaneConstraint::AXIS), or will not able to rotate at all (AxisPlaneConstraint::FORBIDDEN).

Use Frame::setOrientation() to define the orientation of the constrained Frame before it gets constrained.

Attention
An AxisPlaneConstraint::PLANE Type() is not meaningful for rotational constraints and will be ignored.

Definition at line 101 of file constraint.cpp.

References AxisPlaneConstraint::rotationConstraintType().

Referenced by AxisPlaneConstraint::setRotationConstraint().

void setTranslationConstraint ( Type  type,
const Vec direction 
)
void setTranslationConstraintDirection ( const Vec direction)

Defines the translationConstraintDirection().

The coordinate system where direction is expressed depends on your class implementation.

Definition at line 52 of file constraint.cpp.

References Vec::norm(), and AxisPlaneConstraint::translationConstraintType().

Referenced by AxisPlaneConstraint::setTranslationConstraint().

void setTranslationConstraintType ( Type  type)
inline

Sets the Type() of the translationConstraintType().

Default is AxisPlaneConstraint::FREE.

Definition at line 216 of file constraint.h.

Referenced by AxisPlaneConstraint::setTranslationConstraint().

Vec translationConstraintDirection ( ) const
inline

Returns the direction used by the translation constraint.

It represents the axis direction (AxisPlaneConstraint::AXIS) or the plane normal (AxisPlaneConstraint::PLANE) depending on the translationConstraintType(). It is undefined for AxisPlaneConstraint::FREE or AxisPlaneConstraint::FORBIDDEN.

The AxisPlaneConstraint derived classes express this direction in different coordinate system (camera for CameraConstraint, local for LocalConstraint, and world for WorldConstraint). This value can be modified with setTranslationConstraintDirection().

Definition at line 238 of file constraint.h.

Referenced by LocalConstraint::constrainTranslation(), WorldConstraint::constrainTranslation(), and CameraConstraint::constrainTranslation().

Type translationConstraintType ( ) const
inline

Returns the translation constraint Type().

Depending on this value, the Frame will freely translate (AxisPlaneConstraint::FREE), will only be able to translate along an axis direction (AxisPlaneConstraint::AXIS), will be forced to stay into a plane (AxisPlaneConstraint::PLANE) or will not able to translate at all (AxisPlaneConstraint::FORBIDDEN).

Use Frame::setPosition() to define the position of the constrained Frame before it gets constrained.

Definition at line 228 of file constraint.h.

Referenced by LocalConstraint::constrainTranslation(), WorldConstraint::constrainTranslation(), CameraConstraint::constrainTranslation(), and AxisPlaneConstraint::setTranslationConstraintDirection().


The documentation for this class was generated from the following files: