AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
OrientedFrictionModels.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 <agx/FrictionModel.h>
20#include <agx/Attachment.h>
21#include <agx/BitState.h>
22
23namespace agx
24{
29
34 template<typename T>
36 {
37 public:
38 using Model = T;
39
40 public:
48 const agx::Vec3& primaryDirection,
50
55
60 void setReferenceFrame( const agx::Frame* refFrame );
61
66
71 void setPrimaryDirection( const agx::Vec3& primaryDirection );
72
83 void setFrame( const agxCollide::Geometry* geometry, const agx::Frame* frame );
84
92 void setFrame( const agx::RigidBody* rb, const agx::Frame* frame );
93
94
101 const agx::Frame* getFrame( const agxCollide::Geometry* geometry ) const;
102
110 const agx::Frame* getFrameOrReference( const agxCollide::Geometry* geometry ) const;
111
112 public:
117 virtual void calculateTangentPlane( const agxCollide::Geometry* geometry1,
118 const agxCollide::Geometry* geometry2,
119 const agx::Vec3& point,
120 const agx::Vec3& normal,
121 const agx::Real depth,
122 agx::Vec3& ret_u,
123 agx::Vec3& ret_v ) const;
124
125 protected:
127
128 private:
129 struct GeometryFrame
130 {
133
134 inline bool isValid() const
135 {
136 return geometry.isValid() && frame.isValid();
137 }
138 };
139
141
142 private:
143 agx::FrameConstObserver m_refFrame;
144 agx::Vec3 m_primaryDirection;
145 GeometryFrameTable m_geometryFrameTable;
146 };
147
148#ifdef SWIG
149 %template(OrientedBoxFrictionModelImpl) OrientedFrictionModelImpl<agx::BoxFrictionModel>;
150 %template(OrientedScaleBoxFrictionModelImpl) OrientedFrictionModelImpl<agx::ScaleBoxFrictionModel>;
151 %template(OrientedIterativeProjectedConeFrictionModelImpl) OrientedFrictionModelImpl<agx::IterativeProjectedConeFriction>;
152#endif
153
158 {
159 public:
161
162 public:
170 const agx::Vec3& primaryDirection,
172
173 public:
175
176 protected:
178
180 };
181
186 {
187 public:
189
190 public:
198 const agx::Vec3& primaryDirection,
200
201 public:
203
204 protected:
206
208 };
209
214 {
215 public:
217
218 public:
226 const agx::Vec3& primaryDirection,
228
229 public:
231
232 protected:
234
236 };
237
250 {
251 public:
261 const agx::Frame* refFrame,
262 const agx::Vec3& primaryDirection,
264 agx::Bool scaleWithDepth = false );
265
270 void setNormalForceMagnitude( agx::Real normalForceMagnitude );
271
276
286
291
292 public:
297 const agxCollide::Geometry* geometry2,
298 const agx::Vec3& point,
299 const agx::Vec3& normal,
300 const agx::Real depth,
301 const agx::Real dt,
302 const size_t numPoints ) const override;
303
305
306 protected:
308
310
311 private:
312 enum Flag : agx::UInt16
313 {
314 SCALE_WITH_DEPTH = 1 << 0
315 };
316 using Flags = agx::BitState<Flag, agx::UInt16>;
317
318 private:
319 agx::Real m_normalForceMagnitude;
320 Flags m_flags;
321 };
322
323 template<typename T>
325 const agx::Vec3& primaryDirection,
327 : T( solveType ), m_refFrame( refFrame ), m_primaryDirection( primaryDirection )
328 {
329 }
330
331 template<typename T>
333 {
334 }
335
336 template<typename T>
338 {
339 return m_refFrame;
340 }
341
342 template<typename T>
344 {
345 m_refFrame = refFrame;
346 }
347
348 template<typename T>
350 {
351 return m_primaryDirection;
352 }
353
354 template<typename T>
356 {
357 m_primaryDirection = primaryDirection;
358 }
359
360 template<typename T>
362 {
363 auto pruneIt = m_geometryFrameTable.begin();
364 while ( pruneIt != m_geometryFrameTable.end() ) {
365 if ( !pruneIt->second.isValid() )
366 pruneIt = m_geometryFrameTable.erase( pruneIt );
367 else
368 ++pruneIt;
369 }
370
371 if ( geometry == nullptr )
372 return;
373
374 auto it = m_geometryFrameTable.find( geometry );
375 // Insert new.
376 if ( it == m_geometryFrameTable.end() && frame != nullptr )
377 it = m_geometryFrameTable.insert( geometry, { geometry, frame } );
378 // Remove old.
379 else if ( it != m_geometryFrameTable.end() && frame == nullptr )
380 m_geometryFrameTable.erase( it );
381 // Change existing.
382 else if ( it != m_geometryFrameTable.end() && frame != it->second.frame )
383 it->second.frame = frame;
384 }
385
386 template<typename T>
388 {
389 if ( rb == nullptr )
390 return;
391
392 for ( const auto& geometry : rb->getGeometries() )
393 setFrame( geometry, frame );
394 }
395
396 template<typename T>
398 {
399 if ( const auto data = m_geometryFrameTable.try_get( geometry ) )
400 return data->frame;
401 return nullptr;
402 }
403
404 template<typename T>
406 {
407 const auto frameTableIt = geometry != nullptr && !m_geometryFrameTable.empty() ?
408 m_geometryFrameTable.find( geometry ) :
409 m_geometryFrameTable.end();
410 return frameTableIt == m_geometryFrameTable.end() ?
411 m_refFrame.get() :
412 frameTableIt->second.frame.get();
413 }
414
415 template<typename T>
417 const agxCollide::Geometry* geometry2,
418 const agx::Vec3& /*point*/,
419 const agx::Vec3& normal,
420 const agx::Real /*depth*/,
421 agx::Vec3& ret_u,
422 agx::Vec3& ret_v ) const
423 {
424 const auto f1 = getFrameOrReference( geometry1 );
425 const auto f2 = getFrameOrReference( geometry2 );
426 // geometry1 is always from a dynamic body, e.g., if both geometry1
427 // and geometry2 has explicit frames we use one from a dynamic body.
428 const auto f = f1 != m_refFrame ? f1 : f2;
429 agxAssert( f != nullptr || m_refFrame == nullptr );
430
432 f->transformVectorToWorld( m_primaryDirection ) :
433 m_primaryDirection,
434 normal,
435 ret_u,
436 ret_v );
437 }
438}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Oriented box friction model that uses the same normal force magnitude for all contact points associat...
void setEnableScaleWithDepth(agx::Bool enable)
Enable/disable scale of the given normal force with the contact point depth resulting in a maximum fr...
virtual agx::Real calculateNormalForce(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2, const agx::Vec3 &point, const agx::Vec3 &normal, const agx::Real depth, const agx::Real dt, const size_t numPoints) const override
void setNormalForceMagnitude(agx::Real normalForceMagnitude)
Assign normal force magnitude.
ConstantNormalForceOrientedBoxFrictionModel(agx::Real normalForceMagnitude, const agx::Frame *refFrame, const agx::Vec3 &primaryDirection, agx::FrictionModel::SolveType solveType=agx::FrictionModel::SPLIT, agx::Bool scaleWithDepth=false)
Construct given normal force magnitude, reference frame and primary direction.
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
@ SPLIT
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
Definition: FrictionModel.h:62
static void calculateTangentPlane(const Vec3 &primaryDirectionWorld, const Vec3 &normal, Vec3 &ret_u, Vec3 &ret_v)
Calculates friction tangents directions given primaryDirectionWorld and contact normal.
Inheritance with partial specialization due to bug with ref_ptr containers.
Box friction model with oriented friction box.
OrientedBoxFrictionModel(const agx::Frame *refFrame, const agx::Vec3 &primaryDirection, agx::FrictionModel::SolveType solveType=agx::FrictionModel::SPLIT)
Construct given frame of reference and primary friction direction.
Oriented friction box base implementation containing a frame of reference and the primary direction g...
void setFrame(const agx::RigidBody *rb, const agx::Frame *frame)
Utility method to assign all current geometries of rb the explicit oriented frame frame.
OrientedFrictionModelImpl(const agx::Frame *refFrame, const agx::Vec3 &primaryDirection, agx::FrictionModel::SolveType solveType)
Construct given frame of reference and primary friction direction.
void setPrimaryDirection(const agx::Vec3 &primaryDirection)
Assign primary friction direction given in reference frame.
const agx::Frame * getFrameOrReference(const agxCollide::Geometry *geometry) const
Explicit oriented frame for geometry or reference frame of this model if not assigned.
const agx::Frame * getReferenceFrame() const
void setReferenceFrame(const agx::Frame *refFrame)
Assign frame of reference.
void setFrame(const agxCollide::Geometry *geometry, const agx::Frame *frame)
Assign reference frame override for the given geometry.
const agx::Vec3 & getPrimaryDirection() const
virtual void calculateTangentPlane(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2, const agx::Vec3 &point, const agx::Vec3 &normal, const agx::Real depth, agx::Vec3 &ret_u, agx::Vec3 &ret_v) const
Calculates primary and secondary friction directions in world coordinates given contact point.
const agx::Frame * getFrame(const agxCollide::Geometry *geometry) const
Explicit oriented frame for geometry or nullptr if not assigned.
Iterative projected cone friction model with oriented friction box.
OrientedIterativeProjectedConeFrictionModel(const agx::Frame *refFrame, const agx::Vec3 &primaryDirection, agx::FrictionModel::SolveType solveType=agx::FrictionModel::SPLIT)
Construct given frame of reference and primary friction direction.
Scale box friction model with oriented friction box.
OrientedScaleBoxFrictionModel(const agx::Frame *refFrame, const agx::Vec3 &primaryDirection, agx::FrictionModel::SolveType solveType=agx::FrictionModel::SPLIT)
Construct given frame of reference and primary friction direction.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
const agxCollide::GeometryRefVector & getGeometries() const
bool isValid() const
Definition: observer_ptr.h:288
#define agxAssert(expr)
Definition: debug.h:143
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint16_t UInt16
Definition: Integer.h:31
bool Bool
Definition: Integer.h:40
double Real
Definition: Real.h:41