#include "Viewer.h" #include #include #include #include #include using namespace X3DTK; using namespace std; Viewer::Viewer(const char *file) : normLength(1.0f), normal(false) { x3dfile = (char *)file; } Viewer::~Viewer() { // Releases scene graphs of scene. scene.release(); } void Viewer::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_L : loadFile(); break; case Qt::Key_N : normal = !normal; scene.setNormal(normal); break; case Qt::Key_Minus : normLength /= 2.0f; scene.setNormalLength(normLength); break; case Qt::Key_Plus : normLength *= 2.0f; scene.setNormalLength(normLength); 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); // 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]) ); showEntireScene(); } void Viewer::init() { #ifdef GL_RESCALE_NORMAL glEnable(GL_RESCALE_NORMAL); #endif about(); loadFile(); } void Viewer::draw() { // Draws the scene. scene.draw(); } void Viewer::about() { QMessageBox::about(this, "about the glNormalViewer", "this is an example showing how to create a new processor that displays the normals of a model.Type 'h' to display help"); } QString Viewer::helpString() const { QString message(""); message += "N" + QString(" enables or disables the display of normals
"); message += "+" + QString(" increases the length of normals
"); message += "-" + QString(" decreases the length of normals
"); 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(); }