Home | Documentation | Download | Screenshots | Developper |
The KeyFrameInterpolator test example.
KeyFrameInterpolator
smoothly interpolate their attached Frame over time on a path defined by Frames.
The interpolation can be started/stopped/reset, played in loop, played at a different speed,
etc...
In this examples, the path is defined by four ManipulatedFrame which all can be moved with the mouse. The interpolating path is updated accordingly.
The path and the interpolating axis are drawn using KeyFrameInterpoar::drawPath()
By default, the QGLViewer Camera holds 12 KeyFrameInterpolator, binded to the F1-12 keys. Use Alt-Fx to define a new keyFrame for path x, and simply press Fx to play/pause the path x. See the shortcuts page for details.
#include "qglviewer.h" class Viewer : public QGLViewer { public : Viewer(); protected : void draw(); void help(); void keyPressEvent(QKeyEvent *e); private : qglviewer::ManipulatedFrame** keyFrame_; qglviewer::KeyFrameInterpolator kfi_; const int nbKeyFrames; int currentKF_; };
#include "keyFrames.h" using namespace qglviewer; using namespace std; Viewer::Viewer() : nbKeyFrames(4) { kfi_.setFrame(new Frame()); kfi_.setLoopInterpolation(); keyFrame_ = new ManipulatedFrame*[nbKeyFrames]; // Create a random path for (int i=0; i<nbKeyFrames; i++) { keyFrame_[i] = new ManipulatedFrame(); keyFrame_[i]->setPosition(-1.0 + 2.0*i/(nbKeyFrames-1), 0.0, 0.0); kfi_.addKeyFrame(keyFrame_[i]); } kfi_.startInterpolation(); currentKF_ = 0; setManipulatedFrame(keyFrame_[currentKF_]); setMouseStateKey(QGLViewer::FRAME, Qt::NoButton); setMouseStateKey(QGLViewer::CAMERA, Qt::AltButton); help(); } void Viewer::help() { cout << endl << "\t\t- - K e y F r a m e s - -" << endl << endl; cout << "A frame is animated using a KeyFrameInterpolator" << endl; cout << "Use the left and right arrows to change the manipulated frame." << endl; cout << "+/- changes the interpolation speed." << endl; cout << "Return start-stops the interpolation." << endl; cout << "Press the Alt key to move the camera." << endl << endl; } void Viewer::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Left : currentKF_ = (currentKF_+nbKeyFrames-1) % nbKeyFrames; setManipulatedFrame(keyFrame_[currentKF_]); updateGL(); break; case Qt::Key_Right : currentKF_ = (currentKF_+1) % nbKeyFrames; setManipulatedFrame(keyFrame_[currentKF_]); updateGL(); break; case Qt::Key_Return : kfi_.toggleInterpolation(); break; case Qt::Key_Plus : kfi_.setInterpolationSpeed(kfi_.interpolationSpeed()+0.25); break; case Qt::Key_Minus : kfi_.setInterpolationSpeed(kfi_.interpolationSpeed()-0.25); break; // case Qt::Key_C : // kfi_.setClosedPath(!kfi_.closedPath()); // break; default: QGLViewer::keyPressEvent(e); } } void Viewer::draw() { glPushMatrix(); glMultMatrixd(kfi_.frame()->matrix()); drawAxis(0.3); glPopMatrix(); kfi_.drawPath(5, 15); for (int i=0; i<nbKeyFrames; i++) { glPushMatrix(); Frame frame; frame.setPosition(kfi_.keyFramePosition(i)); frame.setOrientation(kfi_.keyFrameOrientation(i)); glMultMatrixd(frame.matrix()); if (i == currentKF_) drawAxis(0.5); else drawAxis(0.3); glPopMatrix(); } }
#include "keyFrames.h" #include <qapplication.h> int main(int argc, char** argv) { // Read command lines arguments. QApplication application(argc,argv); // Instantiate the viewer, show it on screen. Viewer viewer; viewer.show(); // Set the viewer as the application main widget. application.setMainWidget(&viewer); // Run main loop. return application.exec(); }
Back to the main page