#include <frame.h>
Inherited by SpinningFrame.
World Coordinate position and orientation | |
Methods to set and restore the frame position and orientation (with respect to the world coordinate system).
Use translation() and rotation() to get the local (defined with respect to the referenceFrame()) frame characteristics. | |
Frame (const Vec &pos, const Quaternion &orien) | |
void | setPosition (const Vec &t) |
void | setPosition (const float x, const float y, const float z) |
void | setPositionWithConstraint (Vec &t) |
void | setOrientation (const float x, const float y, const float z, const float a) |
void | setOrientation (const Quaternion &q) |
void | setOrientationWithConstraint (Quaternion &q) |
void | setOrientationAxisAngle (const float x, const float y, const float z, const float a) |
void | setPositionAndOrientation (const Vec &t, const Quaternion &q) |
void | setPositionAndOrientationWithConstraint (Vec &t, Quaternion &q) |
Vec | position () const |
void | getPosition (float &x, float &y, float &z) const |
Quaternion | orientation () const |
void | getOrientation (float &q0, float &q1, float &q2, float &q3) const |
Composition of frames | |
A frame is defined with respect to a given coordinate system. Default is the world coordinate system, corresponding to a NULL referenceFrame().
Setting the reference frame to non | |
const Frame * | referenceFrame () const |
void | setReferenceFrame (const Frame *const fr) |
bool | settingAsReferenceFrameWillCreateALoop (const Frame *const fr) |
Local frame translation and rotation | |
Methods to set and get the frame translation and rotation (defined with respect to the reference frame).
A frame is defined by its translation with respect to its reference frame, and then by a rotation of the coordinate system around the new translated origin. These values (translation and then rotation) are hence defined with respect to the local reference frame. Use position() and orientation() to get the world coordinates of the frame. | |
void | setTranslation (const float x, const float y, const float z) |
void | setTranslation (const Vec &t) |
void | setTranslationWithConstraint (Vec &t) |
void | setRotation (const float x, const float y, const float z, const float a) |
void | setRotation (const Quaternion &q) |
void | setRotationWithConstraint (Quaternion &q) |
void | setRotationAxisAngle (const float x, const float y, const float z, const float a) |
void | setTranslationAndRotation (const Vec &t, const Quaternion &q) |
void | setTranslationAndRotationWithConstraint (Vec &t, Quaternion &q) |
void | getTranslation (float &x, float &y, float &z) const |
Vec | translation () const |
void | getRotation (float &x, float &y, float &z, float &a) const |
Quaternion | rotation () const |
Displacement of frames | |
These methods translate/rotate the Frame. The associated constraint (if defined) is satisfied. The modified() signal is emitted. | |
void | translate (Vec &t) |
void | translate (const Vec &t) |
void | translate (float t[3]) |
void | translate (float &x, float &y, float &z) |
void | translate (const float x, const float y, const float z) |
void | rotate (Quaternion &q) |
void | rotate (const Quaternion &q) |
void | rotate (float q[4]) |
void | rotate (float &x, float &y, float &z, float &a) |
void | rotate (const float x, const float y, const float z, const float a) |
void | rotateAroundPoint (Quaternion &q, const Vec &p) |
void | rotateAroundPoint (const Quaternion &q, const Vec &p) |
Coordinate system transformation of 3D points | |
A frame is as a new coordinate system, defined with respect to a reference frame (the world coordinate system by default, see the "Composition of frame" section). The coordinatesOf() (resp. inverseCoordinatesOf()) functions transform a 3D point from (resp. to) the world coordinates system. This section defines the 3D point transformation functions. See the Coordinate system transformation of vectors below for the transformation of 3D vectors. The difference between the two sets of functions is simple : for vectors, only the rotational part of the transformations is taken into account, while translation is also considered for 3D points. When local is prepended to the names of the functions, the functions simply transform from (and to) the reference frame.
When In (resp. From) is appended to the names, the functions transform from (resp. To) the frame that is given as an argument. The frame does not need to be in the same branch or the hierarchical tree, and can be Combining any of these functions with its inverse (in any order) leads to the identity.
See the frameTransform example for an illustration of some these functions. | |
Vec | coordinatesOf (const Vec &src) const |
Vec | inverseCoordinatesOf (const Vec &src) const |
Vec | localCoordinatesOf (const Vec &src) const |
Vec | localInverseCoordinatesOf (const Vec &src) const |
Vec | coordinatesOfIn (const Vec &src, const Frame *in) const |
Vec | coordinatesOfFrom (const Vec &src, const Frame *from) const |
void | getCoordinatesOf (const float src[3], float res[3]) const |
void | getInverseCoordinatesOf (const float src[3], float res[3]) const |
void | getLocalCoordinatesOf (const float src[3], float res[3]) const |
void | getLocalInverseCoordinatesOf (const float src[3], float res[3]) const |
void | getCoordinatesOfIn (const float src[3], float res[3], const Frame *in) const |
void | getCoordinatesOfFrom (const float src[3], float res[3], const Frame *from) const |
Coordinate system transformation of vectors | |
A frame is as a new coordinate system, defined with respect to a reference frame (the world coordinate system by default, see the "Composition of frame" section). The transformOf() (resp. inverseTransformOf()) functions transform a 3D vector from (resp. to) the world coordinates system. This section defines the 3D vector transformation functions. See the Coordinate system transformation of 3D points above for the transformation of 3D points. The difference between the two sets of functions is simple : for vectors, only the rotational part of the transformations is taken into account, while translation is also considered for 3D points. The length of the resulting transformed vector is identical to the one of the source vector for all the described functions. When local is prepended to the names of the functions, the functions simply transform from (and to) the reference frame.
When In (resp. From) is appended to the names, the functions transform from (resp. To) the frame that is given as an argument. The frame does not need to be in the same branch or the hierarchical tree, and can be
Combining any of these functions with its inverse (in any order) leads to the identity. | |
Vec | transformOf (const Vec &src) const |
Vec | inverseTransformOf (const Vec &src) const |
Vec | localTransformOf (const Vec &src) const |
Vec | localInverseTransformOf (const Vec &src) const |
Vec | transformOfIn (const Vec &src, const Frame *in) const |
Vec | transformOfFrom (const Vec &src, const Frame *from) const |
void | getTransformOf (const float src[3], float res[3]) const |
void | getInverseTransformOf (const float src[3], float res[3]) const |
void | getLocalTransformOf (const float src[3], float res[3]) const |
void | getLocalInverseTransformOf (const float src[3], float res[3]) const |
void | getTransformOfIn (const float src[3], float res[3], const Frame *in) const |
void | getTransformOfFrom (const float src[3], float res[3], const Frame *from) const |
Constraints on the displacement | |
A constraint can be attached to the frame to limit its displacement. The translate() and rotate() function will satisfy this constraint. Default value is a non-constraint (NULL ) constraint. See the Constraint and derived class documentation. | |
Constraint * | constraint () const |
void | setConstraint (Constraint *c) |
Frame associated matrices | |
const GLdouble * | matrix () const |
void | getMatrix (GLdouble m[4][4]) const |
void | getMatrix (GLdouble m[16]) const |
const GLdouble * | worldMatrix () const |
void | getWorldMatrix (GLdouble m[4][4]) const |
void | getWorldMatrix (GLdouble m[16]) const |
void | setFromMatrix (const float m[4][4]) |
void | alignWithFrame (const Frame *const fr, bool move=false, float threshold=0.85f) |
void | projectOnLine (const Vec &origin, const Vec &dir) |
const GLdouble * | inverseMatrix () const |
void | getInverseMatrix (GLdouble m[4][4]) const |
void | getInverseMatrix (GLdouble m[16]) const |
const GLdouble * | worldInverseMatrix () const |
void | getWorldInverseMatrix (GLdouble m[4][4]) const |
void | getWorldInverseMatrix (GLdouble m[16]) const |
Inversion of the transformation | |
Frame | inverse () const |
void | invert () |
Frame | worldInverse () const |
void | worldInvert () |
XML representation | |
virtual QDomElement | domElement (const QString &name, QDomDocument &doc) const |
virtual void | initFromDOMElement (const QDomElement &de) |
Signals | |
void | modified () |
Public Member Functions | |
Frame () | |
virtual | ~Frame () |
Frame & | operator= (const Frame &f) |
Frame (const Frame &f) |
A Frame is a 3D coordinate system, represented by a position() and an orientation(). The order of these transformations is important : in libQGLViewer, the Frame is firstly translated and then rotated around the new translated origin. A Frame is useful to define the position and orientation of a 3D rigid object :
Frame fr; fr.setPosition(1,0,3); fr.setOrientationAxisAngle(0,1,0, M_PI/2); // Rotation around the Y axis. glPushMatrix(); glMultMatrixd(fr.matrix()); // Draw your object here glPopMatrix();
Many functions are provided to transform a 3D point from one coordinate system to an other : see coordinatesOf(), inverseCoordinatesOf(), coordinatesOfIn(), coordinatesOfFrom()...
You may also want to transform a 3D vector from one frame to an other, which corresponds to applying only the rotational part of the frame transformation : see transformOf() and inverseTransformOf().
See the frameTransform example for an illustration.
The translation() and the rotation() that are encapsulated in a Frame can also be used to represent a solid transformation of space. Such a solid transformation can also be interpreted as a change of coordinate system, and the coordinate system conversion functions actually allow you to use a Frame as a solid transformation. Use inverseCoordinatesOf() (resp. coordinatesOf()) to apply the transformation (resp. its inverse). Note the inversion.
The position and the rotation of a Frame are actually defined with respect to a referenceFrame(). The default referenceFrame() is the world coordinate system, but this value can be set to any other frame using setReferenceFrame(). When a referenceFrame() is specified, one must differentiate :
NULL
value, corresponding to the world coordinate system).A Frame is actually defined by its translation() with respect to its referenceFrame(), and then by a rotation() of the coordinate system around the new translated origin.
Setting a NULL
reference frame resets the world coordinate system as the referenceFrame() (default value). The world coordinate system is the one you are in at the beginning of the QGLViewer::draw() function (see the introduction page>).
Frames can hence easily be organized in a tree hierarchy, which root is the world coordinate system. A loop in the hierarchy would result in an inconsistent (multiple) frame definition. settingAsReferenceFrameWillCreateALoop() checks this and prevents setReferenceFrame() from creating such a loop.
This frame hierarchy is used in methods like coordinatesOfIn(), coordinatesOfFrom()... which allow coordinates (or vector) conversion from a frame to any other one (including the world coordinate system).
Frame* body = new Frame(); Frame* leftArm = new Frame(); Frame* rightArm = new Frame(); leftArm->setReferenceFrame(body); rightArm->setReferenceFrame(body);
void Viewer::draw() { glPushMatrix(); glMultMatrixd(body->matrix()); drawBody(); glPushMatrix(); glMultMatrixd(leftArm->matrix()); drawArm(); glPopMatrix(); glPushMatrix(); glMultMatrixd(rightArm->matrix()); drawArm(); glPopMatrix(); glPopMatrix(); }
An interesting feature of Frames is that their displacement can be constrained. When a Constraint is attached to a Frame, it filters the input of translate() and rotate(), and only the resulting filtered motion is applied to the frame. The default constraint() is NULL
and no filter is applied. Use setConstraint() to attach a constraint to a frame.
Constraints are especially usefull for the ManipulatedFrame instances, in order to forbid some mouse motions. See the constrainedFrame, constrainedCamera and luxo examples for an illustration.
New constraints can very easily be implemented by deriving a class from the Constraint class or any of its derived classes. All you need is to provide your own implementation of the Constraint::constrainTranslation(qglviewer::Vec&, Frame* const) and Constraint::constrainRotation(qglviewer::Quaternion& , Frame* const) functions.
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 ManipulatedFrame class inherits Frame and implements a mouse motion convertion, so that a frame can be manipulated with the mouse. SpinningFrame are animated Frames with a rotational motion.
|
Creates a default frame. Positioned in (0,0,0), with an identity rotation (0,0,0,1). The referenceFrame() is set to |
|
Virtual destructor. Empty. |
|
Copy constructor. translation(), rotation(), constraint() and referenceFrame() are copied. |
|
Creates an initialized frame, with a position and an orientation. The reference frame is set to NULL (meaning world coordinate system). |
|
Align the Frame with an other Frame, so that two of their axis are parallel.
If the X, Y and Z axis of the Frame is almost parallel to any of the X, Y, or Z axis of If, after this first rotation, two other axis are also almost parallel, a second alignment is performed. The two frames then have identical orientations, up to rotations of 90 degrees.
When
ManipulatedFrame::mouseDoubleClickEvent() calls this function when the left mouse button is double clicked. |
|
Returns the current constraint. Result is of type Constraint and
A |
|
This returns the frame coordinates of a point
If inverseCoordinatesOf() performs the inverse transformation. See the frameTransform example for an illustration. |
|
This returns the frame coordinate system coordinates of the point whose position in the
If coordinatesOfIn() performs the inverse transformation. |
|
This returns the
If coordinatesOfFrom() performs the inverse transformation. |
|
Creates an XML QDomElement that represents the Frame. QDomDocument doc("myDocument"); Frame sunFrame; // ... anyNode.addElement(sunFrame.domElement("sunFrame", doc)); // ... See also Camera::domElement(), KeyFrameInterpolator::domElement()...
Reimplemented in ManipulatedCameraFrame, ManipulatedFrame, and SpinningFrame. |
|
Same as coordinatesOf(), but with float parameters. |
|
Same as coordinatesOfFrom(), but with float parameters. |
|
Same as coordinatesOfIn(), but with float parameters. |
|
Same as inverseCoordinatesOf(), but with float parameters. |
|
double[16] parameter version of inverseMatrix(). See also getWorldInverseMatrix() and worldInverseMatrix(). This function is very similar to Quaternion::getInverseMatrix(), it simply includes the negated inverse rotated Frame translation in the last line. |
|
double[4][4] parameter version of inverseMatrix(). See also getWorldInverseMatrix() and worldInverseMatrix(). This function is very similar to Quaternion::getInverseMatrix(), it simply includes the negated inverse rotated Frame translation in the last line.
|
|
Same as inverseTransformOf(), but with float parameters. |
|
Same as localCoordinatesOf(), but with float parameters. |
|
Same as localInverseCoordinatesOf(), but with float parameters. |
|
Same as localInverseTransformOf(), but with float parameters. |
|
Same as localTransformOf(), but with float parameters. |
|
double[16] parameter version of matrix(). See also getWorldMatrix() and worldMatrix(). This function is very similar to Quaternion::getMatrix(), it simply includes the Frame translation in the last line. |
|
double[4][4] parameter version of matrix(). See also getWorldMatrix() and worldMatrix(). This function is very similar to Quaternion::getMatrix(), it simply includes the Frame translation in the last line.
|
|
Get the current orientation of the frame (same as orientation()). Parameters are the orientation Quaternion values. See also setOrientation() and setOrientationAxisAngle(). |
|
Get the current position of the frame (same as position()). See also setPosition(). |
|
Get the current rotation of the frame (same as rotation()). Parameters are the rotation Quaternion values. See also setRotation() and setRotationAxisAngle(). |
|
Same as transformOf(), but with float parameters. |
|
Same as transformOfFrom(), but with float parameters. |
|
Same as transformOfIn(), but with float parameters. |
|
Get the current local translation of the frame (same as translation()). See also setTranslation(). |
|
float[16] parameter version of worldInverseMatrix(). See also getInverseMatrix() and inverseMatrix(). |
|
float[4][4] parameter version of worldInverseMatrix(). See also getInverseMatrix() and inverseMatrix(). |
|
float[16] parameter version of worldMatrix(). See also getMatrix() and matrix(). |
|
float[4][4] parameter version of worldMatrix(). See also getMatrix() and matrix(). |
|
Restore the Frame state from a QDomElement created by domElement(). See Vec::initFromDOMElement() and Quaternion::initFromDOMElement() for details.
Reimplemented in ManipulatedCameraFrame, ManipulatedFrame, and SpinningFrame. |
|
Returns the inverse of the Frame space transformation. The original Frame is not modified. Use invert() to actually modify the Frame. The rotation() of the new Frame is the Quaternion::inverse() of the original rotation(). Its translation() is the negated and inverse rotated image of the original translation(). The new Frame has the same referenceFrame() as the original. Hence only the local Frame transformation is inverted (see the "Hierarchy of frames" section in the Frame Detailed documentation for details on this notion). Use worldInverse() for a global inverse. |
|
This returns the world coordinates of the point whose position in the frame coordinate system is
If coordinatesOf() performs the inverse transformation. See the frameTransform example for an illustration. |
|
Returns the current 4x4 frame inverse matrix. This matrix only represents the local inverse transformation (see referenceFrame() for frame composition). Use getWorldInverseMatrix() or worldInverseMatrix() to have the full frame inverse transformation matrix (i.e. from the world coordinate system). worldInverseMatrix() and inverseMatrix() will return identical results when the frame is not composed (referenceFrame() == NULL). See also getInverseMatrix().
|
|
This returns the world transform of the vector whose coordinates in the frame coordinate system is For vectors, only the rotational part of the transformation is taken into account, see inverseCoordinatesOf() for the point equivalent function. transformOf() performs the inverse transformation. |
|
Invert the Frame (same as inverse(), but the Frame is actually inverted). The new rotation is the inverse of the previous one. The translation is the negated inverse rotation of the original translation(). This method only inverts the local Frame transformation (see inverse() for details). Use worldInvert() for a full transformation inversion. The modified() signal is emitted. |
|
Returns the frame coordinates of a point
If localInverseCoordinatesOf() performs the inverse transformation. |
|
Returns the reference frame coordinates (default is the world coordinates system, see referenceFrame()) of a point
If localCoordinatesOf() performs the inverse transformation. |
|
Returns the reference frame transform (default is the world coordinates system, see referenceFrame()) of a vector For vectors, only the rotational part of the transformation is taken into account, see localCoordinatesOf() for the point equivalent function. localTransformOf() performs the inverse transformation. |
|
Returns the frame transform of a vector For vectors, only the rotational part of the transformation is taken into account, see localCoordinatesOf() for the point equivalent function. localInverseTransformOf() performs the inverse transformation. |
|
Returns the current 4x4 frame matrix. Can be used with worldMatrix() and matrix() will return identical results when the frame is not composed (referenceFrame() == NULL). See also getMatrix().
|
|
This signal is emitted whenever the position or the orientation of the Frame is modified. Connect this signal to any object that must be notified. QObject::connect(myFrame, SIGNAL(modified()), myObject, SLOT(update())); This signal can also be connected to all the viewers using QGLViewer::connectSignalToAllViewers().
|
|
operator= : referenceFrame() and constraint() pointers are copied. |
|
Returns the current frame orientation (defined with respect to the world coordinate system). See setOrientation(). |
|
Returns the current frame origin position (defined in the world coordinate system). See setPosition(). |
|
Translates the frame so that its position is on the line defined by |
|
Returns the current reference frame, defined with setReferenceFrame().
The frame is "child" of the referenceFrame(), meaning that its position and orientation are defined with respect to the referenceFrame(). A Convenient functions allow you to convert 3D coordinates from one frame to an other : coordinatesOf(), localCoordinatesOf(), coordinatesOfIn() and their inverse functions. Vectors can also be converted from one frame to an other using transformOf(), transformOfIn, localTransformOf() and the inverse functions.
A warning is printed if setting |
|
Same as rotate(), but with float parameters (Quaternion values). Actual rotation may differ from these values in order to satisfy the rotation constraint(). Use the non-const parameter version of this function to get the filtered values back. |
|
Same as rotate(), but with float parameters (Quaternion values). Parameters may be modified to satisfy rotation constraint(). See also the const parameter version of this function. |
|
Same as rotate(), but parameter is given as a float[4]. Quaternion |
|
Compose current frame rotation with |
|
Compose current frame rotation with |
|
Same as rotateAroundPoint(), but the rotation Quaternion is |
|
Same as rotate(), but position() is modified as if the Frame was rotated of
If the frame is constrained (see setConstraint()), |
|
Returns the current Quaternion orientation. See setRotation(). |
|
Set the constraint attached with the frame. A |
|
Set the frame state from a matrix representation. Matrix has to be a proper row-major order transformation representation (rotation is in the upper left 3x3 matrix, while translation is on the last line). matrix() returns the current matrix value.
|
|
Set the current orientation of the frame (with respect to the world coordinate system). See orientation() and setOrientationWithConstraint(). |
|
Same as setOrientation(), but with float parameters. |
|
Set the current orientation of the frame. Parameters are the rotation axis vector and its angle (in radians). |
|
Same as setOrientation(), but the possible constraint() of the Frame is enforced. |
|
Same as setPosition(), but with |
|
Set the position of the origin of the frame, with respect to the world coordinate system. Use setTranslation() to defined to local frame translation (with respect to the reference frame). See also position(), orientation() and setPositionWithConstraint(). |
|
Same as successive calls to setPosition() and then setOrientation(). Only one modified() signal is emitted, which is convenient if this signal is connected to a viewer updateGL() slot. See also setTranslationAndRotation() and setPositionAndOrientationWithConstraint(). |
|
Same as setPositionAndOrientation() but the position and orientation increments are filtered by the possible constraint(). |
|
Same as setPosition(), but the possible constraint() of the Frame is enforced. |
|
Set the current reference frame. The frame then becomes a "child" of the referenceFrame(), meaning that its position and orientation are defined with respect to the referenceFrame(). |
|
Set the current rotation Quaternion. See rotation() and the different Quaternion constructors. Emits the modified() signal. See also setTranslation() and setRotationWithConstraint(). |
|
Set the current rotation of the frame. Parameters are the rotation Quaternion float values. Get current rotation with rotation(). |
|
Set the current rotation of the frame. Parameters are the rotation axis vector and its angle (in radians). |
|
Same as setRotation(), but the possible constraint() of the Frame is enforced. |
|
Returns |
|
Set the current local translation of the frame. Use translation() to get the current frame position. See setPosition() and position() to get the world position of the frame. Emits the modified() signal. See also setRotation() and setTranslationWithConstraint(). |
|
Set the current translation of the frame. Same as setTranslation(), but with |
|
Same as successive calls to setPosition() and then setOrientation(). Only one modified() signal is emitted, which is convenient if this signal is connected to a viewer updateGL() slot. See also setPositionAndOrientation() and setTranslationAndRotationWithConstraint(). |
|
Same as setTranslationAndRotation(), but the possible constraint() of the Frame is enforced. |
|
Same as setTranslation(), but the possible constraint() of the Frame is enforced. |
|
This returns the frame transform of a vector For vectors, only the rotational part of the transformation is taken into account, see coordinatesOf() for the point equivalent function. inverseTransformOf() performs the inverse transformation. |
|
This returns the frame coordinate system transform of the vector whose coordinates in the For vectors, only the rotational part of the transformation is taken into account, see coordinatesOfFrom() for the point equivalent function. transformOfIn() performs the inverse transformation. |
|
This returns the For vectors, only the rotational part of the transformation is taken into account, see coordinatesOfIn() for the point equivalent function. transformOfFrom() performs the inverse transformation. |
|
Same as translate() but with const float parameter. The actual translation may differ from the given parameters in order to satisfy the constraint(). Use the non-const version to get the filtered values back. |
|
Same as translate() but with float parameters. Parameters are modified to satisfy translation constraints (see constraint()). See also the non-const parameters version of this version, if you are not interested in the filtered values. |
|
Same as translate() but with a float[3] parameter. |
|
Translate the frame of |
|
Translate the frame of |
|
Returns the current frame position. See setTranslation(). |
|
Returns the world inverse of the Frame transformation. The original Frame is not modified. Use worldInvert() to actually modify the Frame. The orientation() of the new Frame is the Quaternion::inverse() of the original orientation(). Its position() is the negated and inverse rotated image of the original position().
The new Frame has no (i.e. |
|
Returns the 4x4 frame inverse matrix, defined in the world coordinate system. This matrix is simply the inverse of worldMatrix(). worldInverseMatrix() and inverseMatrix() are actually identical when the Frame has no (i.e.
|
|
Invert the Frame world transformations (same as worldInverse(), but the Frame is actually inverted). The new orientation is the inverse of the previous one. The position() is the negated inverse rotation of the original position(). This method only inverts the local Frame transformation (see inverse() for details). Use invert() for a local transformation inversion. The modified() signal is emitted. |
|
Returns the 4x4 frame matrix, defined in the world coordinate system. Can be used with worldMatrix() and matrix() will return identical results when the frame is not composed (referenceFrame() == NULL). See also getWorldMatrix() and getWorldInverseMatrix().
|