AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LocalContactPoint.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 #pragma once
18 
19 #include <agxCollide/Geometry.h>
20 
21 #include <agx/Vec3.h>
22 #include <agx/Vector.h>
23 
25 
26 #ifdef _MSC_VER
27 # pragma warning(push)
28 # pragma warning(disable: 6385) // Disable warning C6385: Reading invalid data
29 # pragma warning(disable: 6386) // Disable warning C6386: Buffer overrun while writing
30 #endif
31 
32 namespace agx
33 {
34  class RigidBody;
35  class ContactMaterial;
36 }
37 
38 namespace agxCollide
39 {
41  {
42  public:
44  {
45  IMPACTING = 1 << 0,
51  NONHOLONOMIC = 1 << 1
57  };
58 
63  template<typename T>
64  static LocalContactPoint create( const T& pointType );
65 
66  public:
68  : m_point()
69  , m_normal()
70  , m_velocity()
71  , m_depth(0)
72  , m_maxNormalForce(agx::Infinity)
73  , m_area(1)
74  , m_elasticRestLengthShape1(1)
75  , m_elasticRestLengthShape2(1)
76  , m_shape1()
77  , m_shape2()
78  , m_material(nullptr)
79  , m_faceIndex1(0)
80  , m_faceIndex2(0)
81  , m_faceFeature1(0)
82  , m_faceFeature2(0)
83  , m_enabled(true)
84  , m_state( 0 )
85  , m_padding( 0 )
86  {
87  m_padding = 0; // remove unused variable warning
88  }
89 
91  : m_point(p)
92  , m_normal(n)
93  , m_velocity()
94  , m_depth(d)
95  , m_maxNormalForce(agx::Infinity)
96  , m_area(1)
97  , m_elasticRestLengthShape1(1)
98  , m_elasticRestLengthShape2(1)
99  , m_shape1()
100  , m_shape2()
101  , m_material(nullptr)
102  , m_faceIndex1(0)
103  , m_faceIndex2(0)
104  , m_faceFeature1(0)
105  , m_faceFeature2(0)
106  , m_enabled(true)
107  , m_state( 0 )
108  , m_padding( 0 )
109  {
110  m_padding = 0; // remove unused variable warning
111  }
112 
114  : LocalContactPoint( p, (agx::Vec3f)n, d )
115  {
116  }
117 
118  AGX_FORCE_INLINE agx::Vec3& point() { return m_point; }
119  AGX_FORCE_INLINE agx::Vec3f& normal() { return m_normal; }
120  AGX_FORCE_INLINE agx::Vec3f& velocity() { return m_velocity; }
121  AGX_FORCE_INLINE agx::Real& depth() { return m_depth; }
122  AGX_FORCE_INLINE agx::Real& maxNormalForce() { return m_maxNormalForce; }
123  AGX_FORCE_INLINE agx::Real& area() { return m_area; }
124  AGX_FORCE_INLINE agx::Real& elasticRestLengthShape1() { return m_elasticRestLengthShape1; }
125  AGX_FORCE_INLINE agx::Real& elasticRestLengthShape2() { return m_elasticRestLengthShape2; }
126  AGX_FORCE_INLINE agx::UInt32& faceIndex1() { return m_faceIndex1; }
127  AGX_FORCE_INLINE agx::UInt32& faceIndex2() { return m_faceIndex2; }
128  AGX_FORCE_INLINE agx::UInt8& faceFeature1() { return m_faceFeature1; }
129  AGX_FORCE_INLINE agx::UInt8& faceFeature2() { return m_faceFeature2; }
132  AGX_FORCE_INLINE bool& enabled() { return m_enabled; }
133  AGX_FORCE_INLINE const agx::ContactMaterial*& material() { return m_material; }
134  AGX_FORCE_INLINE agx::UInt8& state() { return m_state; }
136  {
137  if ( isHolonomic )
138  {
139  m_state = ( agx::UInt8 )( m_state & ~NONHOLONOMIC );
140  }
141  else
142  {
143  m_state |= ( agx::UInt8 ) NONHOLONOMIC;
144  }
145  }
146 
147  AGX_FORCE_INLINE const agx::Vec3& point() const { return m_point; }
148  AGX_FORCE_INLINE const agx::Vec3f& normal() const { return m_normal; }
149  AGX_FORCE_INLINE const agx::Vec3f& velocity() const { return m_velocity; }
150  AGX_FORCE_INLINE const agx::Real& depth() const { return m_depth; }
151  AGX_FORCE_INLINE const agx::Real& maxNormalForce() const { return m_maxNormalForce; }
152  AGX_FORCE_INLINE const agx::Real& area() const { return m_area; }
153  AGX_FORCE_INLINE const agx::Real& elasticRestLengthShape1() const { return m_elasticRestLengthShape1; }
154  AGX_FORCE_INLINE const agx::Real& elasticRestLengthShape2() const { return m_elasticRestLengthShape2; }
155  AGX_FORCE_INLINE const agx::UInt32& faceIndex1() const { return m_faceIndex1; }
156  AGX_FORCE_INLINE const agx::UInt32& faceIndex2() const { return m_faceIndex2; }
157  AGX_FORCE_INLINE const agx::UInt8& faceFeature1() const { return m_faceFeature1; }
158  AGX_FORCE_INLINE const agx::UInt8& faceFeature2() const { return m_faceFeature2; }
159  AGX_FORCE_INLINE const agx::Physics::Geometry::ShapePtr& shape1() const {return m_shape1;}
160  AGX_FORCE_INLINE const agx::Physics::Geometry::ShapePtr& shape2() const {return m_shape2;}
161  AGX_FORCE_INLINE const bool& enabled() const { return m_enabled; }
162  AGX_FORCE_INLINE const agx::ContactMaterial* const & material() const { return m_material; }
163  AGX_FORCE_INLINE const agx::UInt8& state() const { return m_state; }
164  AGX_FORCE_INLINE const bool isHolonomic() const { return ( m_state & NONHOLONOMIC ) == 0; }
165 
166  private:
167  agx::Vec3 m_point;
168  agx::Vec3f m_normal;
169  agx::Vec3f m_velocity;
170  agx::Real m_depth;
171  agx::Real m_maxNormalForce;
172  agx::Real m_area;
173  agx::Real m_elasticRestLengthShape1;
174  agx::Real m_elasticRestLengthShape2;
177  const agx::ContactMaterial* m_material;
178  agx::UInt32 m_faceIndex1;
179  agx::UInt32 m_faceIndex2;
180  agx::UInt8 m_faceFeature1;
181  agx::UInt8 m_faceFeature2;
182  bool m_enabled;
183  agx::UInt8 m_state;
184  agx::UInt8 m_padding;
185  };
186 
187  template<typename T>
189  {
190  LocalContactPoint local( pointType.point(), pointType.normal(), pointType.depth() );
191  local.m_maxNormalForce = pointType.maxNormalForce();
192  local.m_velocity = pointType.velocity();
193  local.m_area = pointType.area();
194  local.m_elasticRestLengthShape1 = pointType.elasticRestLengthShape1();
195  local.m_elasticRestLengthShape2 = pointType.elasticRestLengthShape2();
196  local.m_shape1 = pointType.shape1();
197  local.m_shape2 = pointType.shape2();
198  local.m_faceIndex1 = pointType.faceIndex1();
199  local.m_faceIndex2 = pointType.faceIndex2();
200  local.m_faceFeature1 = pointType.faceFeature1();
201  local.m_faceFeature2 = pointType.faceFeature2();
202  local.m_state = pointType.state();
203  return local;
204  }
205 
207 
209  {
210  public:
212 
213  public:
215  m_geometries[0] = nullptr;
216  m_geometries[1] = nullptr;
217  m_bodies[0] = nullptr;
218  m_bodies[1] = nullptr;
219  m_contactMaterial = nullptr;
220  m_hasInternalMaterial = false;
221  m_hasSurfaceVelocity = false;
222  }
223 
225  m_geometries[0] = g1;
226  m_geometries[1] = g2;
227  if (m_geometries[0])
228  m_bodies[0] = m_geometries[0]->getRigidBody();
229  if (m_geometries[1])
230  m_bodies[1] = m_geometries[1]->getRigidBody();
231  m_contactMaterial = nullptr;
232  m_hasInternalMaterial = false;
233  m_hasSurfaceVelocity = false;
234  }
235 
237  m_geometries[0] = g1;
238  m_geometries[1] = g2;
239  m_bodies[0] = b1;
240  m_bodies[1] = b2;
241  m_contactMaterial = nullptr;
242  m_hasInternalMaterial = false;
243  m_hasSurfaceVelocity = false;
244  }
245 
247  m_geometries[0] = g1;
248  m_geometries[1] = g2;
249  if (m_geometries[0])
250  m_bodies[0] = m_geometries[0]->getRigidBody();
251  if (m_geometries[1])
252  m_bodies[1] = m_geometries[1]->getRigidBody();
253  m_points.clear();
254  }
255 
257  m_geometries[0] = g1;
258  m_geometries[1] = g2;
259  m_bodies[0] = b1;
260  m_bodies[1] = b2;
261  m_points.clear();
262  }
263 
264  AGX_FORCE_INLINE void setGeometry( size_t ith, Geometry *geom ) { agxAssert(ith <2 ); m_geometries[ith] = geom; }
265  AGX_FORCE_INLINE void setRigidBody( size_t ith, agx::RigidBody* body ) { agxAssert(ith <2 ); m_bodies[ith] = body; }
268  AGX_FORCE_INLINE void setHasSurfaceVelocity(const agx::Bool hasSurfaceVelocity) { m_hasSurfaceVelocity = hasSurfaceVelocity; }
269 
270  AGX_FORCE_INLINE void addPoint(const LocalContactPoint& point) { m_points.push_back(point); }
272  AGX_FORCE_INLINE const LocalContactPointVector& points() const { return m_points; }
273 
274  AGX_FORCE_INLINE agxCollide::Geometry* geometry( size_t ith ) { agxAssert(ith <2 ); return m_geometries[ith]; }
275  AGX_FORCE_INLINE const agxCollide::Geometry* geometry( size_t ith ) const { agxAssert(ith <2 ); return m_geometries[ith]; }
276 
277  AGX_FORCE_INLINE agx::RigidBody* rigidBody( size_t ith ) { agxAssert(ith <2 ); return m_bodies[ith]; }
278  AGX_FORCE_INLINE const agx::RigidBody* rigidBody( size_t ith ) const { agxAssert(ith <2 ); return m_bodies[ith]; }
279 
280  AGX_FORCE_INLINE agx::ContactMaterial *material() { return m_contactMaterial; }
281  AGX_FORCE_INLINE const agx::ContactMaterial *material() const { return m_contactMaterial; }
282 
283  AGX_FORCE_INLINE agx::Bool& hasInternalMaterial() { return m_hasInternalMaterial; }
284  AGX_FORCE_INLINE const agx::Bool& hasInternalMaterial() const { return m_hasInternalMaterial; }
285 
286  AGX_FORCE_INLINE agx::Bool& getHasSurfaceVelocity() { return m_hasSurfaceVelocity; }
287  AGX_FORCE_INLINE const agx::Bool& getHasSurfaceVelocity() const { return m_hasSurfaceVelocity; }
288 
289 
290  private:
291  Geometry* m_geometries[2];
292  agx::RigidBody* m_bodies[2];
293  LocalContactPointVector m_points;
294  agx::ContactMaterial* m_contactMaterial;
295  agx::Bool m_hasInternalMaterial;
296  agx::Bool m_hasSurfaceVelocity;
297  };
298 
300 
302  {
303  public:
305  {
306  }
307 
309  {
310  }
311 
312  AGX_FORCE_INLINE const agx::Physics::GeometryPtr& geometry() const { return m_geometry; }
314 
315  AGX_FORCE_INLINE const agx::Physics::ParticlePtr& particle() const { return m_particle; }
317 
318  private:
319  agx::Physics::ParticlePtr m_particle;
320  agx::Physics::GeometryPtr m_geometry;
321  };
322 
324 
326  {
327  public:
329  {
330  }
331 
333  {
334  }
335 
336  AGX_FORCE_INLINE const agx::Physics::ParticlePtr& particle1() const { return m_particle1; }
338 
339 
340  AGX_FORCE_INLINE const agx::Physics::ParticlePtr& particle2() const { return m_particle2; }
342 
343  private:
344  agx::Physics::ParticlePtr m_particle1;
345  agx::Physics::ParticlePtr m_particle2;
346  };
347 
349 }
350 
351 #ifdef _MSC_VER
352 # pragma warning(pop)
353 #endif
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:503
const LocalContactPointVector & points() const
void push_back(const T &value)
Definition: Vector.h:1362
LocalGeometryContact(Geometry *g1, Geometry *g2, agx::RigidBody *b1, agx::RigidBody *b2)
This contact point is impacting - i.e., relative speed along the normal is above some threshold...
LocalContactPointVector & points()
const bool & enabled() const
const agx::Vec3f & velocity() const
bool Bool
Definition: Integer.h:48
LocalParticlePairContact(agx::Physics::ParticlePtr p1, agx::Physics::ParticlePtr p2)
agx::Physics::ParticlePtr & particle2()
LocalContactPoint(const agx::Vec3 &p, const agx::Vec3f &n, agx::Real d)
const agx::UInt8 & faceFeature2() const
const agx::RigidBody * rigidBody(size_t ith) const
const agx::Physics::ParticlePtr & particle2() const
const agx::Real & maxNormalForce() const
const agx::ContactMaterial *const & material() const
const agx::Physics::Geometry::ShapePtr & shape1() const
void setGeometry(size_t ith, Geometry *geom)
uint8_t UInt8
Definition: Integer.h:38
const agx::Physics::Geometry::ShapePtr & shape2() const
This contact point is treated as a non-holonomic constraint in the normal direction - i...
agxCollide::Geometry * geometry(size_t ith)
Pointer to a entity instance of type Physics.Geometry.Shape.
Definition: ShapeEntity.h:195
const agx::Real & elasticRestLengthShape2() const
const agx::Physics::GeometryPtr & geometry() const
void setRigidBody(size_t ith, agx::RigidBody *body)
agx::Physics::ParticlePtr & particle1()
const agx::Real & elasticRestLengthShape1() const
const agx::UInt8 & faceFeature1() const
#define AGX_FORCE_INLINE
Definition: Object.h:62
agx::Vector< LocalParticleGeometryContact > LocalParticleGeometryContactVector
void setContactMaterial(agx::ContactMaterial *material)
const agx::UInt32 & faceIndex1() const
const agx::ContactMaterial * material() const
agx::Physics::Geometry::ShapePtr & shape1()
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
const agx::Physics::ParticlePtr & particle1() const
agx::Vector< LocalParticlePairContact > LocalParticlePairContactVector
agx::RigidBody * rigidBody(size_t ith)
LocalParticleGeometryContact(agx::Physics::ParticlePtr particle, agx::Physics::GeometryPtr geometry)
agx::Vector< LocalGeometryContact > LocalGeometryContactVector
const agx::Bool & getHasSurfaceVelocity() const
Pointer to a entity instance of type Physics.Geometry.
void init(Geometry *g1, Geometry *g2)
const agx::Physics::ParticlePtr & particle() const
const agxCollide::Geometry * geometry(size_t ith) const
void setHasSurfaceVelocity(const agx::Bool hasSurfaceVelocity)
const agx::Bool & hasInternalMaterial() const
LocalGeometryContact(Geometry *g1, Geometry *g2)
AGXCORE_EXPORT const Real Infinity
Vec3T< Real32 > Vec3f
Definition: Vec3.h:39
#define agxAssert(expr)
Definition: debug.h:143
agx::Physics::GeometryPtr & geometry()
void setIsHolonomic(bool isHolonomic)
const agx::Real & depth() const
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
void addPoint(const LocalContactPoint &point)
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
Definition: Vector.h:1149
const agx::Vec3 & point() const
void setHasInternalMaterial(const agx::Bool hasInternalMaterial)
const agx::UInt32 & faceIndex2() const
const agx::Vec3f & normal() const
const agx::Real & area() const
const agx::ContactMaterial *& material()
LocalContactPoint(const agx::Vec3 &p, const agx::Vec3 &n, agx::Real d)
double Real
Definition: Real.h:42
agx::Physics::Geometry::ShapePtr & shape2()
const agx::UInt8 & state() const
agx::ContactMaterial * material()
Pointer to a entity instance of type Physics.Particle.
void init(Geometry *g1, Geometry *g2, agx::RigidBody *b1, agx::RigidBody *b2)
agx::Physics::ParticlePtr & particle()
uint32_t UInt32
Definition: Integer.h:40
agx::VectorPOD< LocalContactPoint > LocalContactPointVector
agx::RigidBody * getRigidBody()
Definition: Geometry.h:832
static LocalContactPoint create(const T &pointType)
Creates an enabled copy of given pointType (agxCollide::ContactPoint).