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