mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
OP-306 Update revealed two bugs in the widget destructors, workaround for now, too late for today...
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2683 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
959e9101b2
commit
c1555d9dfe
@ -1,184 +1,184 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file gpsconstellationwidget.cpp
|
* @file gpsconstellationwidget.cpp
|
||||||
* @author Edouard Lafargue Copyright (C) 2010.
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
* @addtogroup GPSGadgetPlugin GPS Gadget Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief A widget which displays the GPS constellation
|
* @brief A widget which displays the GPS constellation
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gpsconstellationwidget.h"
|
#include "gpsconstellationwidget.h"
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the widget
|
* Initialize the widget
|
||||||
*/
|
*/
|
||||||
GpsConstellationWidget::GpsConstellationWidget(QWidget *parent) : QGraphicsView(parent)
|
GpsConstellationWidget::GpsConstellationWidget(QWidget *parent) : QGraphicsView(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create a layout, add a QGraphicsView and put the SVG inside.
|
// Create a layout, add a QGraphicsView and put the SVG inside.
|
||||||
// The constellation widget looks like this:
|
// The constellation widget looks like this:
|
||||||
// |--------------------|
|
// |--------------------|
|
||||||
// | |
|
// | |
|
||||||
// | |
|
// | |
|
||||||
// | Constellation |
|
// | Constellation |
|
||||||
// | |
|
// | |
|
||||||
// | |
|
// | |
|
||||||
// | |
|
// | |
|
||||||
// |--------------------|
|
// |--------------------|
|
||||||
|
|
||||||
|
|
||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
QSvgRenderer *renderer = new QSvgRenderer();
|
QSvgRenderer *renderer = new QSvgRenderer();
|
||||||
renderer->load(QString(":/gpsgadget/images/gpsEarth.svg"));
|
renderer->load(QString(":/gpsgadget/images/gpsEarth.svg"));
|
||||||
|
|
||||||
world = new QGraphicsSvgItem();
|
world = new QGraphicsSvgItem();
|
||||||
world->setSharedRenderer(renderer);
|
world->setSharedRenderer(renderer);
|
||||||
world->setElementId("map");
|
world->setElementId("map");
|
||||||
|
|
||||||
scene = new QGraphicsScene(this);
|
scene = new QGraphicsScene(this);
|
||||||
scene->addItem(world);
|
scene->addItem(world);
|
||||||
scene->setSceneRect(world->boundingRect());
|
scene->setSceneRect(world->boundingRect());
|
||||||
setScene(scene);
|
setScene(scene);
|
||||||
|
|
||||||
// Now create 'maxSatellites' satellite icons which we will move around on the map:
|
// Now create 'maxSatellites' satellite icons which we will move around on the map:
|
||||||
for (int i=0; i < MAX_SATTELITES;i++) {
|
for (int i=0; i < MAX_SATTELITES;i++) {
|
||||||
satellites[i][0] = 0;
|
satellites[i][0] = 0;
|
||||||
satellites[i][1] = 0;
|
satellites[i][1] = 0;
|
||||||
satellites[i][2] = 0;
|
satellites[i][2] = 0;
|
||||||
satellites[i][3] = 0;
|
satellites[i][3] = 0;
|
||||||
|
|
||||||
satIcons[i] = new QGraphicsSvgItem(world);
|
satIcons[i] = new QGraphicsSvgItem(world);
|
||||||
satIcons[i]->setSharedRenderer(renderer);
|
satIcons[i]->setSharedRenderer(renderer);
|
||||||
satIcons[i]->setElementId("sat-notSeen");
|
satIcons[i]->setElementId("sat-notSeen");
|
||||||
satIcons[i]->hide();
|
satIcons[i]->hide();
|
||||||
|
|
||||||
satTexts[i] = new QGraphicsSimpleTextItem("##",satIcons[i]);
|
satTexts[i] = new QGraphicsSimpleTextItem("##",satIcons[i]);
|
||||||
satTexts[i]->setBrush(QColor("Black"));
|
satTexts[i]->setBrush(QColor("Black"));
|
||||||
satTexts[i]->setFont(QFont("Courier"));
|
satTexts[i]->setFont(QFont("Courier"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GpsConstellationWidget::~GpsConstellationWidget()
|
GpsConstellationWidget::~GpsConstellationWidget()
|
||||||
{
|
{
|
||||||
delete scene;
|
delete scene;
|
||||||
scene = 0;
|
scene = 0;
|
||||||
|
|
||||||
delete renderer;
|
//delete renderer;
|
||||||
renderer = 0;
|
//renderer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpsConstellationWidget::showEvent(QShowEvent *event)
|
void GpsConstellationWidget::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
// Thit fitInView method should only be called now, once the
|
// Thit fitInView method should only be called now, once the
|
||||||
// widget is shown, otherwise it cannot compute its values and
|
// widget is shown, otherwise it cannot compute its values and
|
||||||
// the result is usually a ahrsbargraph that is way too small.
|
// the result is usually a ahrsbargraph that is way too small.
|
||||||
fitInView(world, Qt::KeepAspectRatio);
|
fitInView(world, Qt::KeepAspectRatio);
|
||||||
// Scale, can't use fitInView since that doesn't work until we're shown.
|
// Scale, can't use fitInView since that doesn't work until we're shown.
|
||||||
// qreal factor = height()/world->boundingRect().height();
|
// qreal factor = height()/world->boundingRect().height();
|
||||||
// world->setScale(factor);
|
// world->setScale(factor);
|
||||||
// setSceneRect(world->boundingRect());
|
// setSceneRect(world->boundingRect());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpsConstellationWidget::resizeEvent(QResizeEvent* event)
|
void GpsConstellationWidget::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
fitInView(world, Qt::KeepAspectRatio);
|
fitInView(world, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr)
|
void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr)
|
||||||
{
|
{
|
||||||
if (index >= MAX_SATTELITES) {
|
if (index >= MAX_SATTELITES) {
|
||||||
// A bit of error checking never hurts.
|
// A bit of error checking never hurts.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add range checking
|
// TODO: add range checking
|
||||||
satellites[index][0] = prn;
|
satellites[index][0] = prn;
|
||||||
satellites[index][1] = elevation;
|
satellites[index][1] = elevation;
|
||||||
satellites[index][2] = azimuth;
|
satellites[index][2] = azimuth;
|
||||||
satellites[index][3] = snr;
|
satellites[index][3] = snr;
|
||||||
|
|
||||||
if (prn) {
|
if (prn) {
|
||||||
QPointF opd = polarToCoord(elevation,azimuth);
|
QPointF opd = polarToCoord(elevation,azimuth);
|
||||||
opd += QPointF(-satIcons[index]->boundingRect().center().x(),
|
opd += QPointF(-satIcons[index]->boundingRect().center().x(),
|
||||||
-satIcons[index]->boundingRect().center().y());
|
-satIcons[index]->boundingRect().center().y());
|
||||||
satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), false);
|
satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), false);
|
||||||
if (snr) {
|
if (snr) {
|
||||||
satIcons[index]->setElementId("satellite");
|
satIcons[index]->setElementId("satellite");
|
||||||
} else {
|
} else {
|
||||||
satIcons[index]->setElementId("sat-notSeen");
|
satIcons[index]->setElementId("sat-notSeen");
|
||||||
}
|
}
|
||||||
satIcons[index]->show();
|
satIcons[index]->show();
|
||||||
|
|
||||||
QRectF iconRect = satIcons[index]->boundingRect();
|
QRectF iconRect = satIcons[index]->boundingRect();
|
||||||
QString prnString = QString().number(prn);
|
QString prnString = QString().number(prn);
|
||||||
if(prnString.length() == 1) {
|
if(prnString.length() == 1) {
|
||||||
prnString = "0" + prnString;
|
prnString = "0" + prnString;
|
||||||
}
|
}
|
||||||
satTexts[index]->setText(prnString);
|
satTexts[index]->setText(prnString);
|
||||||
QRectF textRect = satTexts[index]->boundingRect();
|
QRectF textRect = satTexts[index]->boundingRect();
|
||||||
|
|
||||||
QTransform matrix;
|
QTransform matrix;
|
||||||
qreal scale = 0.70 * (iconRect.width() / textRect.width());
|
qreal scale = 0.70 * (iconRect.width() / textRect.width());
|
||||||
matrix.translate(iconRect.width()/2, iconRect.height()/2);
|
matrix.translate(iconRect.width()/2, iconRect.height()/2);
|
||||||
matrix.scale(scale,scale);
|
matrix.scale(scale,scale);
|
||||||
matrix.translate(-textRect.width()/2,-textRect.height()/2);
|
matrix.translate(-textRect.width()/2,-textRect.height()/2);
|
||||||
satTexts[index]->setTransform(matrix,false);
|
satTexts[index]->setTransform(matrix,false);
|
||||||
} else {
|
} else {
|
||||||
satIcons[index]->hide();
|
satIcons[index]->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Converts the elevation/azimuth to X/Y coordinates on the map
|
Converts the elevation/azimuth to X/Y coordinates on the map
|
||||||
|
|
||||||
*/
|
*/
|
||||||
QPointF GpsConstellationWidget::polarToCoord(int elevation, int azimuth)
|
QPointF GpsConstellationWidget::polarToCoord(int elevation, int azimuth)
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
double rad_elevation;
|
double rad_elevation;
|
||||||
double rad_azimuth;
|
double rad_azimuth;
|
||||||
|
|
||||||
|
|
||||||
rad_elevation = M_PI*elevation/180;
|
rad_elevation = M_PI*elevation/180;
|
||||||
rad_azimuth = M_PI*azimuth/180;
|
rad_azimuth = M_PI*azimuth/180;
|
||||||
|
|
||||||
x = cos(rad_elevation)*sin(rad_azimuth);
|
x = cos(rad_elevation)*sin(rad_azimuth);
|
||||||
y = -cos(rad_elevation)*cos(rad_azimuth);
|
y = -cos(rad_elevation)*cos(rad_azimuth);
|
||||||
|
|
||||||
x = world->boundingRect().width()/2 * x;
|
x = world->boundingRect().width()/2 * x;
|
||||||
y = world->boundingRect().height()/2 * y;
|
y = world->boundingRect().height()/2 * y;
|
||||||
|
|
||||||
x = (world->boundingRect().width() / 2) + x;
|
x = (world->boundingRect().width() / 2) + x;
|
||||||
y = (world->boundingRect().height() / 2) + y;
|
y = (world->boundingRect().height() / 2) + y;
|
||||||
|
|
||||||
return QPointF(x,y);
|
return QPointF(x,y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,325 +1,325 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file modelviewgadgetwidget.cpp
|
* @file modelviewgadgetwidget.cpp
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup ModelViewPlugin ModelView Plugin
|
* @addtogroup ModelViewPlugin ModelView Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief A gadget that displays a 3D representation of the UAV
|
* @brief A gadget that displays a 3D representation of the UAV
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#include "modelviewgadgetwidget.h"
|
#include "modelviewgadgetwidget.h"
|
||||||
#include "extensionsystem/pluginmanager.h"
|
#include "extensionsystem/pluginmanager.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
ModelViewGadgetWidget::ModelViewGadgetWidget(QWidget *parent)
|
ModelViewGadgetWidget::ModelViewGadgetWidget(QWidget *parent)
|
||||||
: QGLWidget(QGLFormat(QGL::SampleBuffers),parent)
|
: QGLWidget(QGLFormat(QGL::SampleBuffers),parent)
|
||||||
// : QGLWidget(parent)
|
// : QGLWidget(parent)
|
||||||
, m_pFactory(GLC_Factory::instance(this->context()))
|
, m_pFactory(GLC_Factory::instance(this->context()))
|
||||||
, m_Light()
|
, m_Light()
|
||||||
, m_World()
|
, m_World()
|
||||||
, m_GlView(this)
|
, m_GlView(this)
|
||||||
, m_MoverController()
|
, m_MoverController()
|
||||||
, m_ModelBoundingBox()
|
, m_ModelBoundingBox()
|
||||||
, m_MotionTimer()
|
, m_MotionTimer()
|
||||||
, vboEnable(false)
|
, vboEnable(false)
|
||||||
{
|
{
|
||||||
// Prevent crash on non-VBO enabled systems during GLC geometry creation
|
// Prevent crash on non-VBO enabled systems during GLC geometry creation
|
||||||
GLC_State::setVboUsage(vboEnable);
|
GLC_State::setVboUsage(vboEnable);
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
mvInitGLSuccess = false;
|
mvInitGLSuccess = false;
|
||||||
|
|
||||||
CreateScene();
|
CreateScene();
|
||||||
|
|
||||||
m_Light.setPosition(4000.0, -40000.0, 80000.0);
|
m_Light.setPosition(4000.0, -40000.0, 80000.0);
|
||||||
m_Light.setAmbientColor(Qt::lightGray);
|
m_Light.setAmbientColor(Qt::lightGray);
|
||||||
|
|
||||||
m_GlView.cameraHandle()->setDefaultUpVector(glc::Z_AXIS);
|
m_GlView.cameraHandle()->setDefaultUpVector(glc::Z_AXIS);
|
||||||
m_GlView.cameraHandle()->setFrontView();
|
m_GlView.cameraHandle()->setFrontView();
|
||||||
m_GlView.setToOrtho(true); // orthogonal view
|
m_GlView.setToOrtho(true); // orthogonal view
|
||||||
|
|
||||||
QColor repColor;
|
QColor repColor;
|
||||||
repColor.setRgbF(1.0, 0.11372, 0.11372, 0.0);
|
repColor.setRgbF(1.0, 0.11372, 0.11372, 0.0);
|
||||||
m_MoverController= m_pFactory->createDefaultMoverController(repColor, &m_GlView);
|
m_MoverController= m_pFactory->createDefaultMoverController(repColor, &m_GlView);
|
||||||
|
|
||||||
// Get required UAVObjects
|
// Get required UAVObjects
|
||||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||||
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
||||||
attActual = AttitudeActual::GetInstance(objManager);
|
attActual = AttitudeActual::GetInstance(objManager);
|
||||||
|
|
||||||
// Create objects to display
|
// Create objects to display
|
||||||
connect(&m_MotionTimer, SIGNAL(timeout()), this, SLOT(updateAttitude()));
|
connect(&m_MotionTimer, SIGNAL(timeout()), this, SLOT(updateAttitude()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelViewGadgetWidget::~ModelViewGadgetWidget()
|
ModelViewGadgetWidget::~ModelViewGadgetWidget()
|
||||||
{
|
{
|
||||||
delete m_pFactory;
|
//delete m_pFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Public funcitons ////
|
//// Public funcitons ////
|
||||||
void ModelViewGadgetWidget::reloadScene()
|
void ModelViewGadgetWidget::reloadScene()
|
||||||
{
|
{
|
||||||
CreateScene();
|
CreateScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Private functions ////
|
//// Private functions ////
|
||||||
void ModelViewGadgetWidget::initializeGL()
|
void ModelViewGadgetWidget::initializeGL()
|
||||||
{
|
{
|
||||||
if (loadError)
|
if (loadError)
|
||||||
return;
|
return;
|
||||||
// OpenGL initialization
|
// OpenGL initialization
|
||||||
m_GlView.initGl();
|
m_GlView.initGl();
|
||||||
|
|
||||||
// Enable VBO usage if configured (default is to disable)
|
// Enable VBO usage if configured (default is to disable)
|
||||||
GLC_State::setVboUsage(vboEnable);
|
GLC_State::setVboUsage(vboEnable);
|
||||||
if (!vboEnable)
|
if (!vboEnable)
|
||||||
{
|
{
|
||||||
qDebug("VBOs disabled. Enable for better performance if GPU supports it. (Most do)");
|
qDebug("VBOs disabled. Enable for better performance if GPU supports it. (Most do)");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_GlView.reframe(m_ModelBoundingBox);
|
m_GlView.reframe(m_ModelBoundingBox);
|
||||||
// Calculate camera depth of view
|
// Calculate camera depth of view
|
||||||
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
// Enable antialiasing
|
// Enable antialiasing
|
||||||
glEnable(GL_MULTISAMPLE);
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
m_MotionTimer.start(100);
|
m_MotionTimer.start(100);
|
||||||
setFocusPolicy(Qt::StrongFocus); // keyboard capture for camera switching
|
setFocusPolicy(Qt::StrongFocus); // keyboard capture for camera switching
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::paintGL()
|
void ModelViewGadgetWidget::paintGL()
|
||||||
{
|
{
|
||||||
if (loadError)
|
if (loadError)
|
||||||
return;
|
return;
|
||||||
// Clear screen
|
// Clear screen
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
// Load identity matrix
|
// Load identity matrix
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
// Enable antialiasing
|
// Enable antialiasing
|
||||||
glEnable(GL_MULTISAMPLE);
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
// define the light
|
// define the light
|
||||||
m_Light.enable();
|
m_Light.enable();
|
||||||
|
|
||||||
// define view matrix
|
// define view matrix
|
||||||
m_GlView.glExecuteCam();
|
m_GlView.glExecuteCam();
|
||||||
m_Light.glExecute();
|
m_Light.glExecute();
|
||||||
|
|
||||||
// Display the collection of GLC_Object
|
// Display the collection of GLC_Object
|
||||||
m_World.render(0, glc::TransparentRenderFlag);
|
m_World.render(0, glc::TransparentRenderFlag);
|
||||||
m_World.render(0, glc::ShadingFlag);
|
m_World.render(0, glc::ShadingFlag);
|
||||||
|
|
||||||
// Display UI Info (orbit circle)
|
// Display UI Info (orbit circle)
|
||||||
m_MoverController.drawActiveMoverRep();
|
m_MoverController.drawActiveMoverRep();
|
||||||
mvInitGLSuccess = true;
|
mvInitGLSuccess = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::resizeGL(int width, int height)
|
void ModelViewGadgetWidget::resizeGL(int width, int height)
|
||||||
{
|
{
|
||||||
m_GlView.setWinGLSize(width, height); // Compute window aspect ratio
|
m_GlView.setWinGLSize(width, height); // Compute window aspect ratio
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GLC_Object to display
|
// Create GLC_Object to display
|
||||||
void ModelViewGadgetWidget::CreateScene()
|
void ModelViewGadgetWidget::CreateScene()
|
||||||
{
|
{
|
||||||
// put a black background if the 3D model is invalid or if the background image is also invalid
|
// put a black background if the 3D model is invalid or if the background image is also invalid
|
||||||
if (acFilename == ":/modelview/models/warning_sign.obj" or !QFile::exists(bgFilename))
|
if (acFilename == ":/modelview/models/warning_sign.obj" or !QFile::exists(bgFilename))
|
||||||
bgFilename= ":/modelview/models/black.jpg";
|
bgFilename= ":/modelview/models/black.jpg";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_GlView.loadBackGroundImage(bgFilename);
|
m_GlView.loadBackGroundImage(bgFilename);
|
||||||
}
|
}
|
||||||
catch(GLC_Exception e)
|
catch(GLC_Exception e)
|
||||||
{
|
{
|
||||||
qDebug("ModelView: background image file loading failed.");
|
qDebug("ModelView: background image file loading failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(QFile::exists(acFilename))
|
if(QFile::exists(acFilename))
|
||||||
{
|
{
|
||||||
QFile aircraft(acFilename);
|
QFile aircraft(acFilename);
|
||||||
m_World= GLC_Factory::instance()->createWorldFromFile(aircraft);
|
m_World= GLC_Factory::instance()->createWorldFromFile(aircraft);
|
||||||
m_ModelBoundingBox= m_World.boundingBox();
|
m_ModelBoundingBox= m_World.boundingBox();
|
||||||
m_GlView.reframe(m_ModelBoundingBox); // center 3D model in the scene
|
m_GlView.reframe(m_ModelBoundingBox); // center 3D model in the scene
|
||||||
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
||||||
loadError = false;
|
loadError = false;
|
||||||
if (!mvInitGLSuccess)
|
if (!mvInitGLSuccess)
|
||||||
initializeGL();
|
initializeGL();
|
||||||
} else {
|
} else {
|
||||||
loadError = true;
|
loadError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(GLC_Exception e)
|
catch(GLC_Exception e)
|
||||||
{
|
{
|
||||||
qDebug("ModelView: aircraft file loading failed.");
|
qDebug("ModelView: aircraft file loading failed.");
|
||||||
loadError = true;
|
loadError = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::wheelEvent(QWheelEvent * e)
|
void ModelViewGadgetWidget::wheelEvent(QWheelEvent * e)
|
||||||
{
|
{
|
||||||
double delta = m_GlView.cameraHandle()->distEyeTarget() - (e->delta()/120) ;
|
double delta = m_GlView.cameraHandle()->distEyeTarget() - (e->delta()/120) ;
|
||||||
m_GlView.cameraHandle()->setDistEyeTarget(delta);
|
m_GlView.cameraHandle()->setDistEyeTarget(delta);
|
||||||
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::mousePressEvent(QMouseEvent *e)
|
void ModelViewGadgetWidget::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
if (m_MoverController.hasActiveMover()) return;
|
if (m_MoverController.hasActiveMover()) return;
|
||||||
|
|
||||||
switch (e->button())
|
switch (e->button())
|
||||||
{
|
{
|
||||||
case (Qt::LeftButton):
|
case (Qt::LeftButton):
|
||||||
m_MotionTimer.stop();
|
m_MotionTimer.stop();
|
||||||
m_MoverController.setActiveMover(GLC_MoverController::TurnTable, e);
|
m_MoverController.setActiveMover(GLC_MoverController::TurnTable, e);
|
||||||
updateGL();
|
updateGL();
|
||||||
break;
|
break;
|
||||||
case (Qt::RightButton):
|
case (Qt::RightButton):
|
||||||
printf("VBO enabled: %s, VBO supported: %s, VBO used: %s\n",
|
printf("VBO enabled: %s, VBO supported: %s, VBO used: %s\n",
|
||||||
vboEnable ? "yes" : "no",
|
vboEnable ? "yes" : "no",
|
||||||
GLC_State::vboSupported() ? "yes" : "no",
|
GLC_State::vboSupported() ? "yes" : "no",
|
||||||
GLC_State::vboUsed() ? "yes" : "no");
|
GLC_State::vboUsed() ? "yes" : "no");
|
||||||
printf("Renderer - %s \n", (char*)glGetString(GL_RENDERER));
|
printf("Renderer - %s \n", (char*)glGetString(GL_RENDERER));
|
||||||
printf("Extensions - %s\n", (char*)glGetString(GL_EXTENSIONS));
|
printf("Extensions - %s\n", (char*)glGetString(GL_EXTENSIONS));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::mouseMoveEvent(QMouseEvent * e)
|
void ModelViewGadgetWidget::mouseMoveEvent(QMouseEvent * e)
|
||||||
{
|
{
|
||||||
if (not m_MoverController.hasActiveMover()) return;
|
if (not m_MoverController.hasActiveMover()) return;
|
||||||
m_MoverController.move(e);
|
m_MoverController.move(e);
|
||||||
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
m_GlView.setDistMinAndMax(m_World.boundingBox());
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::mouseReleaseEvent(QMouseEvent*)
|
void ModelViewGadgetWidget::mouseReleaseEvent(QMouseEvent*)
|
||||||
{
|
{
|
||||||
if (not m_MoverController.hasActiveMover()) return;
|
if (not m_MoverController.hasActiveMover()) return;
|
||||||
m_MoverController.setNoMover();
|
m_MoverController.setNoMover();
|
||||||
m_MotionTimer.start();
|
m_MotionTimer.start();
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelViewGadgetWidget::keyPressEvent(QKeyEvent * e) // switch between camera
|
void ModelViewGadgetWidget::keyPressEvent(QKeyEvent * e) // switch between camera
|
||||||
{
|
{
|
||||||
if (e->key() == Qt::Key_1)
|
if (e->key() == Qt::Key_1)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setIsoView();
|
m_GlView.cameraHandle()->setIsoView();
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_2)
|
if (e->key() == Qt::Key_2)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setFrontView();
|
m_GlView.cameraHandle()->setFrontView();
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_3)
|
if (e->key() == Qt::Key_3)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setIsoView();
|
m_GlView.cameraHandle()->setIsoView();
|
||||||
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(90));
|
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(90));
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_4)
|
if (e->key() == Qt::Key_4)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setLeftView();
|
m_GlView.cameraHandle()->setLeftView();
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_5)
|
if (e->key() == Qt::Key_5)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setTopView();
|
m_GlView.cameraHandle()->setTopView();
|
||||||
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180));
|
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180));
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_6)
|
if (e->key() == Qt::Key_6)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setRightView();;
|
m_GlView.cameraHandle()->setRightView();;
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_7)
|
if (e->key() == Qt::Key_7)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setIsoView();
|
m_GlView.cameraHandle()->setIsoView();
|
||||||
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(-90));
|
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(-90));
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_8)
|
if (e->key() == Qt::Key_8)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setRearView();;
|
m_GlView.cameraHandle()->setRearView();;
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_9)
|
if (e->key() == Qt::Key_9)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setIsoView();
|
m_GlView.cameraHandle()->setIsoView();
|
||||||
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180));
|
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180));
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
if (e->key() == Qt::Key_0)
|
if (e->key() == Qt::Key_0)
|
||||||
{
|
{
|
||||||
m_GlView.cameraHandle()->setBottomView();
|
m_GlView.cameraHandle()->setBottomView();
|
||||||
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180));
|
m_GlView.cameraHandle()->rotateAroundTarget(glc::Z_AXIS,glc::toRadian(180));
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Private slots Functions
|
// Private slots Functions
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
void ModelViewGadgetWidget::updateAttitude()
|
void ModelViewGadgetWidget::updateAttitude()
|
||||||
{
|
{
|
||||||
AttitudeActual::DataFields data = attActual->getData(); // get attitude data
|
AttitudeActual::DataFields data = attActual->getData(); // get attitude data
|
||||||
GLC_StructOccurence* rootObject= m_World.rootOccurence(); // get the full 3D model
|
GLC_StructOccurence* rootObject= m_World.rootOccurence(); // get the full 3D model
|
||||||
// create quaternions rotations for each axis
|
// create quaternions rotations for each axis
|
||||||
QQuaternion qX= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),data.Pitch);
|
QQuaternion qX= QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),data.Pitch);
|
||||||
QQuaternion qY= QQuaternion::fromAxisAndAngle(QVector3D(0,1,0),data.Roll);
|
QQuaternion qY= QQuaternion::fromAxisAndAngle(QVector3D(0,1,0),data.Roll);
|
||||||
QQuaternion qZ= QQuaternion::fromAxisAndAngle(QVector3D(0,0,1),data.Yaw);
|
QQuaternion qZ= QQuaternion::fromAxisAndAngle(QVector3D(0,0,1),data.Yaw);
|
||||||
QQuaternion quat= qX * qY * qZ; // create the quaternion of all the rotations
|
QQuaternion quat= qX * qY * qZ; // create the quaternion of all the rotations
|
||||||
// pass values to simpler variables
|
// pass values to simpler variables
|
||||||
double x= quat.vector().x();
|
double x= quat.vector().x();
|
||||||
double y= quat.vector().y();
|
double y= quat.vector().y();
|
||||||
double z= quat.vector().z();
|
double z= quat.vector().z();
|
||||||
double w= quat.scalar();
|
double w= quat.scalar();
|
||||||
// create and gives the product of 2 4x4 matrices to get the rotation of the 3D model's matrix
|
// create and gives the product of 2 4x4 matrices to get the rotation of the 3D model's matrix
|
||||||
QMatrix4x4 m1;
|
QMatrix4x4 m1;
|
||||||
m1.setRow(0, QVector4D(w,z,-y,x));
|
m1.setRow(0, QVector4D(w,z,-y,x));
|
||||||
m1.setRow(1, QVector4D(-z,w,x,y));
|
m1.setRow(1, QVector4D(-z,w,x,y));
|
||||||
m1.setRow(2, QVector4D(y,-x,w,z));
|
m1.setRow(2, QVector4D(y,-x,w,z));
|
||||||
m1.setRow(3, QVector4D(-x,-y,-z,w));
|
m1.setRow(3, QVector4D(-x,-y,-z,w));
|
||||||
QMatrix4x4 m2;
|
QMatrix4x4 m2;
|
||||||
m2.setRow(0, QVector4D(w,z,-y,-x));
|
m2.setRow(0, QVector4D(w,z,-y,-x));
|
||||||
m2.setRow(1, QVector4D(-z,w,x,-y));
|
m2.setRow(1, QVector4D(-z,w,x,-y));
|
||||||
m2.setRow(2, QVector4D(y,-x,w,-z));
|
m2.setRow(2, QVector4D(y,-x,w,-z));
|
||||||
m2.setRow(3, QVector4D(x,y,z,w));
|
m2.setRow(3, QVector4D(x,y,z,w));
|
||||||
QMatrix4x4 m0= m1 * m2;
|
QMatrix4x4 m0= m1 * m2;
|
||||||
// convert QMatrix4x4 to GLC_Matrix4x4
|
// convert QMatrix4x4 to GLC_Matrix4x4
|
||||||
GLC_Matrix4x4 rootObjectRotation;
|
GLC_Matrix4x4 rootObjectRotation;
|
||||||
for (int i=0; i<16; i++){
|
for (int i=0; i<16; i++){
|
||||||
rootObjectRotation.data()[i]= m0.data()[i];
|
rootObjectRotation.data()[i]= m0.data()[i];
|
||||||
}
|
}
|
||||||
// sets and updates the 3D model's matrix
|
// sets and updates the 3D model's matrix
|
||||||
rootObject->structInstance()->setMatrix(rootObjectRotation);
|
rootObject->structInstance()->setMatrix(rootObjectRotation);
|
||||||
rootObject->updateChildrenAbsoluteMatrix();
|
rootObject->updateChildrenAbsoluteMatrix();
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user