source: osgVisual/trunk/include/draw2D/visual_draw2D.h @ 364

Last change on this file since 364 was 221, checked in by Torben Dannhauer, 14 years ago

Updated copyright NOTICE
(No code changes)

File size: 5.5 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 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        #include <leakDetection.h>
32
33/**
34 * \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.
35 *
36 * This class is realized as singleton to make sure that only one interface controls the 2D drawing.
37 * 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.
38 *
39 * 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.
40 *
41 *
42 * @author Torben Dannhauer
43 * @date  Sep 2009
44 */ 
45class visual_draw2D : public osg::Referenced
46{
47private:
48        /**
49         * \brief Constructor : Private accessible to prevent instantiation of thsi class by external caller.
50         *
51         */ 
52        visual_draw2D(void);
53
54        /**
55         * \brief Copy-Constructor: Private accessible to prevent copies (from outside) of this class.
56         *
57         * @param cc : Instance to copy. Not relevant because this funtion is not implemented. If this function is not definied,
58         * the compiler would create a public accessible dafault copy constructor.
59         */ 
60        visual_draw2D(const visual_draw2D& cc);
61
62public:
63        /**
64         * \brief Destructor: Public accessible to allow external functions to clean up this singleton.
65         *
66         */ 
67        ~visual_draw2D(void);
68
69        /**
70         * \brief This function returns the singleton instance for usage.
71         *
72         * @return Pointer to the instance.
73         */ 
74        static visual_draw2D* getInstance();
75
76        /**
77         * \brief This function initilizes the 2DDraw interface.
78         *
79         * @param sceneGraphRoot_ : Scene root to add the 2D drawings to.
80         * @param viewer_ : Applications main viewer to get the screen resolution
81         * @return : True if successful.
82         */ 
83        bool init( osg::CoordinateSystemNode *sceneGraphRoot_, osgViewer::Viewer *viewer_ );
84
85        /**
86         * \brief This function shut "drawing interface down.
87         *
88         * It removes all drawables and shuts them down to allow them to uninstall their updater.
89         *
90         */ 
91        void shutdown();
92
93        /**
94         * \brief Call this function to add a Geode with drawables which contain 2d content.
95         *
96         * @param content_ : Geode with drawables to add.
97         * @param name_ : Name to set the geode to for further identification.
98         * @param renderBinDetail_ : Renderbin to add the content to. 99 is the default for HUD
99         * @return : true of adding was successful.
100         */ 
101        bool addDrawContent( osg::Geode* content_, std::string name_,int renderBinDetail_ = 99 );
102
103        /**
104         * \brief This function returns a content geode if the name matches the specified one.
105         *
106         * @param name_ : content to search after.
107         * @return : Pointer to the found geode. If no Node with that name is found, NULL is returned.
108         */ 
109        osg::Geode* getDrawContent( std::string name_ );
110
111        /**
112         * \brief This function removes Drawcontent specified by name_.
113         *
114         * @param name_ : Name of drawcontent to remove.
115         * @return : Returns true if drawcontent was found and successfully removed.
116         */ 
117        bool removeDrawContent( std::string name_ );
118       
119        /**
120         * \brief This function removes all drawContents.
121         *
122         */ 
123        void removeAllDrawContents();
124
125        /**
126         * \brief This function returns the number of registered drawContents.
127         *
128         * @return : Number of registered drawContents.
129         */ 
130        inline int getDrawContentNum();
131
132private:
133        /**
134         * This camera ist NESTED_RENDER and renders all "D drawings.
135         *
136         * It is rendered after the 3D scene but before POST_RENDER cameras like distortion.
137         */ 
138        osg::ref_ptr<osg::Camera> camera;
139
140        /**
141         * 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.
142         */ 
143        osg::ref_ptr<osg::MatrixTransform> draw2DModelViewMatrix;
144
145        /**
146         * 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.
147         */ 
148        osg::ref_ptr<osg::Projection> draw2DProjectionMatrix;
149
150        /**
151         * This flag indicated whether the draw2D interface is initialized.
152         */ 
153        bool initialized;
154
155        /**
156         * This variable contains the width of the rendering screen during the initialization of this node.
157         */ 
158        int screen_width;
159
160        /**
161         * This variable contains the height of the rendering screen during the initialization of this node.
162         */ 
163        int screen_height;
164};
165
166}       // END NAMESPACE
Note: See TracBrowser for help on using the repository browser.