diff --git a/ground/src/plugins/modelview/modelview.pro b/ground/src/plugins/modelview/modelview.pro index 4db2a4277..8d1434b3a 100644 --- a/ground/src/plugins/modelview/modelview.pro +++ b/ground/src/plugins/modelview/modelview.pro @@ -1,19 +1,20 @@ -TEMPLATE = lib -TARGET = ModelViewGadget -include(../../openpilotgcsplugin.pri) -include(../../plugins/coreplugin/coreplugin.pri) -include(../../libs/glc_lib/glc_lib.pri) -INCLUDEPATH += ../../libs/glc_lib/install/include/GLC_lib -HEADERS += modelviewplugin.h \ - modelviewgadgetconfiguration.h \ - modelviewgadget.h \ - modelviewgadgetwidget.h \ - modelviewgadgetfactory.h \ - modelviewgadgetoptionspage.h -SOURCES += modelviewplugin.cpp \ - modelviewgadgetconfiguration.cpp \ - modelviewgadget.cpp \ - modelviewgadgetfactory.cpp \ - modelviewgadgetwidget.cpp \ - modelviewgadgetoptionspage.cpp -OTHER_FILES += ModelViewGadget.pluginspec +TEMPLATE = lib +TARGET = ModelViewGadget +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../libs/glc_lib/glc_lib.pri) +include(modelview_dependencies.pri) +INCLUDEPATH += ../../libs/glc_lib/install/include/GLC_lib +HEADERS += modelviewplugin.h \ + modelviewgadgetconfiguration.h \ + modelviewgadget.h \ + modelviewgadgetwidget.h \ + modelviewgadgetfactory.h \ + modelviewgadgetoptionspage.h +SOURCES += modelviewplugin.cpp \ + modelviewgadgetconfiguration.cpp \ + modelviewgadget.cpp \ + modelviewgadgetfactory.cpp \ + modelviewgadgetwidget.cpp \ + modelviewgadgetoptionspage.cpp +OTHER_FILES += ModelViewGadget.pluginspec diff --git a/ground/src/plugins/modelview/modelview_dependencies.pri b/ground/src/plugins/modelview/modelview_dependencies.pri new file mode 100644 index 000000000..9da489f64 --- /dev/null +++ b/ground/src/plugins/modelview/modelview_dependencies.pri @@ -0,0 +1,3 @@ +include(../../plugins/uavobjects/uavobjects.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../libs/utils/utils.pri) diff --git a/ground/src/plugins/modelview/modelviewgadgetoptionspage.cpp b/ground/src/plugins/modelview/modelviewgadgetoptionspage.cpp index 44b5ba9f6..0dce4f86e 100644 --- a/ground/src/plugins/modelview/modelviewgadgetoptionspage.cpp +++ b/ground/src/plugins/modelview/modelviewgadgetoptionspage.cpp @@ -82,7 +82,7 @@ void ModelViewGadgetOptionsPage::finish() void ModelViewGadgetOptionsPage::changeAC() { QString ac = QFileDialog::getOpenFileName(qobject_cast(this), - tr("Model 3D File"), "../artwork/", tr("3D File (*.dae)") ); + tr("Model 3D File"), "../artwork/", tr("3D File (*.dae *.3ds)") ); m_config->setAcFilename(ac); m_acFileLabel->setText(ac); } diff --git a/ground/src/plugins/modelview/modelviewgadgetwidget.cpp b/ground/src/plugins/modelview/modelviewgadgetwidget.cpp index 9998666ee..7195c24ad 100644 --- a/ground/src/plugins/modelview/modelviewgadgetwidget.cpp +++ b/ground/src/plugins/modelview/modelviewgadgetwidget.cpp @@ -25,6 +25,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "modelviewgadgetwidget.h" +#include "extensionsystem/pluginmanager.h" #include ModelViewGadgetWidget::ModelViewGadgetWidget(QWidget *parent) @@ -48,11 +49,17 @@ ModelViewGadgetWidget::ModelViewGadgetWidget(QWidget *parent) m_MoverController= m_pFactory->createDefaultMoverController(repColor, &m_GlView); m_GlView.cameraHandle()->setDefaultUpVector(glc::Y_AXIS); + m_GlView.cameraHandle()->setRightView(); //m_GlView.cameraHandle()->setIsoView(); + // Get required UAVObjects + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager* objManager = pm->getObject(); + attActual = AttitudeActual::GetInstance(objManager); + // Create objects to display CreateScene(); - connect(&m_MotionTimer, SIGNAL(timeout()), this, SLOT(rotateView())); + connect(&m_MotionTimer, SIGNAL(timeout()), this, SLOT(updateAttitude())); } ModelViewGadgetWidget::~ModelViewGadgetWidget() @@ -78,7 +85,7 @@ void ModelViewGadgetWidget::initializeGL() m_GlView.setDistMinAndMax(m_World.boundingBox()); glEnable(GL_NORMALIZE); - m_MotionTimer.start(60); + m_MotionTimer.start(100); } void ModelViewGadgetWidget::resizeEvent(QResizeEvent *event) @@ -172,10 +179,20 @@ void ModelViewGadgetWidget::mouseReleaseEvent(QMouseEvent*) ////////////////////////////////////////////////////////////////////// // Private slots Functions ////////////////////////////////////////////////////////////////////// -// Rotate the view -void ModelViewGadgetWidget::rotateView() +void ModelViewGadgetWidget::updateAttitude() { - m_GlView.cameraHandle()->rotateAroundTarget(glc::Y_AXIS, 2.0 * glc::PI / static_cast(200)); - updateGL(); + // Reset view to zero angles + // NOTE: Some aircraft 3D models have different orientation and axis + m_GlView.cameraHandle()->setTopView(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::X_AXIS, 180.0*glc::PI/180.0); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, 90.0*glc::PI/180.0); + // Rotate to the actual angles (if a gimbal lock at yaw 90/270 deg, change sequence of rotations) + AttitudeActual::DataFields data = attActual->getData(); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS, data.Yaw*glc::PI/180.0); + m_GlView.cameraHandle()->rotateAroundTarget(glc::X_AXIS, data.Roll*glc::PI/180.0); + m_GlView.cameraHandle()->rotateAroundTarget(glc::Y_AXIS, -data.Pitch*glc::PI/180.0); + updateGL(); } + + diff --git a/ground/src/plugins/modelview/modelviewgadgetwidget.h b/ground/src/plugins/modelview/modelviewgadgetwidget.h index 6ee34eaf0..4a3611c5a 100644 --- a/ground/src/plugins/modelview/modelviewgadgetwidget.h +++ b/ground/src/plugins/modelview/modelviewgadgetwidget.h @@ -37,6 +37,9 @@ #include #include +#include "uavobjects/uavobjectmanager.h" +#include "uavobjects/attitudeactual.h" + class ModelViewGadgetWidget : public QGLWidget @@ -70,8 +73,7 @@ private: // Private slots Functions ////////////////////////////////////////////////////////////////////// private slots: - //! Rotate the view - void rotateView(); + void updateAttitude(); private: GLC_Factory* m_pFactory; @@ -85,6 +87,8 @@ private: QString acFilename; QString bgFilename; + + AttitudeActual* attActual; }; #endif /* MODELVIEWGADGETWIDGET_H_ */