/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer * * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. * You have to aquire licenses for all used proprietary modules. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include "visual_vista2D.h" using namespace osgVisual; visual_vista2D::visual_vista2D(void) { // Create a Vista2D View view = new Vista2D::VistaView(); } visual_vista2D::~visual_vista2D(void) { } void visual_vista2D::init(std::string vista2DFilename_) { /*************** load view ***************/ view->load( vista2DFilename_ ); view->setBackgroundMode(false); // don't paint background view->setPosition(800,450); view->setZoom( 0.5 ); /*************** start animation with self running datasource ***************/ view->startView (true); } bool visual_vista2D::createVistaOverlay( std::string vista2DFilename_, osg::CoordinateSystemNode *sceneGraphRoot_ ) { // Check if Vista2D file exist if (! osgDB::fileExists( vista2DFilename_ ) ) { osg::notify( osg::WARN ) << "WARNING: Could not find specified Vista2D projectfile. Skip adding Vista2D project." << std::endl; return false; } osg::Geode* vista2Dgeode = new osg::Geode(); // Projection node for defining view frustrum for the vista2D-SceneOverlay: osg::Projection* vista2DProjectionMatrix = new osg::Projection; // Initialize the projection matrix for viewing everything we // will add as descendants of this node. Use screen coordinates // to define the horizontal and vertical extent of the projection // matrix. Positions described under this node will equate to // pixel coordinates. vista2DProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,1600,0,900)); /** todo: use screen size dynamically. */ // For the HUD model view matrix use an identity matrix: osg::MatrixTransform* vista2DModelViewMatrix = new osg::MatrixTransform; vista2DModelViewMatrix->setMatrix(osg::Matrix::identity()); // Make sure the model view matrix is not affected by any transforms // above it in the scene graph: vista2DModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF); // Set Stateset of vista2DGeode Renderbin to render quite late.. osg::StateSet* vista2DoverlayStateSet = vista2Dgeode->getOrCreateStateSet(); vista2DoverlayStateSet->setRenderBinDetails( 99, "RenderBin"); // Add the HUD projection matrix as a child of the root node // and the HUD model view matrix as a child of the projection matrix // Anything under this node will be viewed using this projection matrix // and positioned with this model view matrix. vista2DProjectionMatrix->addChild(vista2DModelViewMatrix); // Add the Geometry node to contain HUD geometry as a child of the // HUD model view matrix. vista2DModelViewMatrix->addChild( vista2Dgeode ); // Add Payload: Vista2D osg::ref_ptr vista2D = new visual_vista2D(); vista2D->init( vista2DFilename_ ); vista2D.get()->setUseDisplayList( false ); vista2Dgeode->addDrawable( vista2D.get() ); sceneGraphRoot_->addChild( vista2DProjectionMatrix ); return true; } void visual_vista2D::drawImplementation(osg::RenderInfo& renderInfo) const { // save OSG-State osg::ref_ptr clonedStateSet = reinterpret_cast( renderInfo.getCurrentCamera()->getOrCreateStateSet()->clone(osg::CopyOp::DEEP_COPY_ALL) ); // Draw View view->draw(); // restore OSG-State renderInfo.getCurrentCamera()->setStateSet( clonedStateSet ); } osg::Object* visual_vista2D::cloneType() const { return NULL; } osg::Object* visual_vista2D::clone(const osg::CopyOp& copyop) const { return NULL; }