AGX Dynamics 2.41.2.0
Loading...
Searching...
No Matches
LocalContactPoint.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
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
32namespace agx
33{
34 class RigidBody;
35 class ContactMaterial;
36}
37
38namespace 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#ifndef SWIG
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; }
135#endif
137 {
138 if ( isHolonomic )
139 {
140 m_state = ( agx::UInt8 )( m_state & ~NONHOLONOMIC );
141 }
142 else
143 {
144 m_state |= ( agx::UInt8 ) NONHOLONOMIC;
145 }
146 }
147
148 AGX_FORCE_INLINE agx::Vec3 point() const { return m_point; }
149 AGX_FORCE_INLINE agx::Vec3f normal() const { return m_normal; }
150 AGX_FORCE_INLINE agx::Vec3f velocity() const { return m_velocity; }
151 AGX_FORCE_INLINE agx::Real depth() const { return m_depth; }
152 AGX_FORCE_INLINE agx::Real maxNormalForce() const { return m_maxNormalForce; }
153 AGX_FORCE_INLINE agx::Real area() const { return m_area; }
154 AGX_FORCE_INLINE agx::Real elasticRestLengthShape1() const { return m_elasticRestLengthShape1; }
155 AGX_FORCE_INLINE agx::Real elasticRestLengthShape2() const { return m_elasticRestLengthShape2; }
156 AGX_FORCE_INLINE agx::UInt32 faceIndex1() const { return m_faceIndex1; }
157 AGX_FORCE_INLINE agx::UInt32 faceIndex2() const { return m_faceIndex2; }
158 AGX_FORCE_INLINE agx::UInt8 faceFeature1() const { return m_faceFeature1; }
159 AGX_FORCE_INLINE agx::UInt8 faceFeature2() const { return m_faceFeature2; }
162 AGX_FORCE_INLINE bool enabled() const { return m_enabled; }
163 AGX_FORCE_INLINE const agx::ContactMaterial* material() const { return m_material; }
164 AGX_FORCE_INLINE agx::UInt8 state() const { return m_state; }
165 AGX_FORCE_INLINE bool isHolonomic() const { return ( m_state & NONHOLONOMIC ) == 0; }
166
167 private:
168 agx::Vec3 m_point;
169 agx::Vec3f m_normal;
170 agx::Vec3f m_velocity;
171 agx::Real m_depth;
172 agx::Real m_maxNormalForce;
173 agx::Real m_area;
174 agx::Real m_elasticRestLengthShape1;
175 agx::Real m_elasticRestLengthShape2;
178 const agx::ContactMaterial* m_material;
179 agx::UInt32 m_faceIndex1;
180 agx::UInt32 m_faceIndex2;
181 agx::UInt8 m_faceFeature1;
182 agx::UInt8 m_faceFeature2;
183 bool m_enabled;
184 agx::UInt8 m_state;
185 agx::UInt8 m_padding;
186 };
187
188 template<typename T>
190 {
191 LocalContactPoint local( pointType.point(), pointType.normal(), pointType.depth() );
192 local.m_maxNormalForce = pointType.maxNormalForce();
193 local.m_velocity = pointType.velocity();
194 local.m_area = pointType.area();
195 local.m_elasticRestLengthShape1 = pointType.elasticRestLengthShape1();
196 local.m_elasticRestLengthShape2 = pointType.elasticRestLengthShape2();
197 local.m_shape1 = pointType.shape1();
198 local.m_shape2 = pointType.shape2();
199 local.m_faceIndex1 = pointType.faceIndex1();
200 local.m_faceIndex2 = pointType.faceIndex2();
201 local.m_faceFeature1 = pointType.faceFeature1();
202 local.m_faceFeature2 = pointType.faceFeature2();
203 local.m_state = pointType.state();
204 return local;
205 }
206
208
210 {
211 public:
213
214 public:
216 m_geometries[0] = nullptr;
217 m_geometries[1] = nullptr;
218 m_bodies[0] = nullptr;
219 m_bodies[1] = nullptr;
220 m_contactMaterial = nullptr;
221 m_hasInternalMaterial = false;
222 m_hasSurfaceVelocity = false;
223 }
224
226 m_geometries[0] = g1;
227 m_geometries[1] = g2;
228 if (m_geometries[0])
229 m_bodies[0] = m_geometries[0]->getRigidBody();
230 if (m_geometries[1])
231 m_bodies[1] = m_geometries[1]->getRigidBody();
232 m_contactMaterial = nullptr;
233 m_hasInternalMaterial = false;
234 m_hasSurfaceVelocity = false;
235 }
236
238 m_geometries[0] = g1;
239 m_geometries[1] = g2;
240 m_bodies[0] = b1;
241 m_bodies[1] = b2;
242 m_contactMaterial = nullptr;
243 m_hasInternalMaterial = false;
244 m_hasSurfaceVelocity = false;
245 }
246
248 m_geometries[0] = g1;
249 m_geometries[1] = g2;
250 if (m_geometries[0])
251 m_bodies[0] = m_geometries[0]->getRigidBody();
252 if (m_geometries[1])
253 m_bodies[1] = m_geometries[1]->getRigidBody();
254 m_points.clear();
255 }
256
258 m_geometries[0] = g1;
259 m_geometries[1] = g2;
260 m_bodies[0] = b1;
261 m_bodies[1] = b2;
262 m_points.clear();
263 }
264
265 AGX_FORCE_INLINE void setGeometry( size_t ith, Geometry *geom ) { agxAssert(ith <2 ); m_geometries[ith] = geom; }
266 AGX_FORCE_INLINE void setRigidBody( size_t ith, agx::RigidBody* body ) { agxAssert(ith <2 ); m_bodies[ith] = body; }
269 AGX_FORCE_INLINE void setHasSurfaceVelocity(const agx::Bool hasSurfaceVelocity) { m_hasSurfaceVelocity = hasSurfaceVelocity; }
270
271 AGX_FORCE_INLINE void addPoint(const LocalContactPoint& point) { m_points.push_back(point); }
273 AGX_FORCE_INLINE const LocalContactPointVector& points() const { return m_points; }
274
275 AGX_FORCE_INLINE agxCollide::Geometry* geometry( size_t ith ) { agxAssert(ith <2 ); return m_geometries[ith]; }
276 AGX_FORCE_INLINE const agxCollide::Geometry* geometry( size_t ith ) const { agxAssert(ith <2 ); return m_geometries[ith]; }
277
278 AGX_FORCE_INLINE agx::RigidBody* rigidBody( size_t ith ) { agxAssert(ith <2 ); return m_bodies[ith]; }
279 AGX_FORCE_INLINE const agx::RigidBody* rigidBody( size_t ith ) const { agxAssert(ith <2 ); return m_bodies[ith]; }
280
281 AGX_FORCE_INLINE agx::ContactMaterial *material() { return m_contactMaterial; }
282 AGX_FORCE_INLINE const agx::ContactMaterial *material() const { return m_contactMaterial; }
283
284 AGX_FORCE_INLINE agx::Bool& hasInternalMaterial() { return m_hasInternalMaterial; }
285 AGX_FORCE_INLINE const agx::Bool& hasInternalMaterial() const { return m_hasInternalMaterial; }
286
287 AGX_FORCE_INLINE agx::Bool& getHasSurfaceVelocity() { return m_hasSurfaceVelocity; }
288 AGX_FORCE_INLINE const agx::Bool& getHasSurfaceVelocity() const { return m_hasSurfaceVelocity; }
289
290
291 private:
292 Geometry* m_geometries[2];
293 agx::RigidBody* m_bodies[2];
295 agx::ContactMaterial* m_contactMaterial;
296 agx::Bool m_hasInternalMaterial;
297 agx::Bool m_hasSurfaceVelocity;
298 };
299
301
303 {
304 public:
306 {
307 }
308
310 {
311 }
312
313 AGX_FORCE_INLINE const agx::Physics::GeometryPtr& geometry() const { return m_geometry; }
315
316 AGX_FORCE_INLINE const agx::Physics::ParticlePtr& particle() const { return m_particle; }
318
319 private:
320 agx::Physics::ParticlePtr m_particle;
321 agx::Physics::GeometryPtr m_geometry;
322 };
323
325
327 {
328 public:
330 {
331 }
332
334 {
335 }
336
337 AGX_FORCE_INLINE const agx::Physics::ParticlePtr& particle1() const { return m_particle1; }
339
340
341 AGX_FORCE_INLINE const agx::Physics::ParticlePtr& particle2() const { return m_particle2; }
343
344 private:
345 agx::Physics::ParticlePtr m_particle1;
346 agx::Physics::ParticlePtr m_particle2;
347 };
348
350}
351
352#ifdef _MSC_VER
353# pragma warning(pop)
354#endif
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::RigidBody * getRigidBody()
Definition: Geometry.h:790
const agx::ContactMaterial *& material()
const agx::ContactMaterial * material() const
agx::Real elasticRestLengthShape2() const
agx::Physics::Geometry::ShapePtr shape1() const
@ IMPACTING
This contact point is impacting - i.e., relative speed along the normal is above some threshold.
@ NONHOLONOMIC
This contact point is treated as a non-holonomic constraint in the normal direction - i....
agx::Physics::Geometry::ShapePtr & shape2()
LocalContactPoint(const agx::Vec3 &p, const agx::Vec3f &n, agx::Real d)
agx::Real elasticRestLengthShape1() const
void setIsHolonomic(bool isHolonomic)
agx::Physics::Geometry::ShapePtr shape2() const
static LocalContactPoint create(const T &pointType)
Creates an enabled copy of given pointType (agxCollide::ContactPoint).
LocalContactPoint(const agx::Vec3 &p, const agx::Vec3 &n, agx::Real d)
agx::Physics::Geometry::ShapePtr & shape1()
agx::RigidBody * rigidBody(size_t ith)
void setContactMaterial(agx::ContactMaterial *material)
LocalContactPointVector & points()
void setGeometry(size_t ith, Geometry *geom)
void setHasSurfaceVelocity(const agx::Bool hasSurfaceVelocity)
void addPoint(const LocalContactPoint &point)
void init(Geometry *g1, Geometry *g2)
const agx::RigidBody * rigidBody(size_t ith) const
const agx::Bool & hasInternalMaterial() const
const agxCollide::Geometry * geometry(size_t ith) const
const LocalContactPointVector & points() const
const agx::Bool & getHasSurfaceVelocity() const
const agx::ContactMaterial * material() const
LocalGeometryContact(Geometry *g1, Geometry *g2, agx::RigidBody *b1, agx::RigidBody *b2)
void init(Geometry *g1, Geometry *g2, agx::RigidBody *b1, agx::RigidBody *b2)
LocalGeometryContact(Geometry *g1, Geometry *g2)
void setHasInternalMaterial(const agx::Bool hasInternalMaterial)
void setRigidBody(size_t ith, agx::RigidBody *body)
agxCollide::Geometry * geometry(size_t ith)
agx::ContactMaterial * material()
const agx::Physics::GeometryPtr & geometry() const
LocalParticleGeometryContact(agx::Physics::ParticlePtr particle, agx::Physics::GeometryPtr geometry)
agx::Physics::GeometryPtr & geometry()
agx::Physics::ParticlePtr & particle()
const agx::Physics::ParticlePtr & particle() const
const agx::Physics::ParticlePtr & particle2() const
const agx::Physics::ParticlePtr & particle1() const
agx::Physics::ParticlePtr & particle1()
agx::Physics::ParticlePtr & particle2()
LocalParticlePairContact(agx::Physics::ParticlePtr p1, agx::Physics::ParticlePtr p2)
This class store the combine material properties between two agx::Material's.
Definition: Material.h:516
Pointer to a entity instance of type Physics.Geometry.
Pointer to a entity instance of type Physics.Geometry.Shape.
Definition: ShapeEntity.h:196
Pointer to a entity instance of type Physics.Particle.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
Vector containing 'raw' data.
Definition: agx/Vector.h:246
void push_back(const T &value)
Definition: agx/Vector.h:1362
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
Definition: agx/Vector.h:1149
Templated vector class.
Definition: agx/Vector.h:53
#define agxAssert(expr)
Definition: debug.h:143
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::Vector< LocalParticlePairContact > LocalParticlePairContactVector
agx::VectorPOD< LocalContactPoint > LocalContactPointVector
agx::Vector< LocalParticleGeometryContact > LocalParticleGeometryContactVector
agx::Vector< LocalGeometryContact > LocalGeometryContactVector
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
bool Bool
Definition: Integer.h:40
double Real
Definition: Real.h:42
uint8_t UInt8
Definition: Integer.h:30