AGX Dynamics  2.35.0.1
Capsule.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 #ifndef AGXCOLLIDE_CAPSULE_H
18 #define AGXCOLLIDE_CAPSULE_H
19 
20 #include <agx/agxPhysics_export.h>
22 #include <agxCollide/Shape.h>
23 #include <agxStream/Serializable.h>
24 
25 namespace agxCollide
26 {
28 
35  {
36  public:
43  Capsule( const agx::Real radius = agx::Real(1), const agx::Real height = agx::Real(1) );
44 
49  void setHeight( const agx::Real height );
50 
55  void setRadius( const agx::Real radius );
56 
62  void set( const agx::Real radius, const agx::Real height );
63 
65  agx::Real getHeight() const;
66 
68  agx::Real getRadius() const;
69 
70  virtual Shape *clone() const override;
71  virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override;
72  virtual agx::Real getVolume() const override;
73  virtual bool hasSupportFunction() const override;
74 
79  virtual agx::Vec3 getSupportPoint(const agx::Vec3& supportDirection) const override;
80  virtual const BoundingAABB& updateBoundingVolume() override;
81  virtual BoundingAABB calculateLocalBound() const override;
82  static BoundingAABB calculateBound(const agx::AffineMatrix4x4& transform, const agx::Real radius, const agx::Real height);
83 
85 
86 
87  agx::Physics::Geometry::CapsulePtr getEntity() const;
90 
91  protected:
92 
94  virtual ~Capsule( void );
95 
97  Capsule(const agx::Real radius, const agx::Real height, Shape::Type type, agx::Physics::Geometry::ShapePtr entity );
98  };
99 
100 
101  /* Implementation */
102  inline agx::Physics::Geometry::CapsulePtr Capsule::getEntity() const
103  {
104  return m_entity;
105  }
106 
108  {
109  return getEntity().height();
110  }
111 
113  {
114  return getEntity().radius();
115  }
116 
118  {
119  const agx::Vec3 p1 = agx::Vec3(0, height * agx::Real(0.5), 0) * transform;
120  const agx::Vec3 p2 = agx::Vec3(0, height * agx::Real(-0.5), 0) * transform;
121 
122  BoundingAABB bound (agx::Vec3::componentMin(p1, p2) - agx::Vec3(radius), agx::Vec3::componentMax(p1, p2) + agx::Vec3(radius));
123  return bound;
124  }
125 
127  {
128  return true;
129  }
130 
131 }
132 
133 #endif
#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
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
Implements a Capsule shape for geometric intersection tests.
Definition: Capsule.h:35
virtual agx::Real getVolume() const override
Return the volume of the shape.
virtual BoundingAABB calculateLocalBound() const override
Calculate the bounding volume in the local coordinate system.
void set(const agx::Real radius, const agx::Real height)
Set the radius and height of the capsule.
Capsule(const agx::Real radius=agx::Real(1), const agx::Real height=agx::Real(1))
Constructor.
static BoundingAABB calculateBound(const agx::AffineMatrix4x4 &transform, const agx::Real radius, const agx::Real height)
Definition: Capsule.h:117
void setHeight(const agx::Real height)
Set the height of the capsule.
void setRadius(const agx::Real radius)
Set the radius of the capsule.
virtual agx::Vec3 getSupportPoint(const agx::Vec3 &supportDirection) const override
Returns the support point on face of the shape.
agx::Real getHeight() const
Definition: Capsule.h:107
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override
Calculate the inertia for the shape given a mass.
virtual Shape * clone() const override
Create a clone.
virtual const BoundingAABB & updateBoundingVolume() override
Calculate the bounding volume based on the current Shape parameters including transformation.
virtual bool hasSupportFunction() const override
Definition: Capsule.h:126
agx::Real getRadius() const
Definition: Capsule.h:112
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Base class for a shape.
Definition: Shape.h:54
Type
Define the type of a Shape.
Definition: Shape.h:58
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:49
static Vec3T componentMax(const Vec3T &v1, const Vec3T &v2)
Creates a new vector where each component is the maximum of this and the other vector.
Definition: Vec3Template.h:391
static Vec3T componentMin(const Vec3T &v1, const Vec3T &v2)
Creates a new vector where each component is the minimum of this and the other vector.
Definition: Vec3Template.h:385
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#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...
AGX_DECLARE_POINTER_TYPES(SpaceListener)
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
double Real
Definition: Real.h:42