00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef QGLVIEWER_FRAME_H
00024 #define QGLVIEWER_FRAME_H
00025
00026 #if QT_VERSION >= 0x040000
00027 # include <QObject>
00028 # include <QString>
00029 #else
00030 # include <qobject.h>
00031 # include <qstring.h>
00032 #endif
00033
00034 #include "constraint.h"
00035
00036
00037 namespace qglviewer {
00126 class QGLVIEWER_EXPORT Frame : public QObject
00127 {
00128 Q_OBJECT
00129
00130 public:
00131 Frame();
00132
00134 virtual ~Frame() {};
00135
00136 Frame(const Frame& frame);
00137 Frame& operator=(const Frame& frame);
00138
00139 Q_SIGNALS:
00163 void modified();
00164
00172 void interpolated();
00173
00174 public:
00177 Frame(const Vec& position, const Quaternion& orientation);
00178
00179 void setPosition(const Vec& position);
00180 void setPosition(float x, float y, float z);
00181 void setPositionWithConstraint(Vec& position);
00182
00183 void setOrientation(const Quaternion& orientation);
00184 void setOrientation(double q0, double q1, double q2, double q3);
00185 void setOrientationWithConstraint(Quaternion& orientation);
00186
00187 void setPositionAndOrientation(const Vec& position, const Quaternion& orientation);
00188 void setPositionAndOrientationWithConstraint(Vec& position, Quaternion& orientation);
00189
00192 Vec position() const { return inverseCoordinatesOf(Vec(0.0,0.0,0.0)); };
00193 Quaternion orientation() const;
00194
00195 void getPosition(float& x, float& y, float& z) const;
00196 void getOrientation(double& q0, double& q1, double& q2, double& q3) const;
00198
00199
00200 public:
00208 void setTranslation(const Vec& translation) { t_ = translation; Q_EMIT modified(); };
00209 void setTranslation(float x, float y, float z);
00210 void setTranslationWithConstraint(Vec& translation);
00211
00222 void setRotation(const Quaternion& rotation) { q_ = rotation; Q_EMIT modified(); };
00223 void setRotation(double q0, double q1, double q2, double q3);
00224 void setRotationWithConstraint(Quaternion& rotation);
00225
00226 void setTranslationAndRotation(const Vec& translation, const Quaternion& rotation);
00227 void setTranslationAndRotationWithConstraint(Vec& translation, Quaternion& rotation);
00228
00235 Vec translation() const { return t_; };
00244 Quaternion rotation() const { return q_; };
00245
00246 void getTranslation(float& x, float& y, float& z) const;
00247 void getRotation(double& q0, double& q1, double& q2, double& q3) const;
00249
00250 public:
00269 const Frame* referenceFrame() const { return referenceFrame_; };
00270 void setReferenceFrame(const Frame* const refFrame);
00271 bool settingAsReferenceFrameWillCreateALoop(const Frame* const frame);
00273
00274
00277 void translate(Vec& t);
00278 void translate(const Vec& t);
00279
00280
00281 void translate(float x, float y, float z);
00282 void translate(float& x, float& y, float& z);
00283
00284 void rotate(Quaternion& q);
00285 void rotate(const Quaternion& q);
00286
00287
00288 void rotate(double q0, double q1, double q2, double q3);
00289 void rotate(double& q0, double& q1, double& q2, double& q3);
00290
00291 void rotateAroundPoint(Quaternion& rotation, const Vec& point);
00292 void rotateAroundPoint(const Quaternion& rotation, const Vec& point);
00293
00294 void alignWithFrame(const Frame* const frame, bool move=false, float threshold=0.85f);
00295 void projectOnLine(const Vec& origin, const Vec& direction);
00297
00298
00301 Vec coordinatesOf(const Vec& src) const;
00302 Vec inverseCoordinatesOf(const Vec& src) const;
00303 Vec localCoordinatesOf(const Vec& src) const;
00304 Vec localInverseCoordinatesOf(const Vec& src) const;
00305 Vec coordinatesOfIn(const Vec& src, const Frame* const in) const;
00306 Vec coordinatesOfFrom(const Vec& src, const Frame* const from) const;
00307
00308 void getCoordinatesOf(const float src[3], float res[3]) const;
00309 void getInverseCoordinatesOf(const float src[3], float res[3]) const;
00310 void getLocalCoordinatesOf(const float src[3], float res[3]) const;
00311 void getLocalInverseCoordinatesOf(const float src[3], float res[3]) const;
00312 void getCoordinatesOfIn(const float src[3], float res[3], const Frame* const in) const;
00313 void getCoordinatesOfFrom(const float src[3], float res[3], const Frame* const from) const;
00315
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00339 Vec transformOf(const Vec& src) const;
00340 Vec inverseTransformOf(const Vec& src) const;
00341 Vec localTransformOf(const Vec& src) const;
00342 Vec localInverseTransformOf(const Vec& src) const;
00343 Vec transformOfIn(const Vec& src, const Frame* const in) const;
00344 Vec transformOfFrom(const Vec& src, const Frame* const from) const;
00345
00346 void getTransformOf(const float src[3], float res[3]) const;
00347 void getInverseTransformOf(const float src[3], float res[3]) const;
00348 void getLocalTransformOf(const float src[3], float res[3]) const;
00349 void getLocalInverseTransformOf(const float src[3], float res[3]) const;
00350 void getTransformOfIn(const float src[3], float res[3], const Frame* const in) const;
00351 void getTransformOfFrom(const float src[3], float res[3], const Frame* const from) const;
00353
00354
00363 Constraint* constraint() const { return constraint_; }
00368 void setConstraint(Constraint* const constraint) { constraint_ = constraint; }
00370
00373 public:
00374 const GLdouble* matrix() const;
00375 void getMatrix(GLdouble m[4][4]) const;
00376 void getMatrix(GLdouble m[16]) const;
00377
00378 const GLdouble* worldMatrix() const;
00379 void getWorldMatrix(GLdouble m[4][4]) const;
00380 void getWorldMatrix(GLdouble m[16]) const;
00381
00382 void setFromMatrix(const GLdouble m[4][4]);
00383 void setFromMatrix(const GLdouble m[16]);
00385
00388 Frame inverse() const;
00397 Frame worldInverse() const { return Frame(-(orientation().inverseRotate(position())), orientation().inverse()); }
00399
00402 public:
00403 virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
00404 public Q_SLOTS:
00405 virtual void initFromDOMElement(const QDomElement& element);
00407
00408 private:
00409
00410 Vec t_;
00411 Quaternion q_;
00412
00413
00414 Constraint* constraint_;
00415
00416
00417 const Frame* referenceFrame_;
00418 };
00419
00420 }
00421
00422 #endif // QGLVIEWER_FRAME_H