source: osgVisual/src/vista2D/visual_vista2D.cpp @ 139

Last change on this file since 139 was 31, checked in by Torben Dannhauer, 15 years ago

Adding first version of osgVisual!!

File size: 4.3 KB
RevLine 
[31]1/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
2 *
3 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
9 * You have to aquire licenses for all used proprietary modules.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * OpenSceneGraph Public License for more details.
15*/
16
17#include "visual_vista2D.h"
18
19
20using namespace osgVisual;
21
22visual_vista2D::visual_vista2D(void)
23{
24   // Create a Vista2D View
25   view = new Vista2D::VistaView();
26}
27
28visual_vista2D::~visual_vista2D(void)
29{
30}
31
32void visual_vista2D::init(std::string vista2DFilename_)
33{       
34    /***************
35    load view
36    ***************/
37        view->load( vista2DFilename_ );
38    view->setBackgroundMode(false);     // don't paint background
39        view->setPosition(800,450);
40        view->setZoom( 0.5 );
41
42    /***************
43    start animation with
44    self running datasource
45    ***************/
46    view->startView (true);
47
48}
49
50bool visual_vista2D::createVistaOverlay( std::string vista2DFilename_, osg::CoordinateSystemNode *sceneGraphRoot_ )
51{
52        // Check if Vista2D file exist
53        if (! osgDB::fileExists( vista2DFilename_ ) )
54        {
55                osg::notify( osg::WARN ) << "WARNING: Could not find specified Vista2D projectfile. Skip adding Vista2D project." << std::endl;
56                return false;
57        }
58
59   osg::Geode* vista2Dgeode = new osg::Geode();
60   // Projection node for defining view frustrum for the vista2D-SceneOverlay:
61   osg::Projection* vista2DProjectionMatrix = new osg::Projection;
62
63    // Initialize the projection matrix for viewing everything we
64   // will add as descendants of this node. Use screen coordinates
65   // to define the horizontal and vertical extent of the projection
66   // matrix. Positions described under this node will equate to
67   // pixel coordinates.
68   vista2DProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,1600,0,900));
69 
70   // For the HUD model view matrix use an identity matrix:
71   osg::MatrixTransform* vista2DModelViewMatrix = new osg::MatrixTransform;
72   vista2DModelViewMatrix->setMatrix(osg::Matrix::identity());
73
74   // Make sure the model view matrix is not affected by any transforms
75   // above it in the scene graph:
76   vista2DModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
77
78   // Set Stateset of vista2DGeode Renderbin to render quite late..
79        osg::StateSet* vista2DoverlayStateSet = vista2Dgeode->getOrCreateStateSet();
80        vista2DoverlayStateSet->setRenderBinDetails( 99, "RenderBin");
81
82   // Add the HUD projection matrix as a child of the root node
83   // and the HUD model view matrix as a child of the projection matrix
84   // Anything under this node will be viewed using this projection matrix
85   // and positioned with this model view matrix.
86   vista2DProjectionMatrix->addChild(vista2DModelViewMatrix);
87
88   // Add the Geometry node to contain HUD geometry as a child of the
89   // HUD model view matrix.
90   vista2DModelViewMatrix->addChild( vista2Dgeode );
91
92        // Add Payload: Vista2D                 
93        osg::ref_ptr<visual_vista2D> vista2D = new visual_vista2D();
94        vista2D->init( vista2DFilename_ );
95
96        vista2D.get()->setUseDisplayList( false );
97        vista2Dgeode->addDrawable( vista2D.get() );
98
99        sceneGraphRoot_->addChild( vista2DProjectionMatrix );
100        return true;
101}
102
103void visual_vista2D::drawImplementation(osg::RenderInfo& renderInfo) const
104{
105        // save OSG-State
106        osg::ref_ptr<osg::StateSet> clonedStateSet = reinterpret_cast<osg::StateSet*>( renderInfo.getCurrentCamera()->getOrCreateStateSet()->clone(osg::CopyOp::DEEP_COPY_ALL) );
107
108        // Draw View
109    view->draw();
110
111        // restore OSG-State
112        renderInfo.getCurrentCamera()->setStateSet( clonedStateSet );
113
114}
115
116osg::Object* visual_vista2D::cloneType() const
117{
118        return NULL;
119}
120
121osg::Object* visual_vista2D::clone(const osg::CopyOp& copyop) const
122{ 
123        return NULL;
124}
Note: See TracBrowser for help on using the repository browser.