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