AGX Dynamics  2.37.2.0
RenderSingleton.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 AGXRENDER_RENDERERSINGLETON_H
18 #define AGXRENDER_RENDERERSINGLETON_H
19 
20 #ifdef _MSC_VER
21 # pragma warning(push)
22 # pragma warning( disable : 4251 )
23 // warning C4251: 'X' : class 'Y' needs to have dll-interface to be used by clients of class 'Z'
24 #endif
25 
26 #include <agx/agxPhysics_export.h>
27 #include <agx/Singleton.h>
28 #include <agx/Vec4.h>
29 #include <agx/AffineMatrix4x4.h>
30 
31 #include <agxRender/Color.h>
32 
33 // Forward declarations
34 namespace agx
35 {
36  class Constraint;
37  class ConstraintImplementation;
38 }
39 
40 namespace agxSDK
41 {
42  class Simulation;
43 }
44 
45 namespace agxRender
46 {
47  class RenderManager;
48 
49  AGXPHYSICS_EXPORT void debugRenderFrame( const agx::AffineMatrix4x4& transform, float scale, const agx::Vec4f& colorIdentifier, agxRender::RenderManager* mgr = nullptr );
50  AGXPHYSICS_EXPORT void debugRenderConstraintFrames( const agx::Constraint* constraint, float scale, agxRender::RenderManager* mgr = nullptr, agx::Bool overrideInvalid = false );
51  AGXPHYSICS_EXPORT void debugRenderConstraintFrames( const agx::ConstraintImplementation* constraint, float scale, agxRender::RenderManager* mgr = nullptr, agx::Bool overrideInvalid = false );
52 
55  {
56  public:
57 
59  static RenderSingleton* instance();
60 
62  static bool isInitialized();
63 
65  void clearTemporaries();
66 
68  void clearStatics();
69 
71  void clearAll();
72 
74  void render( agxRender::RenderManager* mgr );
75 
78  {
79  public:
80  Point() {}
81  Point( const agx::Vec3& position, agx::Real size = agx::Real(0.4), const agx::Vec4f& color = agx::Vec4f( 1, 1, 1, 1 ) )
82  : m_position( position ), m_size( size ), m_color( color ) {}
83 
85  return m_position;
86  }
88  return m_size;
89  }
91  return m_color;
92  }
93 
94  private:
95  agx::Vec3 m_position;
97  agx::Vec4f m_color;
98  };
99 
102  {
103  public:
104  Line() {}
105  Line( const agx::Vec3& start, const agx::Vec3& end, agx::Real size = 0.02f, const agx::Vec4f& color = agx::Vec4f( 1, 1, 1, 1 ) )
106  : m_start( start ), m_end( end ), m_size( size ), m_color( color ) {}
107 
109  return m_start;
110  }
112  return m_end;
113  }
115  return m_size;
116  }
118  return m_color;
119  }
120 
121  private:
122  agx::Vec3 m_start;
123  agx::Vec3 m_end;
125  agx::Vec4f m_color;
126  };
127 
130  {
131  public:
132  Text() {}
133  Text( const agx::String& text, const agx::Vec2& position, const agx::Vec4f& color = agx::Vec4f( 1, 1, 1, 1 ) )
134  : m_text( text ), m_position( position ), m_color( color ) {}
135 
137  return m_text;
138  }
140  return m_position;
141  }
143  return m_color;
144  }
145 
146  private:
147  agx::String m_text;
148  agx::Vec2 m_position;
149  agx::Vec4f m_color;
150  };
151 
152 
155  {
156  public:
157  Triangle() {}
158  Triangle( const agx::Vec3& v0, const agx::Vec3& v1, const agx::Vec3& v2, agx::Real size = 0.02f, const agx::Vec4f& color = agx::Vec4f( 1, 1, 1, 1 ) )
159  : m_v0( v0 ), m_v1( v1 ), m_v2( v2 ), m_size(size), m_color( color ) {}
160 
162  return m_color;
163  }
164 
166  return m_v0;
167  }
169  return m_v1;
170  }
172  return m_v2;
173  }
175  return m_size;
176  }
177 
178  private:
179  agx::Vec3 m_v0;
180  agx::Vec3 m_v1;
181  agx::Vec3 m_v2;
183  agx::Vec4f m_color;
184  };
185 
187  {
188  public:
189  Frame() {}
190  Frame( const agx::AffineMatrix4x4& frame, agx::Real scale = agx::Real( 0.5 ), const agx::Vec4f& color = agx::Vec4f( 1, 1, 1, 1 ) ) : m_frame( frame ), m_scale( scale ), m_color( color ) {}
191 
192  const agx::AffineMatrix4x4& getFrame() const { return m_frame; }
193  agx::Real getScale() const { return m_scale; }
194  agx::Vec4f getColor() const { return m_color; }
195 
196  private:
197  agx::AffineMatrix4x4 m_frame;
198  agx::Real m_scale;
199  agx::Vec4f m_color;
200  };
201 
205  void add( const Point& point );
209  void add( const agx::Vec3& position, agx::Real size, const agx::Vec4f& color ) {
210  add( Point( position, size, color ) );
211  }
215  void addStatic( const Point& point );
219  void addStatic( const agx::Vec3& position, agx::Real size, const agx::Vec4f& color ) {
220  addStatic( Point( position, size, color ) );
221  }
222 
226  void add( const Line& line );
230  void add( const agx::Vec3& start, const agx::Vec3& end, agx::Real size, const agx::Vec4f& color ) {
231  add( Line( start, end, size, color ) );
232  }
236  void addStatic( const Line& line );
240  void addStatic( const agx::Vec3& start, const agx::Vec3& end, agx::Real size, const agx::Vec4f& color ) {
241  addStatic( Line( start, end, size, color ) );
242  }
243 
247  void add( const Text& text );
251  void add( const agx::String& text, const agx::Vec2& position, const agx::Vec4f& color ) {
252  add( Text( text, position, color ) );
253  }
257  void addStatic( const Text& text );
261  void addStatic( const agx::String& text, const agx::Vec2& position, const agx::Vec4f& color ) {
262  addStatic( Text( text, position, color ) );
263  }
264 
268  void add(const Triangle& triangle);
272  void add(const agx::Vec3& v0, const agx::Vec3& v1, const agx::Vec3& v2, const agx::Real size, const agx::Vec4f& color) {
273  add(Triangle(v0, v1, v2, size, color));
274  }
278  void addStatic( const Triangle& triangle);
282  void addStatic(const agx::Vec3& v0, const agx::Vec3& v1, const agx::Vec3& v2, const agx::Real size, const agx::Vec4f& color) {
283  addStatic(Triangle(v0, v1, v2, size, color));
284  }
285 
289  void add( const agx::AffineMatrix4x4& frame, agx::Real scale, const agx::Vec4f& color );
290 
294  void addStatic( const agx::AffineMatrix4x4& frame, agx::Real scale, const agx::Vec4f& color );
295 
296  SINGLETON_CLASSNAME_METHOD();
297 
298  protected:
299  RenderSingleton();
300  virtual void shutdown() override;
301 
302  private:
303  static RenderSingleton* s_instance;
304  agx::Vector< Point > m_staticPoints;
305  agx::Vector< Point > m_points;
306  agx::Vector< Line > m_staticLines;
307  agx::Vector< Line > m_lines;
308  agx::Vector< Text > m_staticText;
309  agx::Vector< Text > m_text;
310  agx::Vector< Triangle > m_staticTriangles;
311  agx::Vector< Triangle > m_triangles;
312  agx::Vector< Frame > m_staticFrames;
313  agx::Vector< Frame > m_frames;
314  };
315 }
316 
317 #ifdef _MSC_VER
318 # pragma warning(pop)
319 #endif
320 
321 #endif
Defines a Line to be used in DebugRendering.
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
void add(const agx::Vec3 &position, agx::Real size, const agx::Vec4f &color)
Add temporary point (sphere).
Point(const agx::Vec3 &position, agx::Real size=agx::Real(0.4), const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
bool Bool
Definition: Integer.h:48
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
void addStatic(const agx::Vec3 &v0, const agx::Vec3 &v1, const agx::Vec3 &v2, const agx::Real size, const agx::Vec4f &color)
Add static triangle.
#define m_size
Definition: Vector.h:429
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
void addStatic(const agx::Vec3 &position, agx::Real size, const agx::Vec4f &color)
Add static point (sphere).
#define AGXPHYSICS_EXPORT
The base class for a constraint.
Definition: Constraint.h:88
Namespace containing classes for handling debug rendering of collision geometries, constraints, contacts and rigid bodies.
Definition: Constraint.h:35
Frame(const agx::AffineMatrix4x4 &frame, agx::Real scale=agx::Real(0.5), const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc...
Defines Text to be used in DebugRendering.
Text(const agx::String &text, const agx::Vec2 &position, const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
AGXPHYSICS_EXPORT void debugRenderConstraintFrames(const agx::ConstraintImplementation *constraint, float scale, agxRender::RenderManager *mgr=nullptr, agx::Bool overrideInvalid=false)
Line(const agx::Vec3 &start, const agx::Vec3 &end, agx::Real size=0.02f, const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Triangle(const agx::Vec3 &v0, const agx::Vec3 &v1, const agx::Vec3 &v2, agx::Real size=0.02f, const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
AGXPHYSICS_EXPORT void debugRenderFrame(const agx::AffineMatrix4x4 &transform, float scale, const agx::Vec4f &colorIdentifier, agxRender::RenderManager *mgr=nullptr)
void addStatic(const agx::Vec3 &start, const agx::Vec3 &end, agx::Real size, const agx::Vec4f &color)
Add static line (cylinder)
void addStatic(const agx::String &text, const agx::Vec2 &position, const agx::Vec4f &color)
Add static text.
void add(const agx::Vec3 &v0, const agx::Vec3 &v1, const agx::Vec3 &v2, const agx::Real size, const agx::Vec4f &color)
Add temporary triangle.
const agx::AffineMatrix4x4 & getFrame() const
Defines a Triangle to be used in DebugRendering.
AGXBRICK_EXPORT bool isInitialized()
void add(const agx::String &text, const agx::Vec2 &position, const agx::Vec4f &color)
Add temporary text.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
double Real
Definition: Real.h:42
Utility class for creating debug rendering objects.
LineT< Vec3 > Line
Definition: Line.h:39
Defines a point to be used in DebugRendering.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:30
void add(const agx::Vec3 &start, const agx::Vec3 &end, agx::Real size, const agx::Vec4f &color)
Add temporary line (cylinder)