#include "Viewer.h" #include #include #include #include using namespace X3DTK; using namespace std; Viewer::Viewer(const char *file) { x3dfile = (char *)file; } Viewer::~Viewer() { scene.release(); } void Viewer::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_L : loadFile(); break; case Qt::Key_S : startAnimation(); break; case Qt::Key_P : stopAnimation(); break; default: QGLViewer::keyPressEvent(e); } updateGL(); } void Viewer::loadFile() { QString name = QFileDialog::getOpenFileName("", "X3D files (*.x3d *.X3D);;All files (*)", this); // In case of Cancel if (name.isEmpty()) return; // Loads the file name. scene.load(name, false); scene.init(); // QGLViewer settings. setSceneBoundingBox( qglviewer::Vec(scene.getBBoxMin()[0],scene.getBBoxMin()[1],scene.getBBoxMin()[2]), qglviewer::Vec(scene.getBBoxMax()[0],scene.getBBoxMax()[1],scene.getBBoxMax()[2]) ); setSceneRadius(2.0f*sceneRadius()); showEntireScene(); } void Viewer::init() { #ifdef GL_RESCALE_NORMAL glEnable(GL_RESCALE_NORMAL); #endif about(); loadFile(); } void Viewer::animate() { //Animates the scene. scene.animate(); } void Viewer::draw() { //traverse the scene graph scene.draw(); } void Viewer::about() { QMessageBox::about(this, "about the simpleAnimationViewer", "this is an example showing how to animate a simple X3D scene.Type 'h' to display help"); } QString Viewer::helpString() const { QString message(""); message += "S" + QString(" starts the animation
"); message += "P" + QString(" pauses the animation
"); message += "L" + QString(" loads a new file
"); message += QGLViewer::helpString(); return message; } void Viewer::help() const { QMessageBox *mb = new QMessageBox("help", helpString(), QMessageBox::NoIcon,QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton,QMessageBox::NoButton, NULL, "Help", false,Qt::WStyle_DialogBorder | Qt::WType_Dialog | Qt::WDestructiveClose); mb->show(); }