AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SceneDecorator.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agxOSG/export.h>
20 
21 
22 #include <agx/Vec3.h>
23 #include <agx/Vec4.h>
24 
25 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
26 #include <osg/Referenced>
27 #include <osg/Group>
28 #include <osg/Texture2D>
29 #include <osg/MatrixTransform>
30 #include <osg/Projection>
31 #include <osg/StateSet>
32 #include <osg/PositionAttitudeTransform>
33 #include <osg/Switch>
34 #include <osg/Material>
35 #include <osgShadow/ShadowedScene>
36 #include <osgShadow/ShadowTechnique>
37 #include <osg/LightSource>
38 #include <osg/Geometry>
39 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
40 #include <agxOSG/LightSource.h>
41 
42 
43 namespace agxRender
44 {
45  class Color;
46 }
47 
48 namespace osgText
49 {
50  class Text;
51 }
52 
54 namespace agxOSG
55 {
57 
62  class AGXOSG_EXPORT SceneDecorator : public osg::Group
63  {
64  public:
65 
72  SceneDecorator( int windowSizeX, int windowSizeY, int enabledLights = LIGHT0 | LIGHT1 );
73 
75  void setEnableShadows( bool flag );
76 
78  bool getEnableShadows() const;
79 
81  void setEnable( bool flag );
82 
84  bool getEnable() const;
85 
87  bool isEnabled() const;
88 
90  enum LogoLocation {
91  UPPER_LEFT = 0x1,
92  LOWER_LEFT = 0x2,
93  UPPER_RIGHT = 0x3,
94  LOWER_RIGHT = 0x4,
95  FREE
96  };
97 
102  void setLogoLocation( LogoLocation l );
103 
105  LogoLocation getLogoLocation() const;
106 
111  void setLogoPosition(float x, float y);
112 
114  void setEnableLogo( bool flag );
115 
117  bool getEnableLogo() const;
118 
120  bool setLogoFile(const std::string& filename);
121 
123  void setText( int row, const agx::String& text );
124  void setText( int row, const agx::String& text, const agx::Vec4f& color );
125 
129  void setEnableShaderState( bool flag, bool lock=false );
130 
132  bool getEnableShaderState( ) const;
133 
135  void clearText();
140  bool setBaseTexture(const std::string& imagePath);
141 
145  const osg::Vec2& getLogoDimension();
146 
150  osg::Vec2 getMaximumLogoDimension();
151 
156  void setMaximumLogoDimension(float x, float y);
157 
161  static osg::Vec2 getDefaultLogoPosition();
162 
169  osg::MatrixTransform* getHud() { return m_hudRoot.get(); }
170 
171  // Overriding add/remove child methods
172  virtual bool insertChild( unsigned int index, osg::Node *child ) { return m_currentRoot->insertChild(index, child); }
173  virtual bool addChild(osg::Node *child) { return m_currentRoot->addChild(child); }
174  inline bool removeChild( osg::Node *child ) { return m_currentRoot->removeChild(child); }
175  inline bool removeChild( unsigned int pos, unsigned int numChildrenToRemove=1 ) { return m_currentRoot->removeChild(pos, numChildrenToRemove); }
176  virtual bool replaceChild( osg::Node *origChild, osg::Node* newChild ) { return m_currentRoot->replaceChild(origChild, newChild); }
177  virtual bool setChild( unsigned int i, osg::Node* node ) { return m_currentRoot->setChild(i, node); }
178  virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { return m_currentRoot->removeChildren(pos, numChildrenToRemove); }
179 
184  void calculateLightPositions(osg::Node* bound_node = nullptr);
185 
186  void calculateLightPositions( const osg::BoundingBox& boundingBox );
187 
188  void calculateLightPositions( const osg::BoundingSphere& boundingSphere );
189 
191  std::string getFontName() const;
192 
194  void setFontName(const std::string& fontName);
195 
197  void updateWindowSize(int sizeX, int sizeY);
198 
200  float getFontSize() const;
201 
203  void setFontSize(const float& fontSize);
204 
206  osg::LightSource* getShadowLightSource();
207 
208  enum Lights {
209  LIGHT0 = 0x1,
210  LIGHT1 = 0x2,
211  LIGHT2 = 0x4,
212  ALL = LIGHT0 | LIGHT1 | LIGHT2
213  };
214 
215 
216  static size_t lightToIndex(Lights l);
217 
218  void setEnableCalculateLightPositions( Lights l, bool f );
219 
220  bool getEnableCalculateLightPositions(Lights l) const;
221 
223  bool setShadowLightSource( Lights l);
224 
225  osg::StateSet* getDecoratorStateSet() { return m_decoratorStateSet; }
226 
227  osg::LightSource* getOSGLight(Lights l);
228 
230  agxOSG::LightSource getLightSource(Lights l);
231 
239  NO_SHADOWS
240  };
241 
243  void setShadowMethod(ShadowMethod m);
244 
246  ShadowMethod getShadowMethod() const { return m_shadowMethod; }
247 
249  void setBackgroundColor(const agx::Vec4f& color);
250 
256  void setBackgroundColor(const agx::Vec4f& color1, const agx::Vec4f& color2);
257 
265  void setBackgroundColor(const agx::Vec4f& colorUL, const agx::Vec4f& colorUR, const agx::Vec4f& colorLL, const agx::Vec4f& colorLR);
266 
267 
269  void setBackgroundColor(agx::Vec3 color);
270 
276  void setBackgroundColor(agx::Vec3 upper, agx::Vec3 lower);
277 
285  void setBackgroundColor(agx::Vec3 colorUL, agx::Vec3 colorUR, agx::Vec3 colorLL, agx::Vec3 colorLR);
286 
291  void setEnableLights(int lightMask = ALL);
292 
297  void setEnableRenderedCursor( bool enable );
298  bool getEnableRenderedCursor() const;
299  void updateCursorPosition( float x, float y );
300 
301  osg::Texture2D* getLogo();
302 
304  void setLogo(osg::Texture2D* logo);
305 
306  // Will reset the rendering HUD.
307  void resetHUD();
308 
312  osg::Group* getShadowedScene() const;
313 
317  osg::Group* getNonShadowedScene() const;
318 
319  static const osg::Material* getDefaultDecoratorMaterial();
320 
321  protected:
325  void updateLogo();
326  void createHUD();
327 
328  void createLogo();
329  void createBackground();
330 
331  void init(Lights l);
332 
333  osg::ref_ptr<osg::Group> m_enabledRoot;
334  osg::ref_ptr<osg::Group> m_enabledNonShadowRoot;
335  osg::ref_ptr<osg::Group> m_currentRoot;
336  osg::ref_ptr<osg::Group> m_disabledRoot;
337  osg::ref_ptr<osg::Group> m_disabledNonShadowRoot;
338  osg::ref_ptr<osg::Switch> m_backgroundRoot;
339  osg::observer_ptr<osg::Geometry> m_backgroundQuad;
341  osg::ref_ptr<osg::Texture2D> m_logoTexture;
342  osg::ref_ptr<osg::PositionAttitudeTransform> m_logoTransform;
343  osg::ref_ptr<osg::Switch> m_logoSwitch;
344  osg::ref_ptr<osg::MatrixTransform> m_hudRoot;
345  osg::ref_ptr<osg::StateSet> m_logoStateSet;
348  bool m_enabled;
351  std::string m_baseTexturePath;
353  std::string m_fontName;
354  float m_fontSize;
360 
361  osg::ref_ptr<osgShadow::ShadowedScene> m_shadowedScene;
362  osg::ref_ptr<osgShadow::ShadowTechnique> m_shadowTechnique;
363 
364  osg::ref_ptr<osg::StateSet> m_decoratorStateSet;
365 
367  osg::ref_ptr<osg::LightSource> m_ShadowlightSource;
368  osg::ref_ptr<osg::Vec3Array> m_backgroundColors;
369 
370  void createDecoratorState();
371 
372  virtual ~SceneDecorator();
373 
374  bool m_calculateLightPosition[3];
375 
376  osg::ref_ptr<osg::Node> m_cursorTransform;
377  osg::ref_ptr<osg::Camera> m_hudCamera;
378  osg::ref_ptr<osg::Projection> m_hudProjection;
379 
382 
383  static osg::ref_ptr<osg::Material> s_decoratorMaterial;
384  };
385 }
osg::ref_ptr< osg::Node > m_cursorTransform
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
void AGXPHYSICS_EXPORT init()
Initialize agx.
#define AGXOSG_EXPORT
osg::ref_ptr< osg::Switch > m_logoSwitch
osg::ref_ptr< osg::Vec3Array > m_backgroundColors
virtual bool insertChild(unsigned int index, osg::Node *child)
virtual bool setChild(unsigned int i, osg::Node *node)
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
osg::MatrixTransform * getHud()
Return a pointer to the hud group.
osg::ref_ptr< osg::Group > m_enabledNonShadowRoot
osg::ref_ptr< osg::PositionAttitudeTransform > m_logoTransform
LogoLocation
Specifies the location of the logo.
Vec2T< Real > Vec2
The object holding 2 dimensional vectors and providing basic arithmetic.
Definition: Vec2.h:35
osg::ref_ptr< osg::Switch > m_backgroundRoot
ShadowMethod m_shadowMethod
osg::ref_ptr< osg::LightSource > m_ShadowlightSource
Decorates a scene with a specific AGX Rendering Style.
bool removeChild(unsigned int pos, unsigned int numChildrenToRemove=1)
osg::ref_ptr< osgShadow::ShadowedScene > m_shadowedScene
osg::ref_ptr< osg::StateSet > m_decoratorStateSet
Templated vector class.
Definition: Vector.h:52
osg::ref_ptr< osgShadow::ShadowTechnique > m_shadowTechnique
bool removeChild(osg::Node *child)
osg::observer_ptr< osg::Geometry > m_backgroundQuad
osg::ref_ptr< osg::MatrixTransform > m_hudRoot
agx::Vector< osg::ref_ptr< osg::LightSource > > m_lightSources
ShadowMethod getShadowMethod() const
static osg::ref_ptr< osg::Material > s_decoratorMaterial
virtual bool replaceChild(osg::Node *origChild, osg::Node *newChild)
osg::ref_ptr< osg::Camera > m_hudCamera
osg::ref_ptr< osg::Group > m_currentRoot
osg::ref_ptr< osg::StateSet > m_logoStateSet
osg::ref_ptr< osg::Group > m_disabledRoot
std::string m_baseTexturePath
osg::ref_ptr< osg::Projection > m_hudProjection
osg::ref_ptr< osg::Group > m_disabledNonShadowRoot
osg::ref_ptr< osg::Group > m_enabledRoot
osg::StateSet * getDecoratorStateSet()
virtual bool addChild(osg::Node *child)
LogoLocation m_logoLocation
osg::ref_ptr< osg::Texture2D > m_logoTexture
agx::Vector< osgText::Text * > m_text