AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
RenderingWrapper.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
23#include <GL/gl.h>
24
25#include <osgViewer/Viewer>
26#include <osg/Version>
27#include <osgGA/TrackBallManipulator>
28#if defined(OSG_VERSION_GREATER_OR_EQUAL)
29# if OSG_VERSION_GREATER_OR_EQUAL(3,0,0)
30# include <osgViewer/api/Win32/GraphicsWindowWin32>
31# else
32# include <osgViewer/GraphicsWindowWin32>
33# endif
34#else
35# include <osgViewer/GraphicsWindowWin32>
36#endif
37#include <agx/PopDisableWarnings.h> // End of disabled warnings.
38
39#include <agxOSG/export.h>
40#include <agx/Integer.h>
41#include <agxSDK/Simulation.h>
42#include <agxOSG/RenderProxy.h>
43
44#include <memory>
45
46namespace agxOSG
47{
48 struct RenderingWrapperWindowsTypes;
49}
50
51namespace agxOSG
52{
53 class AGXOSG_EXPORT GraphicsNode
54 {
55 public:
56 GraphicsNode(osg::Node* node);
57 ~GraphicsNode();
58
59 osg::Node* getNode() const;
60
65 bool setTexture(const agx::String& imagePath, bool repeat = false, agxOSG::TextureMode textureMode = agxOSG::DIFFUSE_TEXTURE, float scaleX = 1.0f, float scaleY = 1.0f);
66
71 void setSpecularColor(const agx::Vec4f& color);
72
76 void setShininess(float shininess);
77
82 void setAmbientColor(const agx::Vec4f& color);
83
87 void setAlpha(float alpha);
88
93 void setDiffuseColor(const agx::Vec4f& color);
94
95 private:
96 osg::observer_ptr< osg::Node > m_node;
97 };
98
99 class AGXOSG_EXPORT GraphicsWindow
100 {
101 public:
102 enum WindowFunctionDisable
103 {
104 NONE = 0x0,
105 FULLSCREEN = 0x1
106 };
107
108 GraphicsWindow();
109 bool init(agx::Int64 handle, int disabledFunctions = NONE);
110
111 void frame();
112
113 void setActiveSimulation(agxSDK::Simulation *simulation);
114 agxSDK::Simulation *getActiveSimulation() const;
115 void removeSimulation(agxSDK::Simulation *simulation);
116
117 osg::Group* getRoot();
118
119 void fitSceneIntoView();
120
121 agxOSG::GraphicsNode* getVisual(const agx::RigidBody* rb) const;
122 agxOSG::GraphicsNode* getOrCreateVisual(agx::RigidBody* rb);
123 agxOSG::GraphicsNode* getVisual(const agxCollide::Geometry* geometry) const;
124 agxOSG::GraphicsNode* getOrCreateVisual(agxCollide::Geometry* geometry);
125
126 ~GraphicsWindow();
127
128 friend RenderingWrapperWindowsTypes;
129 private:
130 void initCamera(osg::Camera *camera);
131
132 std::unique_ptr<RenderingWrapperWindowsTypes> m_winTypes;
133 osg::ref_ptr<osgViewer::Viewer> m_viewer;
134 agxSDK::Simulation *m_activeSimulation;
135 osg::ref_ptr<osg::Group> m_root;
136 osgGA::StandardManipulator *m_manipulator;
137
138 osg::ref_ptr<osg::GraphicsContext::Traits> m_traits;
139 osg::ref_ptr<osg::GraphicsContext> m_graphicsContext;
140 struct SimulationViewContext {
142 osg::ref_ptr<osg::Camera> camera;
143 };
144
146 SimulationFactoryTable m_factoryTable;
147
148 typedef agx::HashVector< const agx::RigidBody*, GraphicsNode > RigidBodyGraphicsNodeContainer;
149 typedef agx::HashVector< const agxCollide::Geometry*, GraphicsNode > GeometryGraphicsNodeContainer;
150 RigidBodyGraphicsNodeContainer m_rbNodes;
151 GeometryGraphicsNodeContainer m_geometryNodes;
152 };
153}
154
155
156#endif // _MSC_VER
157#endif
158/*
159Copyright 2007-2025. Algoryx Simulation AB.
160
161All AGX source code, intellectual property, documentation, sample code,
162tutorials, scene files and technical white papers, are copyrighted, proprietary
163and confidential material of Algoryx Simulation AB. You may not download, read,
164store, distribute, publish, copy or otherwise disseminate, use or expose this
165material unless having a written signed agreement with Algoryx Simulation AB, or having been
166advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
167valid commercial license from Algoryx Simulation AB.
168
169Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
170from using this software, unless otherwise stated in written agreements with
171Algoryx Simulation AB.
172*/
173
174#ifndef AGXOSG_RENDERINGWRAPPER_H
175#define AGXOSG_RENDERINGWRAPPER_H
176
177#if defined(SWIG) || defined(_MSC_VER)
178#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
179
180#include <GL/gl.h>
181
182#include <osgViewer/Viewer>
183#include <osg/Version>
184#include <osgGA/TrackBallManipulator>
185#if defined(OSG_VERSION_GREATER_OR_EQUAL)
186# if OSG_VERSION_GREATER_OR_EQUAL(3,0,0)
187# include <osgViewer/api/Win32/GraphicsWindowWin32>
188# else
189# include <osgViewer/GraphicsWindowWin32>
190# endif
191#else
192# include <osgViewer/GraphicsWindowWin32>
193#endif
194#include <agx/PopDisableWarnings.h> // End of disabled warnings.
195
196#include <agxOSG/export.h>
197#include <agx/Integer.h>
198#include <agxSDK/Simulation.h>
199#include <agxOSG/RenderProxy.h>
200
201struct RenderingWrapperWindowsTypes;
202
203
204namespace agxOSG
205{
206 class AGXOSG_EXPORT GraphicsNode
207 {
208 public:
209 GraphicsNode( osg::Node* node );
210 ~GraphicsNode();
211
212 osg::Node* getNode() const;
213
218 bool setTexture( const agx::String& imagePath, bool repeat=false, agxOSG::TextureMode textureMode = agxOSG::DIFFUSE_TEXTURE, float scaleX = 1.0f, float scaleY = 1.0f );
219
224 void setSpecularColor( const agx::Vec4f& color );
225
229 void setShininess( float shininess );
230
235 void setAmbientColor( const agx::Vec4f& color );
236
240 void setAlpha( float alpha );
241
246 void setDiffuseColor( const agx::Vec4f& color );
247
248 private:
249 osg::observer_ptr< osg::Node > m_node;
250 };
251
252 class AGXOSG_EXPORT GraphicsWindow
253 {
254 public:
255 enum WindowFunctionDisable
256 {
257 NONE = 0x0,
258 FULLSCREEN = 0x1
259 };
260
261 GraphicsWindow( );
262 bool init( agx::Int64 handle, int disabledFunctions = NONE );
263
264 bool initEmbeddedQT(int x, int y, int width, int height, float scale = 1.0f);
265 void resize(int x, int y, int width, int height);
266 osgGA::EventQueue* getEventQueue() const;
267
268 void mouseMoveEvent(int x, int y);
269
270 void mousePressEvent(int x, int y, int button);
271
272 void mouseReleaseEvent(int x, int y, int button);
273
274 void keyPressEvent(int key, int mod_key);
275 void keyReleaseEvent(int key, int mod_key);
276
277 void wheelEvent(int motion);
278
279 void frame();
280
281 void setActiveSimulation( agxSDK::Simulation *simulation );
282 agxSDK::Simulation *getActiveSimulation() const;
283 void removeSimulation( agxSDK::Simulation *simulation );
284
285 osg::Group* getRoot();
286 agxOSG::SceneDecorator* getSceneDecorator();
287
288 void fitSceneIntoView();
289
290 agxOSG::GraphicsNode* getVisual( const agx::RigidBody* rb ) const;
291 agxOSG::GraphicsNode* getOrCreateVisual( agx::RigidBody* rb );
292 agxOSG::GraphicsNode* getVisual( const agxCollide::Geometry* geometry ) const;
293 agxOSG::GraphicsNode* getOrCreateVisual( agxCollide::Geometry* geometry );
294
295 ~GraphicsWindow();
296
297 void clear();
298
299 private:
300 void initCamera( osg::Camera *camera );
301
302 std::unique_ptr<RenderingWrapperWindowsTypes> m_winTypes;
303 osg::ref_ptr<osgViewer::Viewer> m_viewer;
304 agxSDK::Simulation *m_activeSimulation;
305 osg::ref_ptr<osg::Group> m_root;
306 osg::ref_ptr<agxOSG::SceneDecorator> m_decorator;
307 osgGA::StandardManipulator *m_manipulator;
308
309 osg::ref_ptr<osg::GraphicsContext::Traits> m_traits;
310 osg::ref_ptr<osg::GraphicsContext> m_graphicsContext;
311 struct SimulationViewContext {
313 osg::ref_ptr<osg::Camera> camera;
314 };
315
317 SimulationFactoryTable m_factoryTable;
318
319 typedef agx::HashVector< const agx::RigidBody*, GraphicsNode > RigidBodyGraphicsNodeContainer;
320 typedef agx::HashVector< const agxCollide::Geometry*, GraphicsNode > GeometryGraphicsNodeContainer;
321 RigidBodyGraphicsNodeContainer m_rbNodes;
322 GeometryGraphicsNodeContainer m_geometryNodes;
323 osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_embeddedWindow;
324 float m_scale;
325 };
326}
327
328
329#endif // _MSC_VER
330#endif
#define AGXOSG_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
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:131
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:49
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 setAlpha(osg::Node *node, float alpha, bool override=false)
Set the alpha part of the material for a node.
AGXOSG_EXPORT void setAmbientColor(osg::Node *node, const agx::Vec4f &color, bool override=false)
Set the ambient part of a material for a node.
AGXOSG_EXPORT void setShininess(osg::Node *node, float shininess, bool override=false)
Set the shininess exponent for the Phong specular model.
TextureMode
Definition: utils.h:101
@ DIFFUSE_TEXTURE
Definition: utils.h:102
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, bool override=false)
Set the specular part of a material for a node.
AGXOSG_EXPORT void setDiffuseColor(osg::Node *node, const agx::Vec4f &color, bool override=false)
Set the diffuse 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:38
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.