mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
Render the model in earth
This commit is contained in:
parent
19111dacd2
commit
b2b44bd23b
@ -89,20 +89,111 @@ using namespace osgEarth::Annotation;
|
||||
|
||||
OsgEarthviewWidget::OsgEarthviewWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_PaintOnScreen, true);
|
||||
|
||||
osg::Group* root = new osg::Group;
|
||||
osg::Node* earth = osgDB::readNodeFile("/Users/jcotton81/Documents/Programming/osgearth/tests/boston.earth");
|
||||
osgEarth::MapNode * mapNode = osgEarth::MapNode::findMapNode( earth );
|
||||
if (!mapNode)
|
||||
{
|
||||
qDebug() <<"Uhoh";
|
||||
}
|
||||
|
||||
root->addChild(earth);
|
||||
|
||||
osg::Node* airplane = createAirplane();
|
||||
osgEarth::Util::ObjectLocatorNode* uavPos = new osgEarth::Util::ObjectLocatorNode(mapNode->getMap());
|
||||
uavPos->getLocator()->setPosition( osg::Vec3d(-71.0763, 42.34425, 150) );
|
||||
uavPos->addChild(airplane);
|
||||
|
||||
root->addChild(uavPos);
|
||||
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(root);
|
||||
|
||||
QWidget* popupWidget = createViewWidget( createCamera(0,0,600,600,"Earth",true), root);
|
||||
popupWidget->show();
|
||||
setLayout(new QVBoxLayout());
|
||||
//layout()->addWidget(popupWidget);
|
||||
|
||||
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
|
||||
_timer.start( 10 );
|
||||
}
|
||||
|
||||
OsgEarthviewWidget::~OsgEarthviewWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void OsgEarthviewWidget::paint()
|
||||
QWidget* OsgEarthviewWidget::createViewWidget( osg::Camera* camera, osg::Node* scene )
|
||||
{
|
||||
osgViewer::View* view = new osgViewer::View;
|
||||
view->setCamera( camera );
|
||||
|
||||
addView( view );
|
||||
|
||||
view->setSceneData( scene );
|
||||
view->addEventHandler( new osgViewer::StatsHandler );
|
||||
view->getDatabasePager()->setDoPreCompile( true );
|
||||
|
||||
manip = new EarthManipulator();
|
||||
view->setCameraManipulator( manip );
|
||||
|
||||
Grid* grid = new Grid();
|
||||
grid->setControl(0,0,new LabelControl("OpenPilot"));
|
||||
ControlCanvas::get(view, true)->addControl(grid);
|
||||
|
||||
// zoom to a good startup position
|
||||
manip->setViewpoint( Viewpoint(-71.0763, 42.34425, 0, 24.261, -21.6, 1450.0), 5.0 );
|
||||
//manip->setHomeViewpoint(Viewpoint("Boston", osg::Vec3d(-71.0763, 42.34425, 0), 24.261, -21.6, 3450.0));
|
||||
|
||||
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
|
||||
return gw ? gw->getGLWidget() : NULL;
|
||||
}
|
||||
|
||||
void OsgEarthviewWidget::paintEvent(QPaintEvent *event)
|
||||
osg::Camera* OsgEarthviewWidget::createCamera( int x, int y, int w, int h, const std::string& name="", bool windowDecoration=false )
|
||||
{
|
||||
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
|
||||
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
||||
traits->windowName = name;
|
||||
traits->windowDecoration = windowDecoration;
|
||||
traits->x = x;
|
||||
traits->y = y;
|
||||
traits->width = w;
|
||||
traits->height = h;
|
||||
traits->doubleBuffer = true;
|
||||
traits->alpha = ds->getMinimumNumAlphaBits();
|
||||
traits->stencil = ds->getMinimumNumStencilBits();
|
||||
traits->sampleBuffers = ds->getMultiSamples();
|
||||
traits->samples = ds->getNumMultiSamples();
|
||||
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );
|
||||
|
||||
camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
|
||||
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
|
||||
camera->setProjectionMatrixAsPerspective(
|
||||
30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f, 10000.0f );
|
||||
return camera.release();
|
||||
}
|
||||
|
||||
osg::Node* OsgEarthviewWidget::createAirplane()
|
||||
{
|
||||
osg::Group* model = new osg::Group;
|
||||
osg::Node *cessna = osgDB::readNodeFile("/Users/jcotton81/Documents/Programming/OpenPilot/artwork/3D Model/multi/joes_cnc/J14-QT_+.3DS");
|
||||
if(cessna) {
|
||||
osg::MatrixTransform* mt = new osg::MatrixTransform();
|
||||
mt->setMatrix(osg::Matrixd::scale(0.2e0,0.2e0,0.2e0));
|
||||
mt->addChild( cessna );
|
||||
|
||||
model->addChild(mt);
|
||||
} else
|
||||
qDebug() << "Bad model file";
|
||||
return model;
|
||||
}
|
||||
|
||||
void OsgEarthviewWidget::paintEvent( QPaintEvent* event )
|
||||
{ frame(); }
|
||||
|
||||
void OsgEarthviewWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
}
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
|
||||
@ -85,17 +87,27 @@ class OsgEarthviewWidget : public QWidget, public osgViewer::CompositeViewer
|
||||
public:
|
||||
OsgEarthviewWidget(QWidget *parent = 0);
|
||||
~OsgEarthviewWidget();
|
||||
void paint();
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
protected: /* Protected methods */
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
/* Create a osgQt::GraphicsWindowQt to add to the widget */
|
||||
QWidget* createViewWidget( osg::Camera* camera, osg::Node* scene );
|
||||
|
||||
/* Create an osg::Camera which sets up the OSG view */
|
||||
osg::Camera* createCamera( int x, int y, int w, int h, const std::string& name, bool windowDecoration );
|
||||
|
||||
/* Get the model to render */
|
||||
osg::Node* createAirplane();
|
||||
private slots:
|
||||
|
||||
private:
|
||||
private: /* Private methods */
|
||||
|
||||
private: /* Private variables */
|
||||
QTimer _timer;
|
||||
EarthManipulator* manip;
|
||||
};
|
||||
#endif /* OSGEARTHVIEWWIDGET_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user