<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>libQGLViewer x3dViewer example</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../qglviewer.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="../images/qglviewer.ico" type="image/x-icon" /> <link rel="icon" href="../images/qglviewer.icon.png" type="image/png" /> </head> <body> <table class="banner"> <tr> <td align="center"><a href="../index.html"><b>Home</b></a></td> <td align="center"><a href="../refManual/hierarchy.html"><b>Documentation</b></a></td> <td align="center"><a href="../download.html"><b>Download</b></a></td> <td align="center" class="qindexHL"><a href="index.html"><b>Screenshots</b></a></td> <td align="center"><a href="../developer.html"><b>Developer</b></a></td> </tr> </table> <h1>The x3dViewer example</h1> <center> <img src="../images/x3dViewer.jpg" width="300" height="200" alt="x3dViewer"/> </center> <p> The X3D Toolkit library is used to load and display a x3d scene. </p> <p> You need to install the X3D library in order to compile this file. See the <a="http://www-artis.imag.fr/Members/Yannick.Legoc">Yannick Le Goc web site</a> (or <a="http://www-imagis.imag.fr/Membres/Yannick.Legoc/X3D/index.html">this page</a>). </p> <p> Once this is done, edit <code>x3dViewer.pro</code>, set <code>LIBX3D_IS_INSTALLED</code> to <code>yes</code> and set <code>INCLUDEPATH</code> and <code>LIBS</code> to the path where you installed libX3D. </p> <p> Press <b>L</b> (load) to load a new 3DS scene. </p> <h2>x3dViewer.h</h2> <pre> <span class="dir">#include <QGLViewer/qglviewer.h> </span><span class="dir">#include <X3DTK/simplex3dglscene.h> </span> <span class="key">class </span>Viewer : <span class="key">public </span>QGLViewer { <span class="key">protected </span>: <span class="key">virtual </span><span class="typ">void </span>init(); <span class="key">virtual </span><span class="typ">void </span>draw(); <span class="key">virtual </span><span class="typ">void </span>keyPressEvent(QKeyEvent *e); <span class="key">virtual </span>QString helpString() <span class="typ">const</span>; <span class="typ">void </span>loadFile(); <span class="key">private</span>: X3DTK::SimpleX3DGLScene scene; };</pre> <h2>x3dViewer.cpp</h2> <pre> <span class="dir">#include </span><span class="dstr">"x3dViewer.h"</span><span class="dir"> </span><span class="dir">#include <qfiledialog.h> </span> <span class="key">using namespace </span>X3DTK; <span class="key">using namespace </span>std; <span class="typ">void </span>Viewer::init() { <span class="dir">#ifdef GL_RESCALE_NORMAL </span> glEnable(GL_RESCALE_NORMAL); <span class="dir">#endif </span> loadFile(); help(); } <span class="typ">void </span>Viewer::keyPressEvent(QKeyEvent *e) { <span class="key">switch </span>(e->key()) { <span class="key">case </span>Qt::Key_L : loadFile(); <span class="key">break</span>; <span class="key">default</span>: QGLViewer::keyPressEvent(e); } } <span class="typ">void </span>Viewer::loadFile() { QString name = QFileDialog::getOpenFileName(<span class="str">""</span>, <span class="str">"X3D files (*.x3d *.X3D);;All files (*)"</span>, <span class="key">this</span>); <span class="com">// In case of Cancel </span> <span class="key">if </span>(name.isEmpty()) <span class="key">return</span>; <span class="com">/// Release previous scene. </span> scene.release(); <span class="com">/// Loads the scene, with no xml validation. </span> scene.load(name, <span class="key">false</span>); <span class="com">/// QGLViewer scene settings. </span> setSceneBoundingBox(scene.getBBoxMin().f_data(), scene.getBBoxMax().f_data()); showEntireScene(); } <span class="typ">void </span>Viewer::draw() { scene.draw(); } QString Viewer::helpString() <span class="typ">const </span>{ QString text(<span class="str">"<h2>x 3 d V i e w e r</h2>"</span>); text += <span class="str">"This example uses the libX3D library to load an x3d object file.<br>"</span>; text += <span class="str">"Press <b>L</b>(oad) to open an x3d file.<br><br>"</span>; text += QGLViewer::helpString(); <span class="key">return </span>text; }</pre> <h2>main.cpp</h2> <pre> <span class="dir">#include </span><span class="dstr">"x3dViewer.h"</span><span class="dir"> </span><span class="dir">#include <qapplication.h> </span> <span class="typ">int </span>main(<span class="typ">int </span>argc, <span class="typ">char</span>** argv) { <span class="com">// Read command lines arguments. </span> QApplication application(argc,argv); <span class="com">// Instantiate the viewer, show it on screen. </span> Viewer viewer; viewer.show(); <span class="com">// Set the viewer as the application main widget. </span> application.setMainWidget(&viewer); <span class="com">// Run main loop. </span> <span class="key">return </span>application.exec(); }</pre> <p> <a href="index.html">Go back</a> to the examples main page </p> <p> <a href="http://validator.w3.org/check/referer"><img src="../images/xhtml.png" alt="Valid XHTML 1.0!" height="31" width="88" border="0"/></a> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="../images/css.png" width="88" height="31" alt="Valid CSS!" border="0"/></a> <i>Last modified on Thursday, February 5, 2004.</i> </p> </body> </html>