History

Added LOD to preview + Shared voxelSystem for reduced memory consumption

atlante45 committed 13 years ago

Commit 1dc8d8d1 parent 7d9d36a10 files · +227 −104Browse files

Showing the changes to interface/src/ImportDialog.cpp (1 of 10 files). Show all

Unified · Split

interface/src/ImportDialog.cpp+112−12
@@ -34,9 +34,9 @@ const float FIELD_OF_VIEW = 60.0f; · 33 unmodified lines
3434
3535 class GLWidget : public QGLWidget {
3636 public:
37− GLWidget(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL);
37+ GLWidget(QWidget* parent = NULL);
3838 void setDraw(bool draw) {_draw = draw;}
39− void setTargetCenter(glm::vec3 targetCenter) {_targetCenter = targetCenter;}
39+ void setTargetCenter(glm::vec3 targetCenter) { _targetCenter = targetCenter; }
4040
4141 protected:
4242 virtual void initializeGL();
@@ -61,9 +61,8 @@ private: · 18 unmodified lines
6161 int _mouseY;
6262 };
6363
64−GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem)
64+GLWidget::GLWidget(QWidget *parent)
6565 : QGLWidget(parent, Application::getInstance()->getGLWidget()),
66− _voxelSystem(voxelSystem),
6766 _draw(false),
6867 _a(0.0f),
6968 _h(VERTICAL_ANGLE),
@@ -71,6 +70,7 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) · 1 unmodified line
7170 _pressed(false),
7271 _mouseX(0),
7372 _mouseY(0) {
73+ _voxelSystem = Application::getInstance()->getSharedVoxelSystem();
7474 }
7575
7676 void GLWidget::initializeGL() {
@@ -110,7 +110,7 @@ void GLWidget::paintGL() { · 33 unmodified lines
110110 UP_VECT.x, UP_VECT.y, UP_VECT.z);
111111
112112
113− if (_draw && _voxelSystem) {
113+ if (_draw) {
114114 glBegin(GL_LINES);
115115 glColor3d(1, 1 ,1);
116116 glVertex3d(0, 0, 0);
@@ -134,11 +134,109 @@ void GLWidget::paintGL() { · 17 unmodified lines
134134 glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 );
135135 glEnd();
136136
137+ glScalef(1.0f / TREE_SCALE, 1.0f / TREE_SCALE, 1.0f / TREE_SCALE);
138+
137139 _voxelSystem->render(false);
140+
141+
142+ ViewFrustum& viewFrustum = *Application::getInstance()->getSharedVoxelSystem()->getViewFrustum();
143+ glm::vec3 position = viewFrustum.getOffsetPosition();
144+ glm::vec3 direction = viewFrustum.getOffsetDirection();
145+ glm::vec3 up = viewFrustum.getOffsetUp();
146+ glm::vec3 right = viewFrustum.getOffsetRight();
147+
148+ // Calculate the origin direction vectors
149+ glm::vec3 lookingAt = position + (direction * 0.2f);
150+ glm::vec3 lookingAtUp = position + (up * 0.2f);
151+ glm::vec3 lookingAtRight = position + (right * 0.2f);
152+
153+ glBegin(GL_LINES);
154+ // Looking At = white
155+ glColor3d(1.0f, 1.0f, 1.0f);
156+ glVertex3d(position.x, position.y, position.z);
157+ glVertex3d(lookingAt.x, lookingAt.y, lookingAt.z);
158+
159+ // Looking At Up = purple
160+ glColor3d(1.0f, 0.0f, 1.0f);
161+ glVertex3d(position.x, position.y, position.z);
162+ glVertex3d(lookingAtUp.x, lookingAtUp.y, lookingAtUp.z);
163+
164+ // Looking At Right = cyan
165+ glColor3d(0.0f, 1.0f, 1.0f);
166+ glVertex3d(position.x, position.y, position.z);
167+ glVertex3d(lookingAtRight.x, lookingAtRight.y, lookingAtRight.z);
168+
169+
170+ // Drawing the bounds of the frustum
171+ // viewFrustum.getNear plane - bottom edge
172+ glColor3d(1.0f, 0.0f, 0.0f);
173+ glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
174+ glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
175+
176+ // viewFrustum.getNear plane - top edge
177+ glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
178+ glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
179+
180+ // viewFrustum.getNear plane - right edge
181+ glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
182+ glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
183+
184+ // viewFrustum.getNear plane - left edge
185+ glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
186+ glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
187+
188+
189+ // viewFrustum.getFar plane - bottom edge
190+ glColor3d(0.0f, 1.0f, 0.0f); // GREEN!!!
191+ glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
192+ glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
193+
194+ // viewFrustum.getFar plane - top edge
195+ glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
196+ glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
197+
198+ // viewFrustum.getFar plane - right edge
199+ glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
200+ glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
201+
202+ // viewFrustum.getFar plane - left edge
203+ glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
204+ glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
205+
206+ // RIGHT PLANE IS CYAN
207+ // right plane - bottom edge - viewFrustum.getNear to distant
208+ glColor3d(0.0f, 1.0f, 1.0f);
209+ glVertex3d(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z);
210+ glVertex3d(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z);
211+
212+ // right plane - top edge - viewFrustum.getNear to distant
213+ glVertex3d(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z);
214+ glVertex3d(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z);
215+
216+ // LEFT PLANE IS BLUE
217+ // left plane - bottom edge - viewFrustum.getNear to distant
218+ glColor3d(0.0f, 0.0f, 1.0f);
219+ glVertex3d(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z);
220+ glVertex3d(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z);
221+
222+ // left plane - top edge - viewFrustum.getNear to distant
223+ glVertex3d(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z);
224+ glVertex3d(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z);
225+ glEnd();
226+
227+ // Draw the keyhole
228+ float keyholeRadius = viewFrustum.getKeyholeRadius();
229+ if (keyholeRadius > 0.0f) {
230+ glPushMatrix();
231+ glColor3d(1.0f, 1.0f, 0.0f);
232+ glTranslatef(position.x, position.y, position.z); // where we actually want it!
233+ glutWireSphere(keyholeRadius, 20, 20);
234+ glPopMatrix();
235+ }
236+
138237 }
139238 }
140239
141−
142240 void GLWidget::mousePressEvent(QMouseEvent* event) {
143241 _pressed = true;
144242 _mouseX = event->globalX();
@@ -158,14 +256,13 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event) { · 13 unmodified lines
158256 _pressed = false;
159257 }
160258
161−ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem)
259+ImportDialog::ImportDialog(QWidget *parent)
162260 : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES),
163261 _importButton (IMPORT_BUTTON_NAME, this),
164262 _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this),
165263 _previewBox (PREVIEW_CHECKBOX_STRING, this),
166264 _previewBar (this),
167− _glPreview (new GLWidget(this, voxelSystem)) {
168−
265+ _glPreview (new GLWidget(this)) {
169266 setOption(QFileDialog::DontUseNativeDialog, true);
170267 setFileMode(QFileDialog::ExistingFile);
171268 setViewMode(QFileDialog::Detail);
@@ -188,15 +285,18 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) · 16 unmodified lines
188285
189286 connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
190287 connect(&_glTimer, SIGNAL(timeout()), SLOT(timer()));
191−
192− connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
193− connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
194288 }
195289
196290 ImportDialog::~ImportDialog() {
197291 delete _glPreview;
198292 }
199293
294+void ImportDialog::init() {
295+ VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem();
296+ connect(voxelSystem, SIGNAL(importSize(float,float,float)), SLOT(setGLCamera(float, float, float)));
297+ connect(voxelSystem, SIGNAL(importProgress(int)), &_previewBar, SLOT(setValue(int)));
298+}
299+
200300 void ImportDialog::import() {
201301 _importButton.setDisabled(true);
202302 _clipboardImportBox.setDisabled(true);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t