AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Contacts.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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#ifdef _MSC_VER
20# pragma warning(push)
21# pragma warning( disable : 4275 ) // warning C4275: non dll-interface class
22#endif
23
25
27#include <agx/agx.h>
28#include <agx/Referenced.h>
29#include <agx/RigidBody.h>
30#include <agx/Vec3.h>
32
33#include <agx/Material.h>
34#include <agx/Vector.h>
40
41
42namespace agxSDK
43{
44 class MaterialManager;
45}
46
47namespace agxCollide
48{
49 class Geometry;
50
51
56 {
57 public:
59 {
60 NORMAL_FORCE = 0,
62 TANGENTIAL_FORCE_V
63 };
64
66 {
67 IMPACTING = 1 << 0,
73 NONHOLONOMIC = 1 << 1
79 };
80
81 public:
86
93
100 ContactPoint(agx::Vec3 thePoint, agx::Vec3f theNormal, agx::Real theDepth);
101
103 void clear();
104
106
107#ifndef SWIG
113 agx::Real& localForce( size_t idx );
114#endif
120 agx::Real localForce( size_t idx ) const;
121
126 agx::Vec3 getForce() const;
127
131 agx::Real getForceMagnitude() const;
132
136 agx::Vec3 getNormalForce() const;
137
141 agx::Real getNormalForceMagnitude() const;
142
146 agx::Real getTangentialForceUMagnitude() const;
147
151 agx::Real getTangentialForceVMagnitude() const;
152
156 agx::Real getTangentialForceMagnitude() const;
157
161 agx::Vec3 getTangentialForce() const;
162
167 agx::UInt32& faceIndex(size_t ith);
168
173 agx::UInt32 const& faceIndex(size_t ith) const;
174
179 agx::UInt8& faceFeature(size_t ith);
180
185 agx::UInt8 const& faceFeature(size_t ith) const;
186
191 agx::Physics::Geometry::ShapePtr& shape(size_t ith);
192
197 agx::Physics::Geometry::ShapePtr const& shape(size_t ith) const;
198
207 agx::Vec3 getWitnessPoint(size_t ith) const;
208
212 agx::Bool hasState( ContactPointState contactPointState ) const;
213
220 void setIsHolonomic( agx::Bool isHolonomic );
221
226 agx::Bool isHolonomic() const;
227 };
228
229
235 template<typename T1, typename T2>
236 void copyContactPoint(const T1& from, T2& to)
237 {
238 to.point() = from.point();
239 to.normal() = from.normal();
240 to.depth() = from.depth();
241 to.area() = from.area();
242
243 to.velocity() = from.velocity();
244 to.enabled() = from.enabled();
245
246 to.shape1() = from.shape1();
247 to.shape2() = from.shape2();
248
249 to.faceIndex1() = from.faceIndex1();
250 to.faceIndex2() = from.faceIndex2();
251 to.faceFeature1() = from.faceFeature1();
252 to.faceFeature2() = from.faceFeature2();
253 to.state() = from.state();
254 }
255
256#ifndef SWIG
261
262
264#endif
266
271 {
272 public:
274
275 public:
278 NO_CONTACT = 0,
279 IMPACT_STATE = 1,
280 CONTACT_STATE = 2,
281 SEPARATION_STATE = 3
282 };
283
284 public:
289
295
299 void clear();
300
308 agx::Vec3f calculateRelativeVelocity( size_t pointIndex = 0 ) const;
309
317 static bool calculateSurfaceVelocity( const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2, LocalContactPoint& p );
318
326 static bool calculateSurfaceVelocity( const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2, ContactPoint& p );
327
332 agxCollide::Geometry* geometry( size_t ith );
333
338 const agxCollide::Geometry* geometry( size_t ith ) const;
339
345 agx::RigidBody* rigidBody( size_t ith );
346
352 const agx::RigidBody* rigidBody( size_t ith ) const;
353
355 ContactPointVector& points();
356
358 const ContactPointVector& points() const;
359
361 void* getCustomData();
362
364 const void* getCustomData() const;
365
370 void setCustomData( void* customData );
371
378 agx::ContactMaterial* getMaterial();
379
386 const agx::ContactMaterial* getMaterial() const;
387
393 const agx::ContactMaterial* getMaterial( bool ) const;
394
396 agx::UInt8 state() const;
397
400
404 void setEnable(bool flag);
405
414 int contains(agx::RigidBody * body) const;
415
424 int contains(agxCollide::Geometry * geometry) const;
425
429 bool isEnabled() const;
430
438
439
441
442
443
448 void setGeometry( size_t ith, Geometry* geom );
449
450 /***
451 When called, this contact should be removed before entering the solver
452 NOTE: Contacts are never removed, only marked as disabled
453 \param immediately - Should the contact be removed immediately
454 */
455 void markForRemoval( bool immediately );
456
462 bool shouldBeCalled() const;
463
467 void setMaterial( agx::ContactMaterial* material );
468
469 void setHasSurfaceVelocity( bool flag );
470
471 GeometryPair getGeometryPair();
472
473 void setHasInternalMaterial( bool flag );
474 bool getHasInternalMaterial( ) const;
475
476 void setState( agx::UInt8 state );
478 };
479
480
481
482 inline int GeometryContact::contains(agx::RigidBody * body) const
483 {
484 if (this->rigidBody(0) == body) return 0;
485 if (this->rigidBody(1) == body) return 1;
486 return -1;
487 }
488
490 {
491 if (this->geometry(0) == geometry) return 0;
492 if (this->geometry(1) == geometry) return 1;
493 return -1;
494 }
495
496
497
498#ifndef SWIG
499 //AGX_STATIC_ASSERT(sizeof(GeometryContact) == sizeof(agx::Physics::GeometryContactPtr));
500#endif
501
502 /* Implementation */
503 inline ContactPoint::ContactPoint() : agx::Physics::ContactPointPtr( agx::Physics::ContactPointModel::createInstance() )
504 {
505 }
506
507 inline ContactPoint::ContactPoint(agx::Physics::ContactPointPtr contact) : agx::Physics::ContactPointPtr(contact)
508 {
509 }
510
511
513 {
514 depth() = agx::Real( 0 );
515 enabled() = true;
516 point().set(0, 0, 0);
517 normal().set(0, 0, 0);
518 state() = agx::UInt8( 0 );
519 tangentU().set(0, 0, 0);
520 tangentV().set(0, 0, 0);
521 localForce().set( 0, 0, 0 );
522 velocity().set(0, 0, 0);
523 faceIndex1() = 0;
524 faceIndex2() = 0;
525 faceFeature1() = 0;
526 faceFeature2() = 0;
527 area() = agx::Real( 0 );
530 }
531
532
534 {
535 agxAssert(idx < 3);
536 return localForce()[idx];
537 }
538
539
541 {
542 agxAssert(idx < 3);
543 return localForce()[idx];
544 }
545
546
547
552
553
562
563
568
569
574
575
577 {
580 return forceU + forceV;
581 }
582
583
588
589
594
595
601
603 {
604 return ( state() & contactPointState ) != 0;
605 }
606
611
613 {
614 if ( isHolonomic )
615 {
616 // remove non-holonomic bit
617 state() = (agx::UInt8)( state() & ~NONHOLONOMIC );
618 }
619 else
620 {
621 // add non-holonomic bit
622 state() |= ( agx::UInt8 )( NONHOLONOMIC );
623 }
624 }
625
630
632 agx::Physics::GeometryContactPtr(contact)
633
634 {
635 }
636
638 {
639 agxAssert(ith < 2);
640 if(ith == 0)
641 return geometry1().model();
642 else
643 return geometry2().model();
644 }
645
647 {
648 agxAssert(ith < 2);
649 if(ith == 0)
650 return geometry1().model();
651 else
652 return geometry2().model();
653 }
654
655 AGX_FORCE_INLINE GeometryPair GeometryContact::getGeometryPair()
656 {
657 return GeometryPair(geometry(0), geometry(1));
658 }
659
660 AGX_FORCE_INLINE void GeometryContact::setGeometry( size_t ith, Geometry* geom )
661 {
662 agxAssert(ith < 2 );
663 if(ith == 0)
664 geometry1() = geom->getEntity();
665 else
666 geometry2() = geom->getEntity();
667 }
668
670 {
671 agx::Vec3 v1, v2;
672 if (pointIndex > points().size() - 1)
673 return agx::Vec3f();
674
675 const agx::RigidBody* rb1 = geometry(0)->getRigidBody();
676 const agx::RigidBody* rb2 = geometry(1)->getRigidBody();
677
678 if (rb1)
679 v1 = rb1->getVelocity() + (rb1->getAngularVelocity() ^ (points()[pointIndex].point() - rb1->getCmPosition()));
680 if (rb2)
681 v2 = rb2->getVelocity() + (rb2->getAngularVelocity() ^ (points()[pointIndex].point() - rb2->getCmPosition()));
682
683 return static_cast<agx::Vec3f>(v1 - v2);
684 }
685
686
688 {
690 lcp.point() = p.point();
692 p.velocity() = lcp.velocity();
693 return hasSurfaceVelocity;
694 }
695
696
698 {
699 agxAssert(ith < 2 );
700 return geometry(ith)->getRigidBody();
701 }
702
704 {
705 agxAssert(ith < 2 );
706 return geometry(ith)->getRigidBody();
707 }
708
709
714
719
724
726 {
727 return customData();
728 }
729
730 inline void GeometryContact::setCustomData( void* customData )
731 {
732 this->customData() = customData;
733 }
734
735
736 AGX_FORCE_INLINE void GeometryContact::markForRemoval( bool immediately )
737 {
738 this->immediately() = immediately;
739 this->enabled() = false;
740 }
741
743 {
744 this->enabled() = flag;
745 }
746
748 {
749 return this->enabled();
750 }
751
752
753 AGX_FORCE_INLINE bool GeometryContact::shouldBeCalled() const
754 {
755 return !immediately();
756 }
757
759 {
760 if ( material() && material().isExplicit() )
761 return material().model();
762 return nullptr;
763 }
764
766 {
767 if ( material() && material().isExplicit() )
768 return material().model();
769 return nullptr;
770 }
771
773 {
774 return material() ? material().model() : nullptr;
775 }
776
777 AGX_FORCE_INLINE void GeometryContact::setMaterial( agx::ContactMaterial* material )
778 {
779 agxAssert( material != nullptr );
780 if (material)
781 this->material() = material->getEntity();
782 }
783
784 AGX_FORCE_INLINE void GeometryContact::setHasSurfaceVelocity( bool flag )
785 {
786 hasSurfaceVelocity() = flag;
787 }
788
789
790 AGX_FORCE_INLINE void GeometryContact::setHasInternalMaterial( bool flag )
791 {
792 hasInternalMaterial() = flag;
793 }
794
795 AGX_FORCE_INLINE bool GeometryContact::getHasInternalMaterial( ) const
796 {
797 return hasInternalMaterial();
798 }
799
807
808 AGX_FORCE_INLINE void GeometryContact::setState( agx::UInt8 state )
809 {
812 }
813
815 {
816 if (ith == 0) return faceIndex1(); else return faceIndex2();
817 }
818
819
821 {
822 if (ith == 0) return faceIndex1(); else return faceIndex2();
823 }
824
825
827 {
828 if (ith == 0) return faceFeature1(); else return faceFeature2();
829 }
830
831
833 {
834 if (ith == 0) return faceFeature1(); else return faceFeature2();
835 }
836
837
839 {
840 if (ith == 0) return shape1(); else return shape2();
841 }
842
843
845 {
846 if (ith == 0) return shape1(); else return shape2();
847 }
848
849
851 {
852 if (ith == 0)
853 return point() - agx::Vec3(normal()) * (depth() * agx::Real(0.5));
854 else
855 return point() + agx::Vec3(normal()) * (depth() * agx::Real(0.5));
856 }
857}
858
859#ifdef _MSC_VER
860# pragma warning(pop)
861#endif
862
#define AGXPHYSICS_EXPORT
A contact point in a contact data.
Definition Contacts.h:56
agx::Real getForceMagnitude() const
Definition Contacts.h:554
void clear()
Clear all values in this contact.
Definition Contacts.h:512
agx::Real getNormalForceMagnitude() const
Definition Contacts.h:570
agx::Real getTangentialForceVMagnitude() const
Definition Contacts.h:590
agx::Bool isHolonomic() const
Definition Contacts.h:607
ContactPoint(agx::Vec3 thePoint, agx::Vec3f theNormal, agx::Real theDepth)
Construct given point, normal and depth.
@ TANGENTIAL_FORCE_V
Tangential force V, orthogonal to the normal force and U.
Definition Contacts.h:62
@ TANGENTIAL_FORCE_U
Tangential force U, orthogonal to the normal force and V.
Definition Contacts.h:61
@ NORMAL_FORCE
Normal force.
Definition Contacts.h:60
void setIsHolonomic(agx::Bool isHolonomic)
Set if contact point should be treated as a holonomic constraint ( regular contact constraint with de...
Definition Contacts.h:612
agx::Real getTangentialForceUMagnitude() const
Definition Contacts.h:584
agx::UInt32 & faceIndex(size_t ith)
Definition Contacts.h:814
agx::Physics::Geometry::ShapePtr & shape(size_t ith)
Definition Contacts.h:838
agx::Bool hasState(ContactPointState contactPointState) const
Definition Contacts.h:602
agx::Vec3 getWitnessPoint(size_t ith) const
Get witness point for ith geometry.
Definition Contacts.h:850
agx::Vec3 getTangentialForce() const
Definition Contacts.h:576
agx::Vec3 getNormalForce() const
Definition Contacts.h:564
@ NONHOLONOMIC
This contact point is treated as a non-holonomic constraint in the normal direction - i....
Definition Contacts.h:73
agx::Vec3 getForce() const
Definition Contacts.h:548
agx::Real getTangentialForceMagnitude() const
Definition Contacts.h:596
agx::UInt8 & faceFeature(size_t ith)
Definition Contacts.h:826
ContactPoint()
Default constructor.
Definition Contacts.h:503
A contact between two geometries.
Definition Contacts.h:271
void setCustomData(void *customData)
Store custom data for this Contact.
Definition Contacts.h:730
agxCollide::Geometry * geometry(size_t ith)
Definition Contacts.h:637
void setEnable(bool flag)
Set to false to disable the contact.
Definition Contacts.h:742
agx::UInt8 state() const
Definition Contacts.h:800
agx::RigidBody * rigidBody(size_t ith)
Returns access to rigid body data.
Definition Contacts.h:697
agx::Vec3f calculateRelativeVelocity(size_t pointIndex=0) const
Calculate the relative velocity in a contact point.
Definition Contacts.h:669
void removeContactPoint(ContactPoint &point)
remove the specified ContactPoint from the set of contact points.
void clear()
Clear contact points.
agx::ContactMaterial * getMaterial()
If the contact material for this geometry contact is explicit it can be accessed here.
Definition Contacts.h:758
int contains(agx::RigidBody *body) const
Will return -1 if body does not exist in this GeometryContact, 0 if it is the first (index 0) and 1 i...
Definition Contacts.h:482
ContactState
Specify the state of the contact.
Definition Contacts.h:277
@ NO_CONTACT
! No contact yet
Definition Contacts.h:278
ContactPointVector & points()
Definition Contacts.h:710
static bool calculateSurfaceVelocity(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2, LocalContactPoint &p)
Calculate the relative velocity in a contact point between geometry1 and geometry2 Put result in p.
agx::Bool hasImpactingPoints() const
GeometryContact()
Default constructor.
Definition Contacts.h:626
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
agx::RigidBody * getRigidBody()
Definition Geometry.h:790
Only use as member allocated variable.
Definition Value.h:285
This class store the combine material properties between two agx::Material's.
Definition Material.h:516
AGXPHYSICS_EXPORT agx::UInt8 & state()
AGXPHYSICS_EXPORT agx::ContactMaterial *& model()
Pointer to a entity instance of type Physics.ContactPoint.
AGXPHYSICS_EXPORT agx::Vec3 & localForce()
AGXPHYSICS_EXPORT agx::Vec3 & point()
AGXPHYSICS_EXPORT agx::Vec3f & normal()
AGXPHYSICS_EXPORT agx::UInt8 & faceFeature1()
The face feature of shape 1 in contact (e.g. voronoi region on triangle for trimesh).
AGXPHYSICS_EXPORT agx::Physics::Geometry::ShapePtr & shape1()
Shape number 1 in contact.
AGXPHYSICS_EXPORT agx::UInt8 & state()
Contact point state, such as impacting, resting etc.
AGXPHYSICS_EXPORT agx::UInt32 & faceIndex2()
The face index of shape 2 in contact (e.g. index of triangle for trimesh).
AGXPHYSICS_EXPORT agx::Physics::Geometry::ShapePtr & shape2()
Shape number 2 in contact.
AGXPHYSICS_EXPORT agx::Real & area()
AGXPHYSICS_EXPORT agx::UInt32 & faceIndex1()
The face index of shape 1 in contact (e.g. index of triangle for trimesh).
AGXPHYSICS_EXPORT agx::Vec3f & velocity()
AGXPHYSICS_EXPORT agx::Bool & enabled()
AGXPHYSICS_EXPORT agx::Vec3f & tangentU()
AGXPHYSICS_EXPORT agx::Vec3f & tangentV()
AGXPHYSICS_EXPORT agx::Real & depth()
AGXPHYSICS_EXPORT agx::UInt8 & faceFeature2()
The face feature of shape 2 in contact (e.g. voronoi region on triangle for trimesh).
AGXPHYSICS_EXPORT agx::Physics::ContactMaterialPtr & material()
A geometry contact hold contact information between two geometries.
AGXPHYSICS_EXPORT agx::Bool & hasInternalMaterial()
AGXPHYSICS_EXPORT void *& customData()
AGXPHYSICS_EXPORT agx::Bool & hasSurfaceVelocity()
AGXPHYSICS_EXPORT agx::Bool & enabled()
AGXPHYSICS_EXPORT agxData::Array< agx::Physics::ContactPointPtr > & points()
The list of contact points.
AGXPHYSICS_EXPORT agx::Physics::GeometryPtr & geometry2()
AGXPHYSICS_EXPORT agx::Physics::BroadPhasePairPtr & broadPhasePair()
AGXPHYSICS_EXPORT agx::Bool & immediately()
AGXPHYSICS_EXPORT agx::Physics::GeometryPtr & geometry1()
AGXPHYSICS_EXPORT agxCollide::Geometry *& model()
Pointer to a entity instance of type Physics.Geometry.Shape.
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
agx::Vec3 getAngularVelocity() const
Angular velocity in world coordinate frame.
Definition RigidBody.h:1196
agx::Vec3 getVelocity() const
Velocity of center of mass frame origin, in world coordinate frame.
Definition RigidBody.h:1191
agx::Vec3 getCmPosition() const
Definition RigidBody.h:1206
void set(T x, T y, T z)
#define agxAssert(expr)
Definition debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define AGX_STATIC_ASSERT(X)
Definition macros.h:23
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
#define AGX_FORCE_INLINE
Definition macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
void copyContactPoint(const T1 &from, T2 &to)
Copy between the different kinds of contact points.
Definition Contacts.h:236
agxData::Array< ContactPoint > ContactPointVector
Definition Contacts.h:265
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition Integer.h:32
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition agx/Vec3.h:36
bool Bool
Definition Integer.h:40
double Real
Definition Real.h:42
uint8_t UInt8
Definition Integer.h:30
Vec3T< Real32 > Vec3f
Definition agx/Vec3.h:39