Inherited by ManipulatedFrame.
World coordinates position and orientation | |
Frame (const Vec &position, const Quaternion &orientation) | |
void | setPosition (const Vec &position) |
void | setPosition (float x, float y, float z) |
void | setPositionWithConstraint (Vec &position) |
void | setOrientation (const Quaternion &orientation) |
void | setOrientation (double q0, double q1, double q2, double q3) |
void | setOrientationWithConstraint (Quaternion &orientation) |
void | setPositionAndOrientation (const Vec &position, const Quaternion &orientation) |
void | setPositionAndOrientationWithConstraint (Vec &position, Quaternion &orientation) |
Vec | position () const |
Quaternion | orientation () const |
void | getPosition (float &x, float &y, float &z) const |
void | getOrientation (double &q0, double &q1, double &q2, double &q3) const |
Local translation and rotation w/r reference Frame | |
void | setTranslation (const Vec &translation) |
void | setTranslation (float x, float y, float z) |
void | setTranslationWithConstraint (Vec &translation) |
void | setRotation (const Quaternion &rotation) |
void | setRotation (double q0, double q1, double q2, double q3) |
void | setRotationWithConstraint (Quaternion &rotation) |
void | setTranslationAndRotation (const Vec &translation, const Quaternion &rotation) |
void | setTranslationAndRotationWithConstraint (Vec &translation, Quaternion &rotation) |
Vec | translation () const |
Quaternion | rotation () const |
void | getTranslation (float &x, float &y, float &z) const |
void | getRotation (double &q0, double &q1, double &q2, double &q3) const |
Frame hierarchy | |
const Frame * | referenceFrame () const |
void | setReferenceFrame (const Frame *const refFrame) |
bool | settingAsReferenceFrameWillCreateALoop (const Frame *const frame) |
Frame modification | |
void | translate (Vec &t) |
void | translate (const Vec &t) |
void | translate (float x, float y, float z) |
void | translate (float &x, float &y, float &z) |
void | rotate (Quaternion &q) |
void | rotate (const Quaternion &q) |
void | rotate (double q0, double q1, double q2, double q3) |
void | rotate (double &q0, double &q1, double &q2, double &q3) |
void | rotateAroundPoint (Quaternion &rotation, const Vec &point) |
void | rotateAroundPoint (const Quaternion &rotation, const Vec &point) |
void | alignWithFrame (const Frame *const frame, bool move=false, float threshold=0.85f) |
void | projectOnLine (const Vec &origin, const Vec &direction) |
Coordinate system transformation of 3D coordinates | |
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 *const in) const |
Vec | coordinatesOfFrom (const Vec &src, const Frame *const 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 *const in) const |
void | getCoordinatesOfFrom (const float src[3], float res[3], const Frame *const from) const |
Coordinate system transformation of vectors | |
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 *const in) const |
Vec | transformOfFrom (const Vec &src, const Frame *const 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 *const in) const |
void | getTransformOfFrom (const float src[3], float res[3], const Frame *const from) const |
Constraint on the displacement | |
Constraint * | constraint () const |
void | setConstraint (Constraint *const constraint) |
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 GLdouble m[4][4]) |
void | setFromMatrix (const GLdouble m[16]) |
Inversion of the transformation | |
Frame | inverse () const |
Frame | worldInverse () const |
XML representation | |
virtual QDomElement | domElement (const QString &name, QDomDocument &document) const |
virtual void | initFromDOMElement (const QDomElement &element) |
Signals | |
void | modified () |
void | interpolated () |
Public Member Functions | |
Frame () | |
virtual | ~Frame () |
Frame (const Frame &frame) | |
Frame & | operator= (const Frame &frame) |
A Frame is a 3D coordinate system, represented by a position() and an orientation(). The order of these transformations is important: the Frame is first translated and then rotated around the new translated origin.
A Frame is useful to define the position and orientation of a 3D rigid object, using its matrix() method, as shown below:
// Builds a Frame at position (0.5,0,0) and oriented such that its Y axis is along the (1,1,1) // direction. One could also have used setPosition() and setOrientation(). Frame fr(Vec(0.5,0,0), Quaternion(Vec(0,1,0), Vec(1,1,1))); glPushMatrix(); glMultMatrixd(fr.matrix()); // Draw your object here, in the local fr coordinate system. glPopMatrix();
Many functions are provided to transform a 3D point from one coordinate system (Frame) to an other: see coordinatesOf(), inverseCoordinatesOf(), coordinatesOfIn(), coordinatesOfFrom()...
You may also want to transform a 3D vector (such as a normal), 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 rigid transformation of space. Such a 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 rigid transformation. Use inverseCoordinatesOf() (resp. coordinatesOf()) to apply the transformation (resp. its inverse). Note the inversion.
The position and the orientation of a Frame are actually defined with respect to a referenceFrame(). The default referenceFrame() is the world coordinate system (represented by a NULL
referenceFrame()). If you setReferenceFrame() to a different Frame, you must then differentiate:
This terminology for local (translation() and rotation()) and global (position() and orientation()) definitions is used in all the methods' names and should be sufficient to prevent ambiguities. These notions are obviously identical when the referenceFrame() is NULL
, i.e. when the Frame is defined in the world coordinate system (the one you are in at the beginning of the QGLViewer::draw() method, 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) conversions from a Frame to any other one (including the world coordinate system).
However, one must note that this hierarchical representation is internal to the Frame classes. When the Frames represent OpenGL coordinates system, one should map this hierarchical representation to the OpenGL GL_MODELVIEW matrix stack. See the matrix() documentation for details.
An interesting feature of Frames is that their displacements 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
resulting in no filtering. 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.
Classical constraints are provided for convenience (see LocalConstraint, WorldConstraint and CameraConstraint) and new constraints can very easily be implemented.
The ManipulatedFrame class inherits Frame and implements a mouse motion convertion, so that a Frame (and hence an object) can be manipulated in the scene with the mouse.
|
Creates a default Frame.
Its position() is (0,0,0) and it has an identity orientation() Quaternion. The referenceFrame() and the constraint() are |
|
Virtual destructor. Empty. |
|
Copy constructor. The translation() and rotation() as well as constraint() and referenceFrame() pointers are copied. |
|
Creates a Frame with a position() and an orientation(). See the Vec and Quaternion documentations for convenient constructors and methods.
The Frame is defined in the world coordinate system (its referenceFrame() is |
|
Aligns the Frame with
If one of 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 90 degrees rotations.
When
The rotation (and translation when |
|
Returns the current constraint applied to the Frame.
A
You may have to use a |
|
Returns the Frame coordinates of a point inverseCoordinatesOf() performs the inverse convertion. transformOf() converts 3D vectors instead of 3D coordinates. See the frameTransform example for an illustration. |
|
Returns the Frame coordinates of the point whose position in the coordinatesOfIn() performs the inverse transformation. |
|
Returns the coordinatesOfFrom() performs the inverse transformation. |
|
Returns an XML
The resulting QDomElement looks like: <name> <position x=".." y=".." z=".." /> <orientation q0=".." q1=".." q2=".." q3=".." /> </name>
Use initFromDOMElement() to restore the Frame state from the resulting See Vec::domElement() for a complete example. See also Quaternion::domElement(), Camera::domElement()...
Reimplemented in ManipulatedCameraFrame, and ManipulatedFrame. |
|
Same as coordinatesOf(), but with |
|
Same as coordinatesOfFrom(), but with |
|
Same as coordinatesOfIn(), but with |
|
Same as inverseCoordinatesOf(), but with |
|
Same as inverseTransformOf(), but with |
|
Same as localCoordinatesOf(), but with |
|
Same as localInverseCoordinatesOf(), but with |
|
Same as localInverseTransformOf(), but with |
|
Same as localTransformOf(), but with |
|
|
|
|
|
The
See Quaternion::Quaternion(double, double, double, double) for details on |
|
|
|
The
See Quaternion::Quaternion(double, double, double, double) for details on |
|
Same as transformOf(), but with |
|
Same as transformOfFrom(), but with |
|
Same as transformOfIn(), but with |
|
Fill |
|
float[16] parameter version of worldMatrix(). See also getMatrix() and matrix(). |
|
float[4][4] parameter version of worldMatrix(). See also getMatrix() and matrix(). |
|
Restores the Frame state from a
See domElement() for the
Reimplemented in ManipulatedCameraFrame, and ManipulatedFrame. |
|
This signal is emitted when the Frame is interpolated by a KeyFrameInterpolator. See the KeyFrameInterpolator documentation for details. If a KeyFrameInterpolator is used to successively interpolate several Frames in your scene, connect the KeyFrameInterpolator::interpolated() signal instead (identical, but independent of the interpolated Frame). |
|
Returns a Frame representing the inverse of the Frame space transformation. The rotation() of the new Frame is the Quaternion::inverse() of the original rotation. Its translation() is the negated inverse rotated image of the original translation. If a Frame is considered as a space rigid transformation (translation and rotation), the inverse() Frame performs the inverse transformation. Only the local Frame transformation (i.e. defined with respect to the referenceFrame()) is inverted. Use worldInverse() for a global inverse.
The resulting Frame has the same referenceFrame() as the Frame and a
|
|
Returns the world coordinates of the point whose position in the Frame coordinate system is coordinatesOf() performs the inverse convertion. Use inverseTransformOf() to transform 3D vectors instead of 3D coordinates. |
|
Returns the world transform of the vector whose coordinates in the Frame coordinate system is transformOf() performs the inverse transformation. Use inverseCoordinatesOf() to transform 3D coordinates instead of 3D vectors. |
|
Returns the Frame coordinates of a point localInverseCoordinatesOf() performs the inverse convertion. See also localTransformOf(). |
|
Returns the referenceFrame() coordinates of a point localCoordinatesOf() performs the inverse convertion. See also localInverseTransformOf(). |
|
Returns the referenceFrame() transform of a vector localTransformOf() performs the inverse transformation. See also localInverseCoordinatesOf(). |
|
Returns the Frame transform of a vector localInverseTransformOf() performs the inverse transformation. See also localCoordinatesOf(). |
|
Returns the 4x4 OpenGL transformation matrix represented by the Frame.
This method should be used in conjunction with Frame* body = new Frame(); Frame* leftArm = new Frame(); Frame* rightArm = new Frame(); leftArm->setReferenceFrame(body); rightArm->setReferenceFrame(body); The associated OpenGL drawing code should look like: void Viewer::draw()
{
glPushMatrix();
glMultMatrixd(body->matrix());
drawBody();
glPushMatrix();
glMultMatrixd(leftArm->matrix());
drawArm();
glPopMatrix();
glPushMatrix();
glMultMatrixd(rightArm->matrix());
drawArm();
glPopMatrix();
glPopMatrix();
}
leftArm and rightArm are both correctly drawn with respect to the body coordinate system.
This matrix only represents the local Frame transformation (i.e. with respect to the referenceFrame()). Use worldMatrix() to get the full Frame transformation matrix (i.e. from the world to the Frame coordinate system). These two match when the referenceFrame() is The result is only valid until the next call to matrix(), getMatrix(), worldMatrix() or getWorldMatrix(). Use it immediately (as above) or use getMatrix() instead.
|
|
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()));
|
|
Equal operator. The referenceFrame() and constraint() pointers are copied.
|
|
Returns the orientation of the Frame, defined in the world coordinate system. See also position(), setOrientation() and rotation(). |
|
Returns the position of the Frame, defined in the world coordinate system. See also orientation(), setPosition() and translation(). |
|
Translates the Frame so that its position() lies on the line defined by
Simply uses an orthogonal projection. |
|
Returns the reference Frame, in which coordinates system the Frame is defined.
The translation() and rotation() of the Frame are defined with respect to the referenceFrame() coordinate system. A
Use position() and orientation() to recursively convert values along the referenceFrame() chain and to get values expressed in the world coordinate system. The values match when the referenceFrame() is Use setReferenceFrame() to set this value and create a Frame hierarchy. Convenient functions allow you to convert 3D coordinates from one Frame to an other: see coordinatesOf(), localCoordinatesOf(), coordinatesOfIn() and their inverse functions. Vectors can also be converted using transformOf(), transformOfIn, localTransformOf() and their inverse functions. |
|
Same as rotate(Quaternion&) but with |
|
Same as rotate(const Quaternion&) but with |
|
Rotates the Frame by
The rotation actually applied to the Frame may differ from See also translate(const Vec&). Emits the modified() signal. |
|
Same as rotate(const Quaternion&) but |
|
Same as rotateAroundPoint(), but with a |
|
Makes the Frame rotate() by
If the Frame has a constraint(), Emits the modified() signal. |
|
Returns the current Quaternion orientation. See setRotation(). |
|
Sets the constraint() attached to the Frame.
A |
|
Sets the Frame from an OpenGL matrix representation (rotation in the upper left 3x3 matrix and translation on the last line). Hence, if a code fragment looks like: GLdouble m[16]={...}; glMultMatrixd(m); Frame fr; fr.setFromMatrix(m); glMultMatrixd(fr.matrix()); Using this conversion, you can benefit from the powerful Frame transformation methods to translate points and vectors to and from the Frame coordinate system to any other Frame coordinate system (including the world coordinate system). See coordinatesOf() and transformOf(). Emits the modified() signal. See also matrix(), getMatrix() and Quaternion::setFromRotationMatrix().
|
|
This is an overloaded method provided for convenience. Same as setFromMatrix(). |
|
Same as setOrientation(), but with |
|
Sets the orientation() of the Frame, defined in the world coordinate system. Emits the modified() signal. Use setRotation() to define the local frame rotation (with respect to the referenceFrame()). The potential constraint() of the Frame is not taken into account, use setOrientationWithConstraint() instead. |
|
Same as setOrientation(), but |
|
Same as setPosition(), but with |
|
Sets the position() of the Frame, defined in the world coordinate system. Emits the modified() signal. Use setTranslation() to define the local frame translation (with respect to the referenceFrame()). The potential constraint() of the Frame is not taken into account, use setPositionWithConstraint() instead. |
|
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 QGLViewer::updateGL() slot. See also setTranslationAndRotation() and setPositionAndOrientationWithConstraint(). |
|
Same as setPositionAndOrientation() but |
|
Same as setPosition(), but |
|
Sets the referenceFrame() of the Frame. The Frame translation() and rotation() are then defined in the referenceFrame() coordinate system. Use position() and orientation() to express these in the world coordinate system.
Emits the modified() signal if
Using this method, you can create a hierarchy of Frames. This hierarchy needs to be a tree, which root is the world coordinate system (i.e. a |
|
Same as setRotation() but with |
|
Sets the rotation() of the Frame, locally defined with respect to the referenceFrame(). Emits the modified() signal. Use setOrientation() to define the world coordinates orientation(). The potential constraint() of the Frame is not taken into account, use setRotationWithConstraint() instead. |
|
Same as setRotation(), but Emits the modified() signal. See also setTranslationWithConstraint() and setOrientationWithConstraint(). |
|
Returns |
|
Same as setTranslation(), but with |
|
Sets the translation() of the frame, locally defined with respect to the referenceFrame(). Emits the modified() signal. Use setPosition() to define the world coordinates position(). Use setTranslationWithConstraint() to take into account the potential constraint() of the Frame. |
|
Same as successive calls to setTranslation() and then setRotation(). Only one modified() signal is emitted, which is convenient if this signal is connected to a QGLViewer::updateGL() slot. See also setPositionAndOrientation() and setTranslationAndRotationWithConstraint(). |
|
Same as setTranslationAndRotation(), but |
|
Same as setTranslation(), but Emits the modified() signal. See also setRotationWithConstraint() and setPositionWithConstraint(). |
|
Returns the Frame transform of a vector inverseTransformOf() performs the inverse transformation. coordinatesOf() converts 3D coordinates instead of 3D vectors (here only the rotational part of the transformation is taken into account). See the frameTransform example for an illustration. |
|
Returns the Frame transform of the vector whose coordinates in the transformOfIn() performs the inverse transformation. |
|
Returns the transformOfFrom() performs the inverse transformation. |
|
Same as translate(Vec&) but with |
|
Same as translate(const Vec&) but with |
|
Translates the Frame of
The translation actually applied to the Frame may differ from See also rotate(const Quaternion&). Emits the modified() signal. |
|
Same as translate(const Vec&) but |
|
Returns the Frame translation, defined with respect to the referenceFrame().
Use position() to get the result in the world coordinates. These two values are identical when the referenceFrame() is See also setTranslation() and setTranslationWithConstraint(). |
|
Returns the inverse() of the Frame world transformation. 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 result Frame has a Use inverse() for a local (i.e. with respect to referenceFrame()) transformation inverse. |
|
Returns the 4x4 OpenGL transformation matrix represented by the Frame.
This method should be used in conjunction with // The modelview here corresponds to the world coordinate system. Frame fr(pos, Quaternion(from, to)); glPushMatrix(); glMultMatrixd(fr.matrix()); // draw object in the fr coordinate system. glPopMatrix();
This matrix represents the global Frame transformation: the entire referenceFrame() hierarchy is taken into account to define the Frame transformation from the world coordinate system. Use matrix() to get the local Frame transformation matrix (i.e. defined with respect to the referenceFrame()). These two match when the referenceFrame() is The OpenGL format of the result is the transpose of the actual mathematical European representation (translation is on the last line instead of the last column).
|