AGX Dynamics  2.35.0.1
RenderingWrapper.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 #ifndef AGXOSG_RENDERINGWRAPPER_H
18 #define AGXOSG_RENDERINGWRAPPER_H
19 
20 #if defined(SWIG) || defined(_MSC_VER)
21 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
22 #include <Winsock2.h>
23 #include <agx/Windows.h>
24 
25 #include <GL/gl.h>
26 
27 #include <osgViewer/Viewer>
28 #include <osg/Version>
29 #include <osgGA/TrackBallManipulator>
30 #if defined(OSG_VERSION_GREATER_OR_EQUAL)
31 # if OSG_VERSION_GREATER_OR_EQUAL(3,0,0)
32 # include <osgViewer/api/Win32/GraphicsWindowWin32>
33 # else
34 # include <osgViewer/GraphicsWindowWin32>
35 # endif
36 #else
37 # include <osgViewer/GraphicsWindowWin32>
38 #endif
39 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
40 
41 #include <agxOSG/export.h>
42 #include <agx/Integer.h>
43 #include <agxSDK/Simulation.h>
44 #include <agxOSG/RenderProxy.h>
45 
46 
47 
48 namespace agxOSG
49 {
50  class AGXOSG_EXPORT GraphicsNode
51  {
52  public:
53  GraphicsNode(osg::Node* node);
54  ~GraphicsNode();
55 
56  osg::Node* getNode() const;
57 
62  bool setTexture(const agx::String& imagePath, bool repeat = false, agxOSG::TextureMode textureMode = agxOSG::DIFFUSE_TEXTURE, float scaleX = 1.0f, float scaleY = 1.0f);
63 
68  void setSpecularColor(const agx::Vec4f& color);
69 
73  void setShininess(float shininess);
74 
79  void setAmbientColor(const agx::Vec4f& color);
80 
84  void setAlpha(float alpha);
85 
90  void setDiffuseColor(const agx::Vec4f& color);
91 
92  private:
93  osg::observer_ptr< osg::Node > m_node;
94  };
95 
96  class AGXOSG_EXPORT GraphicsWindow
97  {
98  public:
99  enum WindowFunctionDisable
100  {
101  NONE = 0x0,
102  FULLSCREEN = 0x1
103  };
104 
105  GraphicsWindow();
106  bool init(agx::Int64 handle, int disabledFunctions = NONE);
107 
108  void frame();
109 
110  void setActiveSimulation(agxSDK::Simulation *simulation);
111  agxSDK::Simulation *getActiveSimulation() const;
112  void removeSimulation(agxSDK::Simulation *simulation);
113 
114  osg::Group* getRoot();
115 
116  void fitSceneIntoView();
117 
118  agxOSG::GraphicsNode* getVisual(const agx::RigidBody* rb) const;
119  agxOSG::GraphicsNode* getOrCreateVisual(agx::RigidBody* rb);
120  agxOSG::GraphicsNode* getVisual(const agxCollide::Geometry* geometry) const;
121  agxOSG::GraphicsNode* getOrCreateVisual(agxCollide::Geometry* geometry);
122 
123  ~GraphicsWindow();
124 
125  private:
126  bool initOpenGLContext(HWND);
127  bool initOSG(HWND hwnd, int disabledFunctions);
128  bool setPixelFormat(HDC hdc);
129  void initCamera(osg::Camera *camera);
130 
131  HDC m_hDC;
132  HGLRC m_hglrc;
133 
134  osg::ref_ptr<osgViewer::Viewer> m_viewer;
135  agxSDK::Simulation *m_activeSimulation;
136  osg::ref_ptr<osg::Group> m_root;
137  osgGA::StandardManipulator *m_manipulator;
138 
139  osg::ref_ptr<osg::GraphicsContext::Traits> m_traits;
140  osg::ref_ptr<osg::GraphicsContext> m_graphicsContext;
141  struct SimulationViewContext {
143  osg::ref_ptr<osg::Camera> camera;
144  };
145 
147  SimulationFactoryTable m_factoryTable;
148 
149  typedef agx::HashVector< const agx::RigidBody*, GraphicsNode > RigidBodyGraphicsNodeContainer;
150  typedef agx::HashVector< const agxCollide::Geometry*, GraphicsNode > GeometryGraphicsNodeContainer;
151  RigidBodyGraphicsNodeContainer m_rbNodes;
152  GeometryGraphicsNodeContainer m_geometryNodes;
153  };
154 }
155 
156 
157 #endif // _MSC_VER
158 #endif
159 /*
160 Copyright 2007-2022. Algoryx Simulation AB.
161 
162 All AGX source code, intellectual property, documentation, sample code,
163 tutorials, scene files and technical white papers, are copyrighted, proprietary
164 and confidential material of Algoryx Simulation AB. You may not download, read,
165 store, distribute, publish, copy or otherwise disseminate, use or expose this
166 material unless having a written signed agreement with Algoryx Simulation AB, or having been
167 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
168 valid commercial license from Algoryx Simulation AB.
169 
170 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
171 from using this software, unless otherwise stated in written agreements with
172 Algoryx Simulation AB.
173 */
174 
175 #ifndef AGXOSG_RENDERINGWRAPPER_H
176 #define AGXOSG_RENDERINGWRAPPER_H
177 
178 #if defined(SWIG) || defined(_MSC_VER)
179 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
180 #include <Winsock2.h>
181 #include <agx/Windows.h>
182 
183 #include <GL/gl.h>
184 
185 #include <osgViewer/Viewer>
186 #include <osg/Version>
187 #include <osgGA/TrackBallManipulator>
188 #if defined(OSG_VERSION_GREATER_OR_EQUAL)
189 # if OSG_VERSION_GREATER_OR_EQUAL(3,0,0)
190 # include <osgViewer/api/Win32/GraphicsWindowWin32>
191 # else
192 # include <osgViewer/GraphicsWindowWin32>
193 # endif
194 #else
195 # include <osgViewer/GraphicsWindowWin32>
196 #endif
197 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
198 
199 #include <agxOSG/export.h>
200 #include <agx/Integer.h>
201 #include <agxSDK/Simulation.h>
202 #include <agxOSG/RenderProxy.h>
203 
204 
205 
206 namespace agxOSG
207 {
208  class AGXOSG_EXPORT GraphicsNode
209  {
210  public:
211  GraphicsNode( osg::Node* node );
212  ~GraphicsNode();
213 
214  osg::Node* getNode() const;
215 
220  bool setTexture( const agx::String& imagePath, bool repeat=false, agxOSG::TextureMode textureMode = agxOSG::DIFFUSE_TEXTURE, float scaleX = 1.0f, float scaleY = 1.0f );
221 
226  void setSpecularColor( const agx::Vec4f& color );
227 
231  void setShininess( float shininess );
232 
237  void setAmbientColor( const agx::Vec4f& color );
238 
242  void setAlpha( float alpha );
243 
248  void setDiffuseColor( const agx::Vec4f& color );
249 
250  private:
251  osg::observer_ptr< osg::Node > m_node;
252  };
253 
254  class AGXOSG_EXPORT GraphicsWindow
255  {
256  public:
257  enum WindowFunctionDisable
258  {
259  NONE = 0x0,
260  FULLSCREEN = 0x1
261  };
262 
263  GraphicsWindow( );
264  bool init( agx::Int64 handle, int disabledFunctions = NONE );
265 
266  bool initEmbeddedQT(int x, int y, int width, int height, float scale = 1.0f);
267  void resize(int x, int y, int width, int height);
268  osgGA::EventQueue* getEventQueue() const;
269 
270  void mouseMoveEvent(int x, int y);
271 
272  void mousePressEvent(int x, int y, int button);
273 
274  void mouseReleaseEvent(int x, int y, int button);
275 
276  void keyPressEvent(int key, int mod_key);
277  void keyReleaseEvent(int key, int mod_key);
278 
279  void wheelEvent(int motion);
280 
281  void frame();
282 
283  void setActiveSimulation( agxSDK::Simulation *simulation );
284  agxSDK::Simulation *getActiveSimulation() const;
285  void removeSimulation( agxSDK::Simulation *simulation );
286 
287  osg::Group* getRoot();
288  agxOSG::SceneDecorator* getSceneDecorator();
289 
290  void fitSceneIntoView();
291 
292  agxOSG::GraphicsNode* getVisual( const agx::RigidBody* rb ) const;
293  agxOSG::GraphicsNode* getOrCreateVisual( agx::RigidBody* rb );
294  agxOSG::GraphicsNode* getVisual( const agxCollide::Geometry* geometry ) const;
295  agxOSG::GraphicsNode* getOrCreateVisual( agxCollide::Geometry* geometry );
296 
297  ~GraphicsWindow();
298 
299  void clear();
300 
301  private:
302  bool initOpenGLContext( HWND );
303  bool initOSG( HWND hwnd, int disabledFunctions );
304  bool setPixelFormat(HDC hdc);
305  void initCamera( osg::Camera *camera );
306 
307  HDC m_hDC;
308  HGLRC m_hglrc;
309 
310  osg::ref_ptr<osgViewer::Viewer> m_viewer;
311  agxSDK::Simulation *m_activeSimulation;
312  osg::ref_ptr<osg::Group> m_root;
313  osg::ref_ptr<agxOSG::SceneDecorator> m_decorator;
314  osgGA::StandardManipulator *m_manipulator;
315 
316  osg::ref_ptr<osg::GraphicsContext::Traits> m_traits;
317  osg::ref_ptr<osg::GraphicsContext> m_graphicsContext;
318  struct SimulationViewContext {
320  osg::ref_ptr<osg::Camera> camera;
321  };
322 
324  SimulationFactoryTable m_factoryTable;
325 
326  typedef agx::HashVector< const agx::RigidBody*, GraphicsNode > RigidBodyGraphicsNodeContainer;
327  typedef agx::HashVector< const agxCollide::Geometry*, GraphicsNode > GeometryGraphicsNodeContainer;
328  RigidBodyGraphicsNodeContainer m_rbNodes;
329  GeometryGraphicsNodeContainer m_geometryNodes;
330  osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_embeddedWindow;
331  float m_scale;
332  };
333 }
334 
335 
336 #endif // _MSC_VER
337 #endif
#define AGXOSG_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Decorates a scene with a specific AGX Rendering Style.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Inheritance with partial specialization due to bug with ref_ptr containers.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
AGXOSG_EXPORT void setDiffuseColor(osg::Node *node, const agx::Vec4f &color)
Set the diffuse part of a material for a node.
AGXOSG_EXPORT void setAlpha(osg::Node *node, float alpha)
Set the alpha part of the material for a node.
AGXOSG_EXPORT void setAmbientColor(osg::Node *node, const agx::Vec4f &color)
Set the ambient part of a material for a node.
AGXOSG_EXPORT void setShininess(osg::Node *node, float shininess)
Set the shininess exponent for the Phong specular model.
TextureMode
Definition: utils.h:90
@ DIFFUSE_TEXTURE
Definition: utils.h:91
AGXOSG_EXPORT bool setTexture(const agxCollide::Geometry *geometry, osg::Group *rootNode, const std::string &imagePath, bool repeat=false, TextureMode mode=DIFFUSE_TEXTURE)
Read an image from disk and apply to the specified geometry as a 2D Texture in OVERRIDE|PROTECTED mod...
AGXOSG_EXPORT void setSpecularColor(osg::Node *node, const agx::Vec4f &color)
Set the specular part of a material for a node.
AGXTERRAIN_EXPORT void clear()
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
Definition: WireUtils.h:392
int64_t Int64
Definition: Integer.h:46
void AGXPHYSICS_EXPORT init()
Initialize agx.