From 114956a514b5fbacb757e882d3f618941c4c313c Mon Sep 17 00:00:00 2001 From: muralha Date: Mon, 4 Oct 2010 10:17:59 +0000 Subject: [PATCH] Ground/ModelView: Added camera switching through keyboard (numbers: 1 to 0). Also, fixed wrong rotation of pitch and yaw. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1874 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../modelview/modelviewgadgetwidget.cpp | 64 ++++++++++++++++++- .../plugins/modelview/modelviewgadgetwidget.h | 1 + 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/ground/src/plugins/modelview/modelviewgadgetwidget.cpp b/ground/src/plugins/modelview/modelviewgadgetwidget.cpp index 679726ce0..a3b2cc2aa 100644 --- a/ground/src/plugins/modelview/modelviewgadgetwidget.cpp +++ b/ground/src/plugins/modelview/modelviewgadgetwidget.cpp @@ -101,6 +101,7 @@ void ModelViewGadgetWidget::initializeGL() glEnable(GL_MULTISAMPLE); m_MotionTimer.start(100); + setFocusPolicy(Qt::StrongFocus); // keyboard capture for camera switching } void ModelViewGadgetWidget::paintGL() @@ -217,6 +218,65 @@ void ModelViewGadgetWidget::mouseReleaseEvent(QMouseEvent*) updateGL(); } +void ModelViewGadgetWidget::keyPressEvent(QKeyEvent * e) // switch between camera +{ + if (e->key() == Qt::Key_1) + { + m_GlView.cameraHandle()->setIsoView(); + updateGL(); + } + if (e->key() == Qt::Key_2) + { + m_GlView.cameraHandle()->setFrontView(); + updateGL(); + } + if (e->key() == Qt::Key_3) + { + m_GlView.cameraHandle()->setIsoView(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(90)); + updateGL(); + } + if (e->key() == Qt::Key_4) + { + m_GlView.cameraHandle()->setLeftView(); + updateGL(); + } + if (e->key() == Qt::Key_5) + { + m_GlView.cameraHandle()->setTopView(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180)); + updateGL(); + } + if (e->key() == Qt::Key_6) + { + m_GlView.cameraHandle()->setRightView();; + updateGL(); + } + if (e->key() == Qt::Key_7) + { + m_GlView.cameraHandle()->setIsoView(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(-90)); + updateGL(); + } + if (e->key() == Qt::Key_8) + { + m_GlView.cameraHandle()->setRearView();; + updateGL(); + } + if (e->key() == Qt::Key_9) + { + m_GlView.cameraHandle()->setIsoView(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180)); + updateGL(); + } + if (e->key() == Qt::Key_0) + { + m_GlView.cameraHandle()->setBottomView(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180)); + updateGL(); + } +} + ////////////////////////////////////////////////////////////////////// // Private slots Functions ////////////////////////////////////////////////////////////////////// @@ -225,9 +285,9 @@ void ModelViewGadgetWidget::updateAttitude() AttitudeActual::DataFields data = attActual->getData(); GLC_StructOccurence* rootObject= m_World.rootOccurence(); GLC_Matrix4x4 rootObjectPosition(0, 0, 0); // will be changed when the acceleration movement is tested - double pitch= glc::toRadian(data.Pitch); + double pitch= glc::toRadian(-data.Pitch); double roll= glc::toRadian(data.Roll); - double yaw= glc::toRadian(data.Yaw); + double yaw= glc::toRadian(-data.Yaw); GLC_Matrix4x4 rootObjectRotation(GLC_Matrix4x4().fromEuler(pitch, roll, yaw)); rootObject->structInstance()->setMatrix(rootObjectPosition * rootObjectRotation); rootObject->updateChildrenAbsoluteMatrix(); diff --git a/ground/src/plugins/modelview/modelviewgadgetwidget.h b/ground/src/plugins/modelview/modelviewgadgetwidget.h index 6ec3b90a7..8e013296b 100644 --- a/ground/src/plugins/modelview/modelviewgadgetwidget.h +++ b/ground/src/plugins/modelview/modelviewgadgetwidget.h @@ -68,6 +68,7 @@ private: void mouseMoveEvent(QMouseEvent * e); void mouseReleaseEvent(QMouseEvent * e); void wheelEvent(QWheelEvent * e); + void keyPressEvent(QKeyEvent * e); ////////////////////////////////////////////////////////////////////// // Private slots Functions