AGXDynamics  2.35.0.2
RenderSingleton.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 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
agxPhysics_export.h
agxRender::RenderSingleton::add
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.
Definition: RenderSingleton.h:272
agxRender::RenderSingleton::Point::Point
Point(const agx::Vec3 &position, agx::Real size=agx::Real(0.4), const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
Definition: RenderSingleton.h:81
agx::end
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Definition: LinearProbingHashSet.h:612
agxRender::RenderSingleton::Triangle::color
agx::Vec4f & color()
Definition: RenderSingleton.h:161
agx::Real
double Real
Definition: Real.h:42
agxRender::RenderSingleton::Triangle::v1
agx::Vec3 & v1()
Definition: RenderSingleton.h:168
agxData::transform
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
agxRender
Namespace containing classes for handling debug rendering of collision geometries,...
Definition: Constraint.h:35
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxRender::debugRenderConstraintFrames
AGXPHYSICS_EXPORT void debugRenderConstraintFrames(const agx::Constraint *constraint, float scale, agxRender::RenderManager *mgr=nullptr, agx::Bool overrideInvalid=false)
agxRender::RenderSingleton::Point::color
agx::Vec4f & color()
Definition: RenderSingleton.h:90
agxRender::RenderSingleton::Frame::Frame
Frame()
Definition: RenderSingleton.h:189
agxRender::RenderManager
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc.
Definition: RenderManager.h:106
agxRender::RenderSingleton::Triangle::v0
agx::Vec3 & v0()
Definition: RenderSingleton.h:165
agxRender::RenderSingleton::Frame::Frame
Frame(const agx::AffineMatrix4x4 &frame, agx::Real scale=agx::Real(0.5), const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
Definition: RenderSingleton.h:190
agxRender::RenderSingleton::Line
Defines a Line to be used in DebugRendering.
Definition: RenderSingleton.h:101
agxRender::RenderSingleton::Text::Text
Text()
Definition: RenderSingleton.h:132
agxRender::debugRenderFrame
AGXPHYSICS_EXPORT void debugRenderFrame(const agx::AffineMatrix4x4 &transform, float scale, const agx::Vec4f &colorIdentifier, agxRender::RenderManager *mgr=nullptr)
agx::AffineMatrix4x4T< Real >
agxRender::RenderSingleton::Frame::getColor
agx::Vec4f getColor() const
Definition: RenderSingleton.h:194
agx::ConstraintImplementation
Definition: ConstraintImplementation.h:100
agxRender::RenderSingleton::Frame::getFrame
const agx::AffineMatrix4x4 & getFrame() const
Definition: RenderSingleton.h:192
agx::Vec4T
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
agxRender::RenderSingleton::Point::Point
Point()
Definition: RenderSingleton.h:80
agxRender::RenderSingleton::Line::size
agx::Real & size()
Definition: RenderSingleton.h:114
agxRender::RenderSingleton::Triangle::v2
agx::Vec3 & v2()
Definition: RenderSingleton.h:171
agxRender::RenderSingleton::Line::color
agx::Vec4f & color()
Definition: RenderSingleton.h:117
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agxRender::RenderSingleton::add
void add(const agx::String &text, const agx::Vec2 &position, const agx::Vec4f &color)
Add temporary text.
Definition: RenderSingleton.h:251
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
Vec4.h
AffineMatrix4x4.h
agxRender::RenderSingleton::Line::Line
Line(const agx::Vec3 &start, const agx::Vec3 &end, agx::Real size=0.02f, const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
Definition: RenderSingleton.h:105
agxRender::RenderSingleton::Point::position
agx::Vec3 & position()
Definition: RenderSingleton.h:84
agxRender::RenderSingleton::Triangle::Triangle
Triangle()
Definition: RenderSingleton.h:157
agxRender::RenderSingleton
Utility class for creating debug rendering objects.
Definition: RenderSingleton.h:54
agxRender::RenderSingleton::Frame::getScale
agx::Real getScale() const
Definition: RenderSingleton.h:193
agx::shutdown
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.
agx::Singleton
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:30
agxRender::RenderSingleton::Line::end
agx::Vec3 & end()
Definition: RenderSingleton.h:111
agxRender::RenderSingleton::add
void add(const agx::Vec3 &start, const agx::Vec3 &end, agx::Real size, const agx::Vec4f &color)
Add temporary line (cylinder)
Definition: RenderSingleton.h:230
m_size
#define m_size
Definition: Vector.h:429
agx::Vec2T
Definition: Vec2Template.h:30
agxRender::RenderSingleton::Point::size
agx::Real & size()
Definition: RenderSingleton.h:87
agxRender::RenderSingleton::addStatic
void addStatic(const agx::Vec3 &position, agx::Real size, const agx::Vec4f &color)
Add static point (sphere).
Definition: RenderSingleton.h:219
agx::Line
LineT< Vec3 > Line
Definition: Line.h:39
agxRender::RenderSingleton::Text
Defines Text to be used in DebugRendering.
Definition: RenderSingleton.h:129
agxRender::RenderSingleton::Text::Text
Text(const agx::String &text, const agx::Vec2 &position, const agx::Vec4f &color=agx::Vec4f(1, 1, 1, 1))
Definition: RenderSingleton.h:133
agxRender::RenderSingleton::add
void add(const agx::Vec3 &position, agx::Real size, const agx::Vec4f &color)
Add temporary point (sphere).
Definition: RenderSingleton.h:209
agx::Bool
bool Bool
Definition: Integer.h:48
Singleton.h
agxBrick::isInitialized
AGXBRICK_EXPORT bool isInitialized()
agxRender::RenderSingleton::Triangle
Defines a Triangle to be used in DebugRendering.
Definition: RenderSingleton.h:154
agx::Constraint
The base class for a constraint.
Definition: Constraint.h:88
agxRender::RenderSingleton::Line::Line
Line()
Definition: RenderSingleton.h:104
agx::AgXString< std::string >
agxRender::RenderSingleton::Triangle::Triangle
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))
Definition: RenderSingleton.h:158
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
Color.h
agxRender::RenderSingleton::Frame
Definition: RenderSingleton.h:186
agx::Vec3T< Real >
agxRender::RenderSingleton::Point
Defines a point to be used in DebugRendering.
Definition: RenderSingleton.h:77
agxRender::RenderSingleton::addStatic
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.
Definition: RenderSingleton.h:282
agxRender::RenderSingleton::Text::position
agx::Vec2 & position()
Definition: RenderSingleton.h:139
agxRender::RenderSingleton::Triangle::size
agx::Real & size()
Definition: RenderSingleton.h:174
agxRender::RenderSingleton::Text::text
agx::String & text()
Definition: RenderSingleton.h:136
agxRender::RenderSingleton::Line::start
agx::Vec3 & start()
Definition: RenderSingleton.h:108
agxRender::RenderSingleton::addStatic
void addStatic(const agx::Vec3 &start, const agx::Vec3 &end, agx::Real size, const agx::Vec4f &color)
Add static line (cylinder)
Definition: RenderSingleton.h:240
agxRender::RenderSingleton::Text::color
agx::Vec4f & color()
Definition: RenderSingleton.h:142
agxRender::RenderSingleton::addStatic
void addStatic(const agx::String &text, const agx::Vec2 &position, const agx::Vec4f &color)
Add static text.
Definition: RenderSingleton.h:261