source: osgVisual/include/draw2D/visual_draw2D.h @ 42

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

Adding first version of osgVisual!!

File size: 5.5 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18#include <osg/Referenced>
19#include <osg/Geometry>
20#include <osg/Geode>
21#include <osg/CoordinateSystemNode>
22#include <osgText/Text>
23#include <osgViewer/Viewer>
24#include <osg/MatrixTransform>
25
26#include <visual_util.h>
27
28
29namespace osgVisual
30{
31
32/**
33 * \brief This class is the interface to place 2D drawings in screen coordinates over the rendered 3D scene, but before POST_RENDER actions like distortion.
34 *
35 * This class is realized as singleton to make sure that only one interface controls the 2D drawing.
36 * It is derived vom osg::Geode to be includable into the scenegraph. At every frame, callbacks are possible to use for updating 2D drawings dynamically.
37 *
38 * If you wish dynamic content in your drawings, implement callbacks in your content geodes. This class is not capable of callbacks, because it is not added into the scenegraph.
39 *
40 *
41 * @author Torben Dannhauer
42 * @date  Sep 2009
43 */ 
44class visual_draw2D : public osg::Referenced
45{
46private:
47        /**
48         * \brief Constructor : Private accessible to prevent instantiation of thsi class by external caller.
49         *
50         */ 
51        visual_draw2D(void);
52
53        /**
54         * \brief Copy-Constructor: Private accessible to prevent copies (from outside) of this class.
55         *
56         * @param cc : Instance to copy. Not relevant because this funtion is not implemented. If this function is not definied,
57         * the compiler would create a public accessible dafault copy constructor.
58         */ 
59        visual_draw2D(const visual_draw2D& cc);
60
61public:
62        /**
63         * \brief Destructor: Public accessible to allow external functions to clean up this singleton.
64         *
65         */ 
66        ~visual_draw2D(void);
67
68        /**
69         * \brief This function returns the singleton instance for usage.
70         *
71         * @return Pointer to the instance.
72         */ 
73        static visual_draw2D* getInstance();
74
75        /**
76         * \brief This function initilizes the 2DDraw interface.
77         *
78         * @param sceneGraphRoot_ : Scene root to add the 2D drawings to.
79         * @param viewer_ : Applications main viewer to get the screen resolution
80         * @return : True if successful.
81         */ 
82        bool init( osg::CoordinateSystemNode *sceneGraphRoot_, osgViewer::Viewer *viewer_ );
83
84        /**
85         * \brief This function shut "drawing interface down.
86         *
87         * It removes all drawables and shuts them down to allow them to uninstall their updater.
88         *
89         */ 
90        void shutdown();
91
92        /**
93         * \brief Call this function to add a Geode with drawables which contain 2d content.
94         *
95         * @param content_ : Geode with drawables to add.
96         * @param name_ : Name to set the geode to for further identification.
97         * @param renderBinDetail_ : Renderbin to add the content to. 99 is the default for HUD
98         * @return : true of adding was successful.
99         */ 
100        bool addDrawContent( osg::Geode* content_, std::string name_,int renderBinDetail_ = 99 );
101
102        /**
103         * \brief This function returns a content geode if the name matches the specified one.
104         *
105         * @param name_ : content to search after.
106         * @return : Pointer to the found geode. If no Node with that name is found, NULL is returned.
107         */ 
108        osg::Geode* getDrawContent( std::string name_ );
109
110        /**
111         * \brief This function removes Drawcontent specified by name_.
112         *
113         * @param name_ : Name of drawcontent to remove.
114         * @return : Returns true if drawcontent was found and successfully removed.
115         */ 
116        bool removeDrawContent( std::string name_ );
117       
118        /**
119         * \brief This function removes all drawContents.
120         *
121         */ 
122        void removeAllDrawContents();
123
124        /**
125         * \brief This function returns the number of registered drawContents.
126         *
127         * @return : Number of registered drawContents.
128         */ 
129        inline int getDrawContentNum();
130
131private:
132        /**
133         * This camera ist NESTED_RENDER and renders all "D drawings.
134         *
135         * It is rendered after the 3D scene but before POST_RENDER cameras like distortion.
136         */ 
137        osg::ref_ptr<osg::Camera> camera;
138
139        /**
140         * This Modelviewematrix is the parent for all geodes which contain 2D drawings. To be known by the addContent() funtion, it is a classwide member attribute.
141         */ 
142        osg::ref_ptr<osg::MatrixTransform> draw2DModelViewMatrix;
143
144        /**
145         * This Projectionmatrix connects the global scenegraph with the 2D modelview matrix. It is used to disconnect the 2D drawing subgraph from the global scenegrpah on shutdown.
146         */ 
147        osg::ref_ptr<osg::Projection> draw2DProjectionMatrix;
148
149        /**
150         * This flag indicated whether the draw2D interface is initialized.
151         */ 
152        bool initialized;
153
154        /**
155         * This variable contains the width of the rendering screen during the initialization of this node.
156         */ 
157        int screen_width;
158
159        /**
160         * This variable contains the height of the rendering screen during the initialization of this node.
161         */ 
162        int screen_height;
163};
164
165}       // END NAMESPACE
Note: See TracBrowser for help on using the repository browser.