Browse Source

Hooked up map/vehicle buttons for osgearth.

QGC4.4
James Goppert 14 years ago
parent
commit
a50b0425ea
  1. 24
      src/ui/map3D/QMap3D.cc
  2. 3
      src/ui/map3D/QMap3D.h
  3. 3
      src/ui/map3D/QOSGWidget.h

24
src/ui/map3D/QMap3D.cc

@ -31,20 +31,34 @@ This file is part of the QGROUNDCONTROL project @@ -31,20 +31,34 @@ This file is part of the QGROUNDCONTROL project
#include "QMap3D.h"
#include <osgEarthUtil/EarthManipulator>
#include <stdexcept>
#include <QFileDialog>
QMap3D::QMap3D(QWidget * parent, const char * name, WindowFlags f) :
QWidget(parent,f)
{
setupUi(this);
osg::ref_ptr<osg::Node> map = osgDB::readNodeFile("data/yahoo_heightfield.earth");
if (!map) throw std::runtime_error("unable to load file");
graphicsView->updateCamera();
graphicsView->setCameraManipulator(new osgEarthUtil::EarthManipulator);
graphicsView->setSceneData(map);
graphicsView->setSceneData(new osg::Group);
graphicsView->updateCamera();
show();
}
QMap3D::~QMap3D()
{
}
void QMap3D::on_pushButton_map_clicked()
{
QString mapName = QFileDialog::getOpenFileName(this, tr("Select an OsgEarth map file"),
QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("OsgEarth file (*.earth);;"));
graphicsView->getSceneData()->asGroup()->addChild(osgDB::readNodeFile(mapName.toStdString()));
graphicsView->updateCamera();
}
void QMap3D::on_pushButton_vehicle_clicked()
{
QString vehicleName = QFileDialog::getOpenFileName(this, tr("Select a 3D model for your vehicle"),
QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("OsgEarth file (*.osg, *.ac, *.3ds);;"));
graphicsView->getSceneData()->asGroup()->addChild(osgDB::readNodeFile(vehicleName.toStdString()));
graphicsView->updateCamera();
}

3
src/ui/map3D/QMap3D.h

@ -45,6 +45,9 @@ class QMap3D : public QWidget, private Ui::QMap3D @@ -45,6 +45,9 @@ class QMap3D : public QWidget, private Ui::QMap3D
public:
QMap3D(QWidget * parent = 0, const char * name = 0, WindowFlags f = 0);
~QMap3D();
public slots:
void on_pushButton_map_clicked();
void on_pushButton_vehicle_clicked();
};
#endif // QMAP3D_H

3
src/ui/map3D/QOSGWidget.h

@ -133,8 +133,7 @@ class ViewerQOSG : public osgViewer::Viewer, public QOSGWidget @@ -133,8 +133,7 @@ class ViewerQOSG : public osgViewer::Viewer, public QOSGWidget
void updateCamera()
{
getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
// we want an aspect ratio of 1.0, not: static_cast<double>(width())/static_cast<double>(height())
getCamera()->setProjectionMatrixAsPerspective(30.0f, 1.0f , 1.0f, 10000.0f);
getCamera()->setProjectionMatrixAsPerspective(30.0f, 1.0f , static_cast<double>(width())/static_cast<double>(height()), 10000.0f);
getCamera()->setGraphicsContext(getGraphicsWindow());
}

Loading…
Cancel
Save