AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
ForceArrowRenderer.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#pragma once
18#include <agxOSG/export.h>
20#include <agx/HashVector.h>
21#include <agx/Constraint.h>
22#include <agxUtil/Statistic.h>
23#include <agxRender/Color.h>
24
25namespace agxOSG
26{
39 {
40 public:
41
46 {
47 MOTOR1D = 0x1,
48 RANGE1D = 0x2,
49 LOCK1D = 0x4,
50 ALL = MOTOR1D | RANGE1D | LOCK1D,
51 DEFAULT = MOTOR1D
52 };
53
56
64 bool add(agx::RigidBody* body, const agx::Vec3& localOffsetRelBody, const agxRender::Color& color = agxRender::Color::Red());
65
72
73
74 /*
75 Add a 1DOF constraint. The sum of the motor forces are visualized with one arrow.
76 \param constraint - The constraint that should be added.
77 \param localOffsetRelBody1 - the start point of the arrow relative the first rigid body of the first constraint.
78 \param color - Color of the arrow.
79 \param statisticsMask - Selects which forces that should be part of the calculation of the length of the force vector.
80 \return true if constraint is successfully added.
81 */
82 bool add(agx::Constraint1DOF* constraint, const agx::Vec3& localOffsetRelBody1, const agxRender::Color& color = agxRender::Color::Red(), ConstraintForceStatistics statisticsMask = DEFAULT);
83
89
97
105
110 void setSmoothFactor(agx::Real smoothFactor);
111
116
122
125
131
136
141 void setScale(agx::Real scale);
142
147
148
149 protected:
150 virtual void update(float x, float y);
152
153 void drawArrow(const agx::Vec3& start, const agx::Vec3& force, const agxRender::Color& color);
154
160
161#ifndef SWIG
166 {
167 NORMAL_X = 0,
173 NUM_FORCES
174 };
175
176 template<typename T>
177 struct Statistic : public agx::Referenced, public T
178 {
179 using T::T;
180 };
181
183
185 public:
189 const agx::Vec3& r,
190 const agxRender::Color& col,
191 ConstraintForceStatistics mask) : constraint(c),
192 statistic(s),
193 relative(r),
194 statisticsMask(mask),
195 color(col) {}
196
197
203 };
204
205 class BodyData : public agx::Referenced {
206 public:
208 agx::Real smoothFactor,
209 const agx::Vec3& r,
210 const agxRender::Color& c) : body(b), relative(r), color(c)
211 {
212 for (int i = 0; i < NUM_FORCES; i++)
213 statistics.push_back(new RendererStatistic(smoothFactor));
214 }
215
220 };
221
224
227#endif
228 };
229
230}
#define AGXOSG_EXPORT
agx::Vector< agx::ref_ptr< RendererStatistic > > statistics
BodyData(agx::RigidBody *b, agx::Real smoothFactor, const agx::Vec3 &r, const agxRender::Color &c)
agx::ref_ptr< RendererStatistic > statistic
ConstraintData(agx::Constraint1DOF *c, RendererStatistic *s, const agx::Vec3 &r, const agxRender::Color &col, ConstraintForceStatistics mask)
Creates an arrow visualizing force, either contact force (for added bodies), or motor force for added...
void drawArrow(const agx::Vec3 &start, const agx::Vec3 &force, const agxRender::Color &color)
virtual void update(float x, float y)
Called once per simulation frame.
agx::Bool setColor(agx::Constraint1DOF *constraint, const agxRender::Color &color)
Set the color of the force vector for the specified constraint.
agx::Real getSmoothFactor() const
bool add(agx::RigidBody *body, const agx::Vec3 &localOffsetRelBody, const agxRender::Color &color=agxRender::Color::Red())
Add body for contact force visualization, normal and friction force are visualized with one arrow eac...
agx::HashVector< agx::Constraint1DOF *, agx::ref_ptr< ConstraintData > > ConstraintHashVector
agx::Bool remove(agx::Constraint1DOF *constraint)
Remove a constraint from the constraint force arrow visualization.
ConstraintHashVector m_constraints
ForceArrowRenderer()
Constructor.
agx::Real getConeHeight() const
bool add(agx::Constraint1DOF *constraint, const agx::Vec3 &localOffsetRelBody1, const agxRender::Color &color=agxRender::Color::Red(), ConstraintForceStatistics statisticsMask=DEFAULT)
void setArrowRadius(agx::Real radius)
Set the unit radius of the arrow.
RigidBodyHashVector m_bodies
agx::Bool setColor(agx::RigidBody *body, const agxRender::Color &color)
Set the color of the force vector for the specified body.
agx::HashVector< agx::RigidBody *, agx::ref_ptr< BodyData > > RigidBodyHashVector
void setSmoothFactor(agx::Real smoothFactor)
A smooth factor for a filter, smoothing the force arrow size.
ConstraintForceStatistics
Specifies which secondary constraints that should be included in the statistics.
void setScale(agx::Real scale)
Scale the size of the arrow (scale 1 would result in 1 Newton giving length of 1 l....
ContactForceStatistics
Contact force directions.
Statistic< agxUtil::ExponentialMovingAverageStatistic > RendererStatistic
agx::Bool remove(agx::RigidBody *body)
Remove a body from the contact force arrow visualization.
agx::Real getScale() const
void setConeHeight(agx::Real height)
Set the unit height of the cone part of the arrow.
agx::Real getArrowRadius() const
Utility color class with "common colors".
Definition: Color.h:48
static agxRender::Color Red()
Definition: Color.h:217
Derive from this class to implement a listener for simulation GuiEvents.
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:710
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
Templated vector class.
Definition: agx/Vector.h:53
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
bool Bool
Definition: Integer.h:40
double Real
Definition: Real.h:41