[4] | 1 | #include "ProjectionModel.h" |
---|
| 2 | #include <QMessageBox> |
---|
| 3 | #include <QGLPixelBuffer> |
---|
| 4 | |
---|
| 5 | #include "Scene.h" |
---|
| 6 | #include "Screen.h" |
---|
| 7 | #include "Channel.h" |
---|
| 8 | #pragma warning(disable: 4003) |
---|
| 9 | #include "gmtl/gmtl.h" |
---|
| 10 | #include "gui/QDesignViewWidget.h" |
---|
| 11 | |
---|
| 12 | using namespace projection; |
---|
| 13 | using namespace gmtl; |
---|
| 14 | |
---|
| 15 | QDesignViewWidget::QDesignViewWidget(QWidget* pParent, const QGLWidget* pSharedWidget, Qt::WFlags flags) |
---|
| 16 | : QGLViewerWidget(pParent, pSharedWidget, flags) |
---|
| 17 | { |
---|
| 18 | m_pModel = NULL; |
---|
| 19 | |
---|
| 20 | m_viewMode = DESIGN_VIEWMODE_PERSPECTIVE; |
---|
| 21 | m_opMode = DESIGN_OPMODE_PROJECTOR; |
---|
| 22 | m_transMode = DESIGN_TRANSMODE_LOCAL; |
---|
| 23 | |
---|
| 24 | m_bAxisVisible = true; |
---|
| 25 | m_bGridVisible = true; |
---|
| 26 | m_bInfoVisible = true; |
---|
| 27 | |
---|
| 28 | m_gridSize = 2.0f; |
---|
| 29 | |
---|
| 30 | m_infoFont.setFamily("Helvetica"); |
---|
| 31 | m_infoFont.setPointSize(14); |
---|
| 32 | |
---|
| 33 | if (!QGLPixelBuffer::hasOpenGLPbuffers()) |
---|
| 34 | QMessageBox::critical(this, APPLICATION_NAME, |
---|
| 35 | tr("%1 requires OpenGL P-Buffer feature.").arg(APPLICATION_NAME)); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | void QDesignViewWidget::init() |
---|
| 39 | { |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | QDesignViewWidget::~QDesignViewWidget() |
---|
| 43 | { |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | void QDesignViewWidget::setModel(ProjectionModel* pModel) |
---|
| 47 | { |
---|
| 48 | m_pModel = pModel; |
---|
| 49 | |
---|
| 50 | setSceneSize(m_pModel->getScreen()->getSize() * 5.0f); |
---|
| 51 | setView(Vec3f(), |
---|
| 52 | makeRot<Quatf>(AxisAnglef(Math::deg2Rad(45.0f), Vec3f(0.0f, 1.0f, 0.0f))) * |
---|
| 53 | makeRot<Quatf>(AxisAnglef(Math::deg2Rad(-30.0f), Vec3f(1.0f, 0.0f, 0.0f))), |
---|
| 54 | sceneSize()*0.5f); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void QDesignViewWidget::draw() |
---|
| 58 | { |
---|
| 59 | if (!isVisible()) return; |
---|
| 60 | |
---|
| 61 | m_pModel->setRenderContext(this); |
---|
| 62 | |
---|
| 63 | m_sceneSize = m_pModel->getScreen()->getSize() * 5.0f; |
---|
| 64 | |
---|
| 65 | glViewport(0, 0, width(), height()); |
---|
| 66 | |
---|
| 67 | glEnable(GL_COLOR_MATERIAL); |
---|
| 68 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
| 69 | |
---|
| 70 | if (m_pModel->getScene()->getShowInDesignView()) |
---|
| 71 | { |
---|
| 72 | glPushMatrix(); |
---|
| 73 | glMultMatrixf(invert(m_pModel->getScene()->getCameraMatrix()).getData()); |
---|
| 74 | m_pModel->getScene()->draw(); |
---|
| 75 | glPopMatrix(); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | glPushMatrix(); |
---|
| 79 | m_pModel->getScreen()->draw(); |
---|
| 80 | m_pModel->getScreen()->drawFrame(); |
---|
| 81 | for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i) |
---|
| 82 | { |
---|
| 83 | if (m_pModel->getChannel(i)->getProjector()->getShowArea()) |
---|
| 84 | m_pModel->getScreen()->draw(PROJECT_SOURCE_PROJECTORAREA, m_pModel->getChannel(i)); |
---|
| 85 | if (m_pModel->getChannel(i)->getView()->getShowArea()) |
---|
| 86 | m_pModel->getScreen()->draw(PROJECT_SOURCE_VIEWAREA, m_pModel->getChannel(i)); |
---|
| 87 | if (m_pModel->getChannel(i)->getShowProjectedScene()) |
---|
| 88 | m_pModel->getScreen()->draw(PROJECT_SOURCE_SCENE, m_pModel->getChannel(i)); |
---|
| 89 | makeCurrent(); |
---|
| 90 | } |
---|
| 91 | glPopMatrix(); |
---|
| 92 | |
---|
| 93 | for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i) |
---|
| 94 | { |
---|
| 95 | glPushMatrix(); |
---|
| 96 | m_pModel->getChannel(i)->drawFrustums(m_pModel->getChannel(i)==m_pModel->getSelectedChannel()); |
---|
| 97 | glPopMatrix(); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 101 | glDisable(GL_LIGHTING); |
---|
| 102 | for (unsigned int i=0; i<m_pModel->getNumChannels(); ++i) |
---|
| 103 | { |
---|
| 104 | if (m_pModel->getChannel(i)->getProjector()->getShow()) |
---|
| 105 | { |
---|
| 106 | glPushMatrix(); |
---|
| 107 | glMultMatrixf(m_pModel->getChannel(i)->getProjectorTransformMatrix().getMatrix().getData()); |
---|
| 108 | glTranslatef(0.0f, 0.0f, 0.05f); |
---|
| 109 | renderText(0, 0, 0, m_pModel->getChannel(i)->getName(), m_infoFont, 5000); |
---|
| 110 | glPopMatrix(); |
---|
| 111 | } |
---|
| 112 | if (m_pModel->getChannel(i)->getView()->getShow()) |
---|
| 113 | { |
---|
| 114 | glPushMatrix(); |
---|
| 115 | glMultMatrixf(m_pModel->getChannel(i)->getView()->getTransformMatrix().getMatrix().getData()); |
---|
| 116 | glTranslatef(0.0f, 0.0f, 0.05f); |
---|
| 117 | renderText(0, 0, 0, m_pModel->getChannel(i)->getName(), m_infoFont, 5000); |
---|
| 118 | glPopMatrix(); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | glPopAttrib(); |
---|
| 122 | |
---|
| 123 | if (m_bInfoVisible) |
---|
| 124 | { |
---|
| 125 | glDisable(GL_LIGHTING); |
---|
| 126 | |
---|
| 127 | int x = int(m_infoFont.pointSize() * 0.5); |
---|
| 128 | int y = int(m_infoFont.pointSize() * 1.5); |
---|
| 129 | int yoffset = int(m_infoFont.pointSize() * 1.5); |
---|
| 130 | switch (m_viewMode) |
---|
| 131 | { |
---|
| 132 | case DESIGN_VIEWMODE_PERSPECTIVE: |
---|
| 133 | renderText(x, y, QString("View Mode: Perspective"), m_infoFont); y += yoffset; break; |
---|
| 134 | case DESIGN_VIEWMODE_CENTER: |
---|
| 135 | renderText(x, y, QString("View Mode: Center"), m_infoFont); y += yoffset; break; |
---|
| 136 | case DESIGN_VIEWMODE_TOP: |
---|
| 137 | renderText(x, y, QString("View Mode: Top"), m_infoFont); y += yoffset; break; |
---|
| 138 | case DESIGN_VIEWMODE_SIDE: |
---|
| 139 | renderText(x, y, QString("View Mode: Side"), m_infoFont); y += yoffset; break; |
---|
| 140 | case DESIGN_VIEWMODE_FRONT: |
---|
| 141 | renderText(x, y, QString("View Mode: Front"), m_infoFont); y += yoffset; break; |
---|
| 142 | } |
---|
| 143 | renderText(x, y, QString("Operation Mode: %1").arg(m_opMode==DESIGN_OPMODE_PROJECTOR?"Projector":"View"), m_infoFont); y += yoffset; |
---|
| 144 | renderText(x, y, QString("Translation Mode: %1").arg(m_transMode==DESIGN_TRANSMODE_LOCAL?"Local":"World"), m_infoFont); y += yoffset; |
---|
| 145 | if (m_pModel->getSelectedChannel()) |
---|
| 146 | renderText(x, y, QString("Channel: %1").arg(m_pModel->getSelectedChannel()->getName()), m_infoFont); y += yoffset; |
---|
| 147 | |
---|
| 148 | #ifdef _DEBUG |
---|
| 149 | renderText(x, y, QString("UpdateViews: %1").arg(m_pModel->m_updateViewsCount), m_infoFont); y += yoffset; |
---|
| 150 | renderText(x, y, QString("UpdateOffscreen: %1").arg(m_pModel->m_updateOffscreenCount), m_infoFont); y += yoffset; |
---|
| 151 | #endif // _DEBUG |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void QDesignViewWidget::setViewMode(DESIGN_VIEWMODE viewMode) |
---|
| 156 | { |
---|
| 157 | if (m_viewMode == viewMode) |
---|
| 158 | return; |
---|
| 159 | |
---|
| 160 | if (viewMode == DESIGN_VIEWMODE_PERSPECTIVE) |
---|
| 161 | { |
---|
| 162 | setPerspective(true); |
---|
| 163 | viewAll(); |
---|
| 164 | } |
---|
| 165 | else if (viewMode == DESIGN_VIEWMODE_CENTER) |
---|
| 166 | { |
---|
| 167 | setPerspective(true); |
---|
| 168 | setView(Vec3f(), Quatf(), 0.0f); |
---|
| 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
| 172 | switch (viewMode) |
---|
| 173 | { |
---|
| 174 | case DESIGN_VIEWMODE_TOP: |
---|
| 175 | setView(Vec3f(), makeRot<Quatf>(AxisAnglef(Math::deg2Rad(-90.0f), Vec3f(1.0f, 0.0f, 0.0f))), 0.0f); |
---|
| 176 | break; |
---|
| 177 | case DESIGN_VIEWMODE_SIDE: |
---|
| 178 | setView(Vec3f(), makeRot<Quatf>(AxisAnglef(Math::deg2Rad(90.0f), Vec3f(0.0f, 1.0f, 0.0f))), 0.0f); |
---|
| 179 | break; |
---|
| 180 | case DESIGN_VIEWMODE_FRONT: |
---|
| 181 | setView(Vec3f(), Quatf(), 0.0f); |
---|
| 182 | break; |
---|
| 183 | } |
---|
| 184 | setPerspective(false); |
---|
| 185 | viewAll(); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | m_viewMode = viewMode; |
---|
| 189 | |
---|
| 190 | updateGL(); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | DESIGN_VIEWMODE QDesignViewWidget::getViewMode() const |
---|
| 194 | { |
---|
| 195 | return m_viewMode; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | void QDesignViewWidget::setOpMode(DESIGN_OPMODE opMode) |
---|
| 199 | { |
---|
| 200 | m_opMode = opMode; |
---|
| 201 | updateGL(); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | DESIGN_OPMODE QDesignViewWidget::getOpMode() const |
---|
| 205 | { |
---|
| 206 | return m_opMode; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void QDesignViewWidget::setTransMode(DESIGN_TRANSMODE transMode) |
---|
| 210 | { |
---|
| 211 | m_transMode = transMode; |
---|
| 212 | updateGL(); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | DESIGN_TRANSMODE QDesignViewWidget::getTransMode() const |
---|
| 216 | { |
---|
| 217 | return m_transMode; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | void QDesignViewWidget::setInfoVisible(bool bVisible) |
---|
| 221 | { |
---|
| 222 | if (m_bInfoVisible != bVisible) |
---|
| 223 | { |
---|
| 224 | m_bInfoVisible = bVisible; |
---|
| 225 | updateGL(); |
---|
| 226 | infoVisibilityChanged(bVisible); |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | bool QDesignViewWidget::isInfoVisible() const |
---|
| 231 | { |
---|
| 232 | return m_bInfoVisible; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | void QDesignViewWidget::keyReleaseEvent(QKeyEvent* pEvent) |
---|
| 236 | { |
---|
| 237 | QGLViewerWidget::keyReleaseEvent(pEvent); |
---|
| 238 | |
---|
| 239 | switch (pEvent->key()) |
---|
| 240 | { |
---|
| 241 | case Qt::Key_I: |
---|
| 242 | setInfoVisible(!isInfoVisible()); |
---|
| 243 | break; |
---|
| 244 | case Qt::Key_F1: |
---|
| 245 | setViewMode(DESIGN_VIEWMODE_PERSPECTIVE); |
---|
| 246 | break; |
---|
| 247 | case Qt::Key_F2: |
---|
| 248 | setViewMode(DESIGN_VIEWMODE_CENTER); |
---|
| 249 | break; |
---|
| 250 | case Qt::Key_F3: |
---|
| 251 | setViewMode(DESIGN_VIEWMODE_TOP); |
---|
| 252 | break; |
---|
| 253 | case Qt::Key_F4: |
---|
| 254 | setViewMode(DESIGN_VIEWMODE_SIDE); |
---|
| 255 | break; |
---|
| 256 | case Qt::Key_F5: |
---|
| 257 | setViewMode(DESIGN_VIEWMODE_FRONT); |
---|
| 258 | break; |
---|
| 259 | case Qt::Key_Space: |
---|
| 260 | m_pModel->selectNextChannel(); |
---|
| 261 | break; |
---|
| 262 | default: |
---|
| 263 | break; |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | if (!m_pModel->getSelectedChannel()) |
---|
| 267 | return; |
---|
| 268 | |
---|
| 269 | processChannelKeyEvent(m_pModel->getSelectedChannel(), pEvent); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | void QDesignViewWidget::processChannelKeyEvent(Channel* pChannel, QKeyEvent* pEvent) |
---|
| 273 | { |
---|
| 274 | #if 1 |
---|
| 275 | Q_UNUSED(pChannel); |
---|
| 276 | Q_UNUSED(pEvent); |
---|
| 277 | #else |
---|
| 278 | if (!pChannel) |
---|
| 279 | return; |
---|
| 280 | |
---|
| 281 | bool bShift = (pEvent->modifiers() & Qt::ShiftModifier); |
---|
| 282 | #ifdef WIN32 |
---|
| 283 | bShift = (GetAsyncKeyState(VK_SHIFT)<0); |
---|
| 284 | #endif // WIN32 |
---|
| 285 | bool bCtrl = (pEvent->modifiers() & Qt::ControlModifier); |
---|
| 286 | // bool bAlt = (pEvent->modifiers() & Qt::AltModifier); |
---|
| 287 | bool bKeypad = (pEvent->modifiers() & Qt::KeypadModifier); |
---|
| 288 | #ifdef WIN32 |
---|
| 289 | bool bCapsLock = false; // <-- Careful, bCapsLock is not used. |
---|
| 290 | bCapsLock = (GetAsyncKeyState(VK_CAPITAL) < 0); |
---|
| 291 | #endif // WIN32 |
---|
| 292 | |
---|
| 293 | float step = 1.0f; |
---|
| 294 | if (bShift && bCtrl) |
---|
| 295 | step = 0.01f; |
---|
| 296 | else if (bShift || bCtrl) |
---|
| 297 | step = 0.1f; |
---|
| 298 | |
---|
| 299 | Frustum* pFrustum = pChannel->getProjector(); |
---|
| 300 | if (m_opMode == DESIGN_OPMODE_VIEW) |
---|
| 301 | pFrustum = pChannel->getView(); |
---|
| 302 | |
---|
| 303 | ProjectionMatrix projMatrix = pFrustum->getProjectionMatrix(); |
---|
| 304 | TransformMatrix xformMatrix = pFrustum->getTransformMatrix(); |
---|
| 305 | gmtl::Vec3f pos = xformMatrix.getPosition(); |
---|
| 306 | gmtl::Vec3f rot = xformMatrix.getRotation(); |
---|
| 307 | gmtl::Quatf quatRot = gmtl::makeRot<gmtl::Quatf>(xformMatrix.getMatrix()); |
---|
| 308 | |
---|
| 309 | if (bKeypad) |
---|
| 310 | { |
---|
| 311 | switch (pEvent->key()) |
---|
| 312 | { |
---|
| 313 | case Qt::Key_8: |
---|
| 314 | case Qt::Key_Up: |
---|
| 315 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
| 316 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1], pos[2]-0.1f*step)); |
---|
| 317 | else |
---|
| 318 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, 0.0f, -0.1f*step)); |
---|
| 319 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 320 | break; |
---|
| 321 | case Qt::Key_2: |
---|
| 322 | case Qt::Key_Down: |
---|
| 323 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
| 324 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1], pos[2]+0.1f*step)); |
---|
| 325 | else |
---|
| 326 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, 0.0f, 0.1f*step)); |
---|
| 327 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 328 | break; |
---|
| 329 | case Qt::Key_6: |
---|
| 330 | case Qt::Key_Right: |
---|
| 331 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
| 332 | xformMatrix.setPosition(gmtl::Vec3f(pos[0]+0.1f*step, pos[1], pos[2])); |
---|
| 333 | else |
---|
| 334 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.1f*step, 0.0f, 0.0f)); |
---|
| 335 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 336 | break; |
---|
| 337 | case Qt::Key_4: |
---|
| 338 | case Qt::Key_Left: |
---|
| 339 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
| 340 | xformMatrix.setPosition(gmtl::Vec3f(pos[0]-0.1f*step, pos[1], pos[2])); |
---|
| 341 | else |
---|
| 342 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(-0.1f*step, 0.0f, 0.0f)); |
---|
| 343 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 344 | break; |
---|
| 345 | case Qt::Key_9: |
---|
| 346 | case Qt::Key_PageUp: |
---|
| 347 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
| 348 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]+0.1f*step, pos[2])); |
---|
| 349 | else |
---|
| 350 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, 0.1f*step, 0.0f)); |
---|
| 351 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 352 | break; |
---|
| 353 | case Qt::Key_3: |
---|
| 354 | case Qt::Key_PageDown: |
---|
| 355 | if (m_transMode == DESIGN_TRANSMODE_WORLD) |
---|
| 356 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]-0.1f*step, pos[2])); |
---|
| 357 | else |
---|
| 358 | xformMatrix.setPosition(pos + quatRot * gmtl::Vec3f(0.0f, -0.1f*step, 0.0f)); |
---|
| 359 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 360 | break; |
---|
| 361 | case Qt::Key_Plus: |
---|
| 362 | projMatrix.setOffaxisY(projMatrix.getOffaxisY()-0.01f*step); |
---|
| 363 | pFrustum->setProjectionMatrix(projMatrix); |
---|
| 364 | break; |
---|
| 365 | case Qt::Key_Minus: |
---|
| 366 | projMatrix.setOffaxisY(projMatrix.getOffaxisY()+0.01f*step); |
---|
| 367 | pFrustum->setProjectionMatrix(projMatrix); |
---|
| 368 | break; |
---|
| 369 | case Qt::Key_Asterisk: |
---|
| 370 | projMatrix.setOffaxisX(projMatrix.getOffaxisX()+0.01f*step); |
---|
| 371 | pFrustum->setProjectionMatrix(projMatrix); |
---|
| 372 | break; |
---|
| 373 | case Qt::Key_Slash: |
---|
| 374 | projMatrix.setOffaxisX(projMatrix.getOffaxisX()-0.01f*step); |
---|
| 375 | pFrustum->setProjectionMatrix(projMatrix); |
---|
| 376 | break; |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | else |
---|
| 380 | { |
---|
| 381 | switch (pEvent->key()) |
---|
| 382 | { |
---|
| 383 | case Qt::Key_PageUp: |
---|
| 384 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]+0.1f*step, pos[2])); |
---|
| 385 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 386 | break; |
---|
| 387 | case Qt::Key_PageDown: |
---|
| 388 | xformMatrix.setPosition(gmtl::Vec3f(pos[0], pos[1]-0.1f*step, pos[2])); |
---|
| 389 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 390 | break; |
---|
| 391 | case Qt::Key_Left: |
---|
| 392 | xformMatrix.setRotation(gmtl::Vec3f(rot[0]+1.0f*step, rot[1], rot[2])); |
---|
| 393 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 394 | break; |
---|
| 395 | case Qt::Key_Right: |
---|
| 396 | xformMatrix.setRotation(gmtl::Vec3f(rot[0]-1.0f*step, rot[1], rot[2])); |
---|
| 397 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 398 | break; |
---|
| 399 | case Qt::Key_Up: |
---|
| 400 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1]+1.0f*step, rot[2])); |
---|
| 401 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 402 | break; |
---|
| 403 | case Qt::Key_Down: |
---|
| 404 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1]-1.0f*step, rot[2])); |
---|
| 405 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 406 | break; |
---|
| 407 | case Qt::Key_Home: |
---|
| 408 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1], rot[2]-1.0f*step)); |
---|
| 409 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 410 | break; |
---|
| 411 | case Qt::Key_End: |
---|
| 412 | xformMatrix.setRotation(gmtl::Vec3f(rot[0], rot[1], rot[2]+1.0f*step)); |
---|
| 413 | pFrustum->setTransformMatrix(xformMatrix); |
---|
| 414 | break; |
---|
| 415 | case Qt::Key_Comma: |
---|
| 416 | projMatrix.setFOV(projMatrix.getFOV()-1.0f*step); |
---|
| 417 | pFrustum->setProjectionMatrix(projMatrix); |
---|
| 418 | break; |
---|
| 419 | case Qt::Key_Period: |
---|
| 420 | projMatrix.setFOV(projMatrix.getFOV()+1.0f*step); |
---|
| 421 | pFrustum->setProjectionMatrix(projMatrix); |
---|
| 422 | break; |
---|
| 423 | case Qt::Key_Q: |
---|
| 424 | if (m_opMode == DESIGN_OPMODE_PROJECTOR) |
---|
| 425 | setOpMode(DESIGN_OPMODE_VIEW); |
---|
| 426 | else |
---|
| 427 | setOpMode(DESIGN_OPMODE_PROJECTOR); |
---|
| 428 | break; |
---|
| 429 | case Qt::Key_T: |
---|
| 430 | if (m_transMode == DESIGN_TRANSMODE_LOCAL) |
---|
| 431 | setTransMode(DESIGN_TRANSMODE_WORLD); |
---|
| 432 | else |
---|
| 433 | setTransMode(DESIGN_TRANSMODE_LOCAL); |
---|
| 434 | break; |
---|
| 435 | } |
---|
| 436 | } |
---|
| 437 | #endif |
---|
| 438 | } |
---|
| 439 | |
---|
| 440 | void QDesignViewWidget::initFromDOMElement(const QDomElement& element) |
---|
| 441 | { |
---|
| 442 | QGLViewerWidget::initFromDOMElement(element); |
---|
| 443 | |
---|
| 444 | QDomElement display = element.firstChildElement("Display"); |
---|
| 445 | if (!display.isNull()) { |
---|
| 446 | QString viewMode = display.attribute("viewMode", "projector"); |
---|
| 447 | if (viewMode == "perspective") |
---|
| 448 | m_viewMode = DESIGN_VIEWMODE_PERSPECTIVE; |
---|
| 449 | else if (viewMode == "center") |
---|
| 450 | m_viewMode = DESIGN_VIEWMODE_CENTER; |
---|
| 451 | else if (viewMode == "top") |
---|
| 452 | m_viewMode = DESIGN_VIEWMODE_TOP; |
---|
| 453 | else if (viewMode == "side") |
---|
| 454 | m_viewMode = DESIGN_VIEWMODE_SIDE; |
---|
| 455 | else if (viewMode == "front") |
---|
| 456 | m_viewMode = DESIGN_VIEWMODE_FRONT; |
---|
| 457 | if (display.attribute("opMode", "projector")=="projector") |
---|
| 458 | m_opMode = DESIGN_OPMODE_PROJECTOR; |
---|
| 459 | else |
---|
| 460 | m_opMode = DESIGN_OPMODE_VIEW; |
---|
| 461 | if (display.attribute("transMode", "local")=="local") |
---|
| 462 | m_transMode = DESIGN_TRANSMODE_LOCAL; |
---|
| 463 | else |
---|
| 464 | m_transMode = DESIGN_TRANSMODE_WORLD; |
---|
| 465 | m_bInfoVisible = (display.attribute("info", "true")=="true"); |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | QDomElement QDesignViewWidget::domElement(QDomDocument& doc) const |
---|
| 470 | { |
---|
| 471 | QDomElement de = QGLViewerWidget::domElement("DesignView", doc); |
---|
| 472 | QDomElement display = de.firstChildElement("Display"); |
---|
| 473 | if (!display.isNull()) { |
---|
| 474 | switch (m_viewMode) { |
---|
| 475 | case DESIGN_VIEWMODE_PERSPECTIVE: display.setAttribute("viewMode", "perspective"); break; |
---|
| 476 | case DESIGN_VIEWMODE_CENTER: display.setAttribute("viewMode", "center"); break; |
---|
| 477 | case DESIGN_VIEWMODE_TOP: display.setAttribute("viewMode", "top"); break; |
---|
| 478 | case DESIGN_VIEWMODE_SIDE: display.setAttribute("viewMode", "side"); break; |
---|
| 479 | case DESIGN_VIEWMODE_FRONT: display.setAttribute("viewMode", "front"); break; |
---|
| 480 | } |
---|
| 481 | display.setAttribute("opMode", m_opMode==DESIGN_OPMODE_PROJECTOR?"projector":"view"); |
---|
| 482 | display.setAttribute("transMode", m_transMode==DESIGN_TRANSMODE_LOCAL?"local":"world"); |
---|
| 483 | display.setAttribute("info", m_bInfoVisible?"true":"false"); |
---|
| 484 | } |
---|
| 485 | return de; |
---|
| 486 | } |
---|