AGX Dynamics 2.40.0.0
Loading...
Searching...
No Matches
Geometry.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
20#include <agx/agx.h>
21#include <agx/observer_ptr.h>
23#include <agxCollide/Shape.h>
25#include <agx/Material.h>
26#include <agx/Event.h>
27
29
30#include <agx/Property.h>
31
33#include <agx/RigidBody.h>
34#include <agx/HashSet.h>
35#include <agx/AffineMatrix4x4.h>
36#include <agx/BitArray.h>
37#include <agx/SymmetricPair.h>
41#include <agx/SetVector.h>
42
43
44namespace agx
45{
46 class Frame;
47 class InternalData;
48 class Emitter;
49}
50
51namespace agxCollide
52{
53 class SweepAndPrune;
54 class LocalContactPoint;
55
56}
57
58namespace agxTerrain
59{
60 class Terrain;
61}
62
63namespace agxData
64{
66}
67
69
70
71namespace agxCollide
72{
73 class Space;
74 class ContactPoint;
75
76
82
92 {
93 public:
96
97 public:
98
103 Geometry( const agx::Name& name = "" );
104
105
110 Geometry( Shape* shape );
111
117 Geometry( Shape* shape, const agx::AffineMatrix4x4& localShapeTransform );
118
123 Geometry *clone( bool shallowCopyRenderData=false ) const;
124
128 agx::Int64 getId() const;
129
134 const agx::Name& getName() const;
135
137 void setName( const agx::Name& name );
138
142 agx::RigidBody *getRigidBody();
143
147 const agx::RigidBody *getRigidBody() const;
148
152 void setMaterial( agx::Material *material );
153
157 agx::Material *getMaterial();
158
162 const agx::Material *getMaterial() const;
163
168
175
182
189
196
201 void setEnable( bool flag );
202
209 bool isEnabled() const;
210
216 bool getEnable() const;
217
232 void setSensor(bool flag, bool generateContactData = true);
233
237 bool isSensor() const;
238
243 bool isSensorGeneratingContactData() const;
244
250 void setEnableMassProperties(bool enableMassProperties);
251
255 bool getEnableMassProperties() const;
256
269 void addGroup( agx::UInt32 id, bool forceContactUpdate = false );
270
283 void addGroup( const agx::Name& name, bool forceContactUpdate = false);
284
290 void removeGroup( agx::UInt32 id, bool forceContactUpdate = false );
291
297 void removeGroup( const agx::Name& name, bool forceContactUpdate = false);
298
303 void removeAllGroups(bool forceContactUpdate = false);
304
311 bool hasGroup( agx::UInt32 id ) const;
312
319 bool hasGroup( const agx::Name& name ) const;
320
325 void setGroupSet( agx::Physics::CollisionGroupSetPtr set );
326
330 const agx::Physics::CollisionGroupSetPtr& getGroupSet() const;
331
334 const GroupSet& getGroupIDs() const;
335
339 void setEnableCollisions( const Geometry* otherGeometry, bool flag );
340
347 bool getEnableCollisions( const Geometry* otherGeometry ) const;
348
354 void setEnableCollisions(bool collide);
355
360
361
372 bool canCollide( const Geometry *otherGeometry ) const;
373
374
383 virtual agx::Vec3f calculateSurfaceVelocity( const agxCollide::LocalContactPoint& point, size_t index ) const;
384
389 virtual const BoundingAABB* getBoundingVolume() const;
390
392 agx::PropertyContainer* getPropertyContainer();
393
395 const agx::PropertyContainer* getPropertyContainer() const;
396
398 bool hasPropertyContainer() const;
399
405
409 Space* getSpace();
410
414 const Space* getSpace() const;
415
416
418
419
424
429
434
441 void setSurfaceVelocity( const agx::Vec3f& surfaceVelocity );
442
447 const agx::Vec3f& getSurfaceVelocity() const;
448
449 agx::UInt32 getSweepAndPruneIndex() const;
450
451 // Normally updated automatically
452 virtual void updateBoundingVolume();
453
454 agx::Physics::GeometryPtr getEntity() const;
455
456 // Normally handled automatically
457 virtual void shapeUpdated();
458
463
464 public:
468 agx::Frame *getFrame();
469
473 const agx::Frame *getFrame() const;
474
480 void setTransform( const agx::AffineMatrix4x4& matrix );
481
486
492
497
502 void setLocalPosition( const agx::Vec3& p );
503
511
516 void setRotation( const agx::Quat& q );
517
523
529
534
539 void setLocalRotation( const agx::Quat& q );
540
546
551
556
567
572 void setPosition( const agx::Vec3& p );
573
581
585 agx::AffineMatrix4x4 getTransform() const;
586
590 agx::Vec3 getPosition() const;
591
595 agx::Quat getRotation() const;
596
597
598 public:
599 /* Old interface, use ShapeGroup instead */
600
608 bool add( Shape *shape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4() );
609
614 bool remove( Shape *shape );
615
628 Shape *getShape();
629
641 const Shape *getShape() const;
642
648 bool setShape(Shape *shape);
650
651
656 bool remove( size_t index );
657
661 const ShapeRefVector& getShapes() const;
662
666 bool replace( size_t shapeIndex, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
667 bool replace( Shape *oldShape, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
668
675 bool replaceShapeTransform( size_t shapeIndex, const agx::AffineMatrix4x4& newTransform );
676
683 bool replaceShapeTransform( Shape *shape, const agx::AffineMatrix4x4& newTransform );
684
690 void cloneShapeRenderData(agxCollide::Shape* target, bool shallowCopy) const;
691
692 public:
693
694 protected:
696 virtual ~Geometry();
697
698 private:
699 friend class agx::Emitter;
700 friend class agx::RigidBody;
701 friend class agx::Frame;
702 friend class GeometryGroup;
703 friend class agxCollide::Space;
705 friend class agxCollide::ShapeGroup;
706 friend class agxTerrain::Terrain;
707
708 void propagateTransform();
709 void updateFrameStorage();
710 ShapeGroup *createWrapperGroup();
711
712 void init(const agx::Name& name);
713
714 mutable agx::PropertyContainerRef m_propertyContainer;
715
716 void setBody( agx::RigidBody *body, const agx::AffineMatrix4x4& invBodyTransform );
717 void removeBody();
718
725 bool setSpace( Space* space, agx::Int64 id );
726
727 void setSweepAndPruneIndex( agx::UInt32 index );
728 void setEntity( agx::Physics::GeometryPtr entity );
729 // void transfer(Space *space);
730 void transfer( agxData::EntityStorage *storage );
731
732 size_t findShapeIndex(Shape *shape);
733
734 void enableCollisionsWithGroup(agx::UInt32 groupId);
735 void disableCollisionsWithGroup(agx::UInt32 groupId);
736
738 friend class agx::InternalData;
742 agx::Referenced* getInternalData() const;
743
747 void setInternalData( agx::Referenced* data );
749
750 private:
751 agx::Int64 m_id;
752 ShapeRef m_shape;
753 agx::Physics::GeometryRef m_entity;
754 agx::RigidBody * m_rigidBody;
755 Space * m_space;
756
757 agx::MaterialRef m_material;
758
759 mutable GeometryHashVector m_disabledCollisionsHash;
760
761 agx::FrameRef m_frame;
762 agx::ref_ptr<agx::Referenced> m_customData;
763 agx::ref_ptr<agx::Referenced> m_internalData;
764 agx::observer_ptr<agx::RigidBody> m_originalBody;
765
766 // Backward compatibility
767 ShapeRefVector m_singleShapeVector;
768
769 static ShapeRefVector s_defaultChildVector;
770 static GroupSet s_emptySet;
771 };
772
773
774 /* Implementation */
775
776 AGX_FORCE_INLINE Shape *Geometry::getShape()
777 {
778 return m_shape;
779 }
780
781 AGX_FORCE_INLINE const Shape *Geometry::getShape() const
782 {
783 return const_cast<Geometry *>( this )->getShape();
784 }
785
786 inline agx::Physics::GeometryPtr Geometry::getEntity() const
787 {
788 return m_entity;
789 }
790 AGX_FORCE_INLINE agx::RigidBody *Geometry::getRigidBody()
791 {
792 return m_rigidBody;
793 }
794
795 AGX_FORCE_INLINE const agx::RigidBody *Geometry::getRigidBody() const
796 {
797 return m_rigidBody;
798 }
799
800 AGX_FORCE_INLINE agx::Int64 Geometry::getId() const
801 {
802 return m_id;
803 }
804
805 AGX_FORCE_INLINE bool Geometry::isEnabled() const
806 {
807 return m_entity.state().enabled();
808 }
809
810 AGX_FORCE_INLINE bool Geometry::isSensor() const
811 {
812 return m_entity.state().sensor();
813 }
814
815 AGX_FORCE_INLINE bool Geometry::getEnableMassProperties() const
816 {
817 return m_entity.state().enableMassProperties();
818 }
819
820
821 inline bool Geometry::isSensorGeneratingContactData() const
822 {
823 return !m_entity.state().booleanSensor();
824 }
825
826 AGX_FORCE_INLINE agx::UInt32 Geometry::getSweepAndPruneIndex() const
827 {
828 return m_entity.sweepAndPruneIndex();
829 }
830
831 AGX_FORCE_INLINE bool Geometry::hasGroup( agx::UInt32 id ) const
832 {
833 return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), id);
834 }
835
836 AGX_FORCE_INLINE bool Geometry::hasGroup( const agx::Name& name ) const
837 {
838 return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), name);
839 }
840
841 AGX_FORCE_INLINE const agx::Physics::CollisionGroupSetPtr& Geometry::getGroupSet() const
842 {
843 return m_entity.collisionGroupSet();
844 }
845
846 AGX_FORCE_INLINE void Geometry::setGroupSet( agx::Physics::CollisionGroupSetPtr set )
847 {
848 m_entity.collisionGroupSet() = set;
849 }
850
851 AGX_FORCE_INLINE const agx::Material *Geometry::getMaterial() const
852 {
853 return m_material;
854 }
855
856 AGX_FORCE_INLINE agx::Material *Geometry::getMaterial()
857 {
858 return m_material;
859 }
860
861 AGX_FORCE_INLINE void Geometry::setSurfaceVelocity( const agx::Vec3f& surfaceVelocity )
862 {
863 m_entity.surfaceVelocity() = surfaceVelocity;
864 }
865
866 AGX_FORCE_INLINE const agx::Vec3f& Geometry::getSurfaceVelocity( ) const
867 {
868 return m_entity.surfaceVelocity();
869 }
870
871 AGX_FORCE_INLINE bool Geometry::getEnable() const
872 {
873 return m_entity.state().enabled();
874 }
875
876 AGX_FORCE_INLINE Space* Geometry::getSpace()
877 {
878 return m_space;
879 }
880 AGX_FORCE_INLINE const Space* Geometry::getSpace() const
881 {
882 return m_space;
883 }
884
885 AGX_FORCE_INLINE agx::Frame* Geometry::getFrame()
886 {
887 return m_frame.get();
888 }
889
890 AGX_FORCE_INLINE const agx::Frame* Geometry::getFrame() const
891 {
892 return m_frame.get();
893 }
894
895 AGX_FORCE_INLINE const BoundingAABB* Geometry::getBoundingVolume() const
896 {
897 return &m_entity.boundingAABB();
898 }
899
900
901 AGX_FORCE_INLINE agx::PropertyContainer* Geometry::getPropertyContainer()
902 {
903 if ( !m_propertyContainer )
904 m_propertyContainer = new agx::PropertyContainer;
905 return m_propertyContainer;
906 }
907
908 AGX_FORCE_INLINE bool Geometry::hasPropertyContainer() const
909 {
910 return ( m_propertyContainer.isValid() );
911 }
912
913 AGX_FORCE_INLINE const agx::PropertyContainer* Geometry::getPropertyContainer() const
914 {
915 if ( !m_propertyContainer )
916 m_propertyContainer = new agx::PropertyContainer;
917
918 return m_propertyContainer;
919 }
920
921 AGX_FORCE_INLINE agx::Vec3f Geometry::calculateSurfaceVelocity( const agxCollide::LocalContactPoint& /* point */, size_t /* index */) const
922 {
923 return getSurfaceVelocity();
924 }
925
926 AGX_FORCE_INLINE agx::AffineMatrix4x4 Geometry::getTransform() const
927 {
928 if (m_rigidBody)
929 return m_entity.transform();
930 else
931 return m_frame->getMatrix();
932
933 }
934
935 AGX_FORCE_INLINE agx::Vec3 Geometry::getPosition() const
936 {
937 if (m_rigidBody)
938 return m_entity.transform().getTranslate();
939 else
940 return m_frame->getTranslate();
941 }
942
943 AGX_FORCE_INLINE agx::Quat Geometry::getRotation() const
944 {
945 if (m_rigidBody)
946 return m_entity.transform().getRotate();
947 return m_frame->getRotate();
948 }
949
950 AGX_FORCE_INLINE void Geometry::updateFrameStorage()
951 {
953 }
954
955 inline agx::Referenced* Geometry::getInternalData() const
956 {
957 return m_internalData;
958 }
959} // namespace agxCollide
#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:208
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
ShapeChangeEvent shapeChangeEvent
Definition: Geometry.h:95
agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const
void removeGroup(agx::UInt32 id, bool forceContactUpdate=false)
Remove a collision group id from the vector of group ids.
void setLocalPosition(agx::Real x, agx::Real y, agx::Real z)
Set the position of the geometry relative to its frame's parent frame.
Geometry(Shape *shape)
Constructor.
void setLocalTransform(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this geometry, ignoring any eventual parent transformation...
const GroupSet & getGroupIDs() const
const agx::Frame * getParentFrame() const
const agx::Name & getName() const
Get the name.
void setEnable(bool flag)
Enable/disable collision testing for geometry.
void setEnableCollisions(const Geometry *otherGeometry, bool flag)
Specify whether otherGeometry is allowed to collide with this geometry.
Geometry * clone(bool shallowCopyRenderData=false) const
This method will make a deep copy of the geometry, excluding membership in any RigidBody.
void setRotation(const agx::EulerAngles &e)
Set the rotation of the geometry relative to world frame.
agx::Event1< Geometry * > ShapeChangeEvent
Definition: Geometry.h:94
void setLocalRotation(const agx::EulerAngles &e)
Set the rotation of the geometry relative to its frame's parent frame.
void setEnableCollisions(bool collide)
Should this geometry collide with any other geometries.
agx::Quat getLocalRotation() const
void setCustomData(agx::Referenced *data)
Store a ref_ptr to a user custom data class, which must be inherited from Referenced.
void setLocalPosition(const agx::Vec3 &p)
Set the position of the geometry relative to its frame's parent frame.
void setTransform(const agx::AffineMatrix4x4 &matrix)
Set the transform of the geometry.
void setName(const agx::Name &name)
Set the name of this Geometry.
void setMaterial(agx::Material *material)
Set the material of the geometry.
void removeAllGroups(bool forceContactUpdate=false)
Remove all collision group ids.
Geometry(const agx::Name &name="")
Constructor.
void setEnableMassProperties(bool enableMassProperties)
If set to true, this geometry will be included in mass property computation when part of a rigid body...
void setPosition(agx::Real x, agx::Real y, agx::Real z)
Set the position of the frame in world coordinates.
bool setParentFrame(agx::Frame *frame)
Set the parent frame of this geometry's frame.
void setSensor(bool flag, bool generateContactData=true)
Sets if the geometry should be a sensor.
agx::Vec3 getLocalPosition() const
CollisionGroupManager::GroupIdHash GroupSet
Deprecated: Only for backward compatibility.
Definition: Geometry.h:333
agx::Vec3 calculateCenterOfMassOffset() const
agx::Referenced * getCustomData()
bool getEnableCollisions() const
void setRotation(const agx::OrthoMatrix3x3 &m)
Set the rotation of the geometry relative to world frame.
void removeMaterial()
Remove the material from the geometry.
virtual void updateBoundingVolume()
agx::Real calculateMass() const
agxCollide::GroupIdCollection findGroupIdCollection() const
void addGroup(agx::UInt32 id, bool forceContactUpdate=false)
Add the specified id to a vector of group id, this will make a geometry part of the group id.
void setPosition(const agx::Vec3 &p)
Set the position of the frame in world coordinates.
agx::Real calculateVolume() const
bool canCollide(const Geometry *otherGeometry) const
void removeGroup(const agx::Name &name, bool forceContactUpdate=false)
Remove a named collision group from the vector of named group ids.
Geometry(Shape *shape, const agx::AffineMatrix4x4 &localShapeTransform)
Constructor.
const agx::Referenced * getCustomData() const
bool getEnableCollisions(const Geometry *otherGeometry) const
This method is only based on what is set using setEnableCollisions().
agx::Frame * getParentFrame()
void addGroup(const agx::Name &name, bool forceContactUpdate=false)
Add the specified name to a vector of named group id, this will make a geometry part of the group nam...
bool remove(Shape *shape)
Remove a shape from the geometry.
void setRotation(const agx::Quat &q)
Set the rotation of the geometry relative to world frame.
const agx::AffineMatrix4x4 & getLocalTransform() const
virtual void shapeUpdated()
void setPropertyContainer(agx::PropertyContainer *container)
Give this a new PropertyContainer.
void setLocalRotation(const agx::Quat &q)
Set the rotation of the geometry relative to its frame's parent frame.
bool add(Shape *shape, const agx::AffineMatrix4x4 &localTransform=agx::AffineMatrix4x4())
Add a shape to the geometry.
Collection of geometry group names and id's.
Base class for a shape.
Definition: Shape.h:59
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:86
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:88
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:70
An event with one argument.
Definition: Event.h:103
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:376
Representation of a name string.
Definition: Name.h:33
Specialized types of matrices for holding orthogonal transformation matrices.
Pointer to a entity instance of type Physics.CollisionGroupSet.
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * transformAttribute
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * localTransformAttribute
Pointer to a entity instance of type Physics.Geometry.
Class that is a container of named properties.
Definition: Property.h:129
void getRotate(T &angle, T &x, T &y, T &z) const
Get the angle and vector components represented by the quaternion.
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:52
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:49
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:32
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:65
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
int64_t Int64
Definition: Integer.h:38
double Real
Definition: Real.h:42