[1931] | 1 | // ===================================================================
|
---|
| 2 | // $Id$
|
---|
| 3 |
|
---|
| 4 | // Qt headers
|
---|
| 5 | #include <QtGui>
|
---|
| 6 | #include <QtOpenGL>
|
---|
| 7 |
|
---|
| 8 | // C++ standard headers
|
---|
| 9 | #include <cmath>
|
---|
| 10 |
|
---|
| 11 | // local headers
|
---|
| 12 | #include "common.h"
|
---|
| 13 | #include "QtGlViewer.h"
|
---|
| 14 | #include "QtGlRenderer.h"
|
---|
| 15 | #include "Trackball.h"
|
---|
| 16 | #include "RssPreprocessor.h"
|
---|
| 17 | #include "SceneGraph.h"
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | namespace GtpVisibilityPreprocessor {
|
---|
| 21 |
|
---|
| 22 | QtGlRendererWidget *renderer;
|
---|
| 23 |
|
---|
| 24 | QtGlViewer::QtGlViewer(QWidget *parent,
|
---|
| 25 | QtGlRendererWidget *renderer):
|
---|
| 26 | QGLWidget(parent), mRenderer(renderer)
|
---|
| 27 | {
|
---|
| 28 | scale = 1.0f;
|
---|
| 29 | mWireframe = false;
|
---|
| 30 | trackball(manipulatorLastQuat, 0.0f, 0.0f, 0.0f, 0.0f);
|
---|
| 31 | connect(renderer, SIGNAL(PvsUpdated()), this, SLOT(updateGL()));
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | QSize
|
---|
| 35 | QtGlViewer::minimumSizeHint() const
|
---|
| 36 | {
|
---|
| 37 | return QSize(100, 100);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | QSize
|
---|
| 41 | QtGlViewer::sizeHint() const {
|
---|
| 42 | return QSize(500, 500);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | // This method has to be rendefined by all renderer implementations
|
---|
| 46 | void
|
---|
| 47 | QtGlViewer::RenderScene()
|
---|
| 48 | {
|
---|
| 49 | mRenderer->mFrame++;
|
---|
| 50 |
|
---|
| 51 | // render into the right side of the window buffer
|
---|
| 52 | if (mRenderer->mRenderViewCells)
|
---|
| 53 | mRenderer->RenderViewCells();
|
---|
| 54 |
|
---|
| 55 | mRenderer->RenderPvs();
|
---|
[1983] | 56 |
|
---|
| 57 | mRenderer->RenderViewPoint();
|
---|
| 58 |
|
---|
[1931] | 59 |
|
---|
| 60 | // if (mRenderer->mShowRays) {
|
---|
| 61 | // RssPreprocessor *p = (RssPreprocessor *)
|
---|
| 62 | // mRenderer->mViewCellsManager->GetPreprocessor();
|
---|
| 63 | // if (p->mRssTree) {
|
---|
| 64 | // VssRayContainer rays;
|
---|
| 65 | // p->mRssTree->CollectRays(rays, 10000);
|
---|
| 66 | // mRenderer->RenderRays(rays);
|
---|
| 67 | // }
|
---|
| 68 | // }
|
---|
| 69 |
|
---|
| 70 | if (mRenderer->mShowRenderCost)
|
---|
| 71 | mRenderer->RenderRenderCost();
|
---|
| 72 |
|
---|
| 73 | glColor3f(1.0f, 1.0f, 1.0f);
|
---|
| 74 | mRenderer->RenderInfo();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | void
|
---|
| 79 | QtGlViewer::initializeGL()
|
---|
| 80 | {
|
---|
| 81 | const char *vendorString, *rendererString, *versionString, *extString;
|
---|
| 82 |
|
---|
| 83 | // get GL info
|
---|
| 84 | vendorString = (const char *) glGetString(GL_VENDOR);
|
---|
| 85 | rendererString = (const char *) glGetString(GL_RENDERER);
|
---|
| 86 | versionString = (const char *) glGetString(GL_VERSION);
|
---|
| 87 | extString = (const char *) glGetString(GL_EXTENSIONS);
|
---|
| 88 |
|
---|
| 89 | Debug << "Info: GL Vendor = "<<vendorString<<endl
|
---|
| 90 | << "Info: GL Renderer = "<<rendererString<<endl
|
---|
| 91 | << "Info: GL Version = "<<versionString<<endl
|
---|
| 92 | << "Info: GL Extensions = "<<extString<<endl<<flush;
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | return;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | void
|
---|
| 99 | QtGlViewer::paintGL()
|
---|
| 100 | {
|
---|
| 101 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 102 | glLoadIdentity();
|
---|
| 103 |
|
---|
| 104 | float m[4][4];
|
---|
| 105 |
|
---|
| 106 | glLoadIdentity();
|
---|
| 107 | gluLookAt(0.0, 0.0, 1.0, /* eye is at (0,0,30) */
|
---|
| 108 | 0.0, 0.0, 0.0, /* center is at (0,0,0) */
|
---|
| 109 | 0.0, 1.0, 0.); /* up is in positive Y direction */
|
---|
| 110 |
|
---|
| 111 | build_rotmatrix(m, manipulatorLastQuat);
|
---|
| 112 | glMultMatrixf(&m[0][0]);
|
---|
| 113 |
|
---|
| 114 | float s = scale*20.0f/Magnitude(mRenderer->mSceneGraph->GetBox().Diagonal());
|
---|
| 115 | glScalef(s, s, s);
|
---|
| 116 |
|
---|
| 117 | Vector3 t = -mRenderer->mSceneGraph->GetBox().Center();
|
---|
| 118 | glTranslatef(t.x, t.y, t.z);
|
---|
| 119 |
|
---|
| 120 | RenderScene();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | void
|
---|
| 124 | QtGlViewer::resizeGL(int width, int height)
|
---|
| 125 | {
|
---|
| 126 | glViewport(0, 0, width, height);
|
---|
| 127 |
|
---|
| 128 | glMatrixMode(GL_PROJECTION);
|
---|
| 129 | glLoadIdentity();
|
---|
| 130 | gluPerspective(70.0, 1.0, 0.1, 100.0);
|
---|
| 131 | // glOrtho(-0.5*width/height, +0.5*width/height, 0.5, -0.5, 4.0, 15.0);
|
---|
| 132 | glMatrixMode(GL_MODELVIEW);
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | void
|
---|
| 137 | QtGlViewer::mousePressEvent(QMouseEvent *event)
|
---|
| 138 | {
|
---|
| 139 | lastPos = event->pos();
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | void
|
---|
| 143 | QtGlViewer::keyPressEvent ( QKeyEvent * e )
|
---|
| 144 | {
|
---|
| 145 | switch (e->key()) {
|
---|
| 146 | case Qt::Key_W:
|
---|
| 147 | mWireframe = !mWireframe;
|
---|
| 148 | updateGL();
|
---|
| 149 | default:
|
---|
| 150 | e->ignore();
|
---|
| 151 | break;
|
---|
| 152 | }
|
---|
| 153 | updateGL();
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | void
|
---|
| 157 | QtGlViewer::mouseMoveEvent(QMouseEvent *event)
|
---|
| 158 | {
|
---|
| 159 | int dx = event->x() - lastPos.x();
|
---|
| 160 | int dy = event->y() - lastPos.y();
|
---|
| 161 |
|
---|
| 162 | if (event->modifiers() & Qt::CTRL)
|
---|
| 163 | {
|
---|
| 164 | scale = scale*(1.0f - dy/(float)height());
|
---|
[1936] | 165 | if (scale < 0.01f)
|
---|
| 166 | scale = 0.01f;
|
---|
[1931] | 167 | updateGL();
|
---|
| 168 | }
|
---|
| 169 | else {
|
---|
| 170 | float W = width();
|
---|
| 171 | float H = height();
|
---|
| 172 | int x = event->x();
|
---|
| 173 | int lastX = lastPos.x();
|
---|
| 174 | int y = event->y();
|
---|
| 175 | int lastY = lastPos.y();
|
---|
| 176 |
|
---|
| 177 | float quat[4];
|
---|
| 178 | trackball(quat,
|
---|
| 179 | (2.0 * lastX - W) / W,
|
---|
| 180 | (H - 2.0 * lastY) / H,
|
---|
| 181 | (2.0 * x - W) / W,
|
---|
| 182 | (H - 2.0 * y) / H
|
---|
| 183 | );
|
---|
| 184 | add_quats(quat, manipulatorLastQuat, manipulatorLastQuat);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | lastPos = event->pos();
|
---|
[1972] | 188 | updateGL();
|
---|
[1931] | 189 | }
|
---|
[1969] | 190 |
|
---|
[1931] | 191 | }
|
---|
[1936] | 192 |
|
---|