Showing the changes to interface/src/ImportDialog.cpp (1 of 10 files). Show all
Unified · Split
| @@ -34,9 +34,9 @@ const float FIELD_OF_VIEW = 60.0f; · 33 unmodified lines | |||
| 34 | 34 | ||
| 35 | class GLWidget : public QGLWidget { | 35 | class GLWidget : public QGLWidget { |
| 36 | public: | 36 | public: |
| 37 | GLWidget(QWidget* parent = NULL, VoxelSystem* voxelSystem = NULL); | 37 | GLWidget(QWidget* parent = NULL); |
| 38 | void setDraw(bool draw) {_draw = draw;} | 38 | void setDraw(bool draw) {_draw = draw;} |
| 39 | void setTargetCenter(glm::vec3 targetCenter) {_targetCenter = targetCenter;} | 39 | void setTargetCenter(glm::vec3 targetCenter) { _targetCenter = targetCenter; } |
| 40 | 40 | ||
| 41 | protected: | 41 | protected: |
| 42 | virtual void initializeGL(); | 42 | virtual void initializeGL(); |
| @@ -61,9 +61,8 @@ private: · 18 unmodified lines | |||
| 61 | int _mouseY; | 61 | int _mouseY; |
| 62 | }; | 62 | }; |
| 63 | 63 | ||
| 64 | GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) | 64 | GLWidget::GLWidget(QWidget *parent) |
| 65 | : QGLWidget(parent, Application::getInstance()->getGLWidget()), | 65 | : QGLWidget(parent, Application::getInstance()->getGLWidget()), |
| 66 | _voxelSystem(voxelSystem), | ||
| 67 | _draw(false), | 66 | _draw(false), |
| 68 | _a(0.0f), | 67 | _a(0.0f), |
| 69 | _h(VERTICAL_ANGLE), | 68 | _h(VERTICAL_ANGLE), |
| @@ -71,6 +70,7 @@ GLWidget::GLWidget(QWidget *parent, VoxelSystem *voxelSystem) · 1 unmodified line | |||
| 71 | _pressed(false), | 70 | _pressed(false), |
| 72 | _mouseX(0), | 71 | _mouseX(0), |
| 73 | _mouseY(0) { | 72 | _mouseY(0) { |
| 73 | _voxelSystem = Application::getInstance()->getSharedVoxelSystem(); | ||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | void GLWidget::initializeGL() { | 76 | void GLWidget::initializeGL() { |
| @@ -110,7 +110,7 @@ void GLWidget::paintGL() { · 33 unmodified lines | |||
| 110 | UP_VECT.x, UP_VECT.y, UP_VECT.z); | 110 | UP_VECT.x, UP_VECT.y, UP_VECT.z); |
| 111 | 111 | ||
| 112 | 112 | ||
| 113 | if (_draw && _voxelSystem) { | 113 | if (_draw) { |
| 114 | glBegin(GL_LINES); | 114 | glBegin(GL_LINES); |
| 115 | glColor3d(1, 1 ,1); | 115 | glColor3d(1, 1 ,1); |
| 116 | glVertex3d(0, 0, 0); | 116 | glVertex3d(0, 0, 0); |
| @@ -134,11 +134,109 @@ void GLWidget::paintGL() { · 17 unmodified lines | |||
| 134 | glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 ); | 134 | glVertex3d(2 * _targetCenter.x, 2 * _targetCenter.y, 0 ); |
| 135 | glEnd(); | 135 | glEnd(); |
| 136 | 136 | ||
| 137 | glScalef(1.0f / TREE_SCALE, 1.0f / TREE_SCALE, 1.0f / TREE_SCALE); | ||
| 138 | |||
| 137 | _voxelSystem->render(false); | 139 | _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 | |||
| 138 | } | 237 | } |
| 139 | } | 238 | } |
| 140 | 239 | ||
| 141 | |||
| 142 | void GLWidget::mousePressEvent(QMouseEvent* event) { | 240 | void GLWidget::mousePressEvent(QMouseEvent* event) { |
| 143 | _pressed = true; | 241 | _pressed = true; |
| 144 | _mouseX = event->globalX(); | 242 | _mouseX = event->globalX(); |
| @@ -158,14 +256,13 @@ void GLWidget::mouseReleaseEvent(QMouseEvent* event) { · 13 unmodified lines | |||
| 158 | _pressed = false; | 256 | _pressed = false; |
| 159 | } | 257 | } |
| 160 | 258 | ||
| 161 | ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) | 259 | ImportDialog::ImportDialog(QWidget *parent) |
| 162 | : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES), | 260 | : QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, IMPORT_FILE_TYPES), |
| 163 | _importButton (IMPORT_BUTTON_NAME, this), | 261 | _importButton (IMPORT_BUTTON_NAME, this), |
| 164 | _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this), | 262 | _clipboardImportBox(IMPORT_TO_CLIPBOARD_CHECKBOX_STRING, this), |
| 165 | _previewBox (PREVIEW_CHECKBOX_STRING, this), | 263 | _previewBox (PREVIEW_CHECKBOX_STRING, this), |
| 166 | _previewBar (this), | 264 | _previewBar (this), |
| 167 | _glPreview (new GLWidget(this, voxelSystem)) { | 265 | _glPreview (new GLWidget(this)) { |
| 168 | |||
| 169 | setOption(QFileDialog::DontUseNativeDialog, true); | 266 | setOption(QFileDialog::DontUseNativeDialog, true); |
| 170 | setFileMode(QFileDialog::ExistingFile); | 267 | setFileMode(QFileDialog::ExistingFile); |
| 171 | setViewMode(QFileDialog::Detail); | 268 | setViewMode(QFileDialog::Detail); |
| @@ -188,15 +285,18 @@ ImportDialog::ImportDialog(QWidget *parent, VoxelSystem* voxelSystem) · 16 unmodified lines | |||
| 188 | 285 | ||
| 189 | connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); | 286 | connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString))); |
| 190 | connect(&_glTimer, SIGNAL(timeout()), SLOT(timer())); | 287 | 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))); | ||
| 194 | } | 288 | } |
| 195 | 289 | ||
| 196 | ImportDialog::~ImportDialog() { | 290 | ImportDialog::~ImportDialog() { |
| 197 | delete _glPreview; | 291 | delete _glPreview; |
| 198 | } | 292 | } |
| 199 | 293 | ||
| 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 | |||
| 200 | void ImportDialog::import() { | 300 | void ImportDialog::import() { |
| 201 | _importButton.setDisabled(true); | 301 | _importButton.setDisabled(true); |
| 202 | _clipboardImportBox.setDisabled(true); | 302 | _clipboardImportBox.setDisabled(true); |