AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ShapeCollider.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#ifndef AGXCOLLIDE_SHAPECOLLIDER_H
18#define AGXCOLLIDE_SHAPECOLLIDER_H
19
20#include <agx/macros.h>
21
23
24#define SHAPE_COLLIDER_VELOCITIES 0
25
26#include <agx/agx.h>
29
30#include <agx/AffineMatrix4x4.h>
31#include <agx/SymmetricPair.h>
32
34#include <agxCollide/Shape.h>
35
36#include <agx/Thread.h>
37#include <agxData/LocalVector.h>
39
40#ifdef _MSC_VER
41# pragma warning(push)
42# pragma warning( disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
43#endif
44
45
46namespace agxCollide
47{
51 class AGXPHYSICS_EXPORT ShapeCollider
52 {
53 public:
55
56 public:
57 virtual ~ShapeCollider() {}
58
59 typedef agx::SymmetricPair<agx::UInt8> TypePair;
60 TypePair getDescriptor() const;
61
62
63 void calculateContacts(
64 agx::Physics::Geometry::ShapeInstance shape1, agx::Physics::Geometry::ShapeInstance shape2,
65 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
66 const agx::Vec3& linearVelocity1, const agx::Vec3& linearVelocity2,
67 const agx::Vec3& angularVelocity1, const agx::Vec3& angularVelocity2,
68 bool earlyOut, LocalContactPointVector& result);
69
70 void calculateContacts(
71 agx::Physics::Geometry::ShapeInstance shape1, agx::Physics::Geometry::ShapeInstance shape2,
72 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
73 bool earlyOut, LocalContactPointVector& result);
74
75
76 /* Convenience wrappers */
77 void calculateContacts(agxCollide::Shape *shape1, agxCollide::Shape *shape2,
78 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
79 const agx::Vec3& linearVelocity1, const agx::Vec3& linearVelocity2,
80 const agx::Vec3& angularVelocity1, const agx::Vec3& angularVelocity2,
81 LocalContactPointVector& result);
82
83 void calculateContacts(agxCollide::Shape *shape1, agxCollide::Shape *shape2,
84 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
85 LocalContactPointVector& result);
86
87 static void addContactPoint(LocalContactPointVector& result, const agx::Vec3& point,
88 const agx::Vec3& normal, agx::Real depth);
89
92 static void addEarlyOutMarkerPoint(LocalContactPointVector& result);
93
94
95 protected:
96 ShapeCollider(agx::UInt8 shapeType1, agx::UInt8 shapeType2) : m_descriptor(shapeType1, shapeType2) {}
97
98 virtual void _calculateContacts(
99 agx::Physics::Geometry::ShapeInstance shape1, agx::Physics::Geometry::ShapeInstance shape2,
100 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
101 const agx::Vec3& linearVelocity1, const agx::Vec3& linearVelocity2,
102 const agx::Vec3& angularVelocity1, const agx::Vec3& angularVelocity2,
103 bool earlyOut, LocalContactPointVector& result) = 0;
104
105
106 private:
107 TypePair m_descriptor;
108 };
109
110 class AGXPHYSICS_EXPORT ShapeColliderPlugin
111 {
112 public:
113 virtual agxCollide::ShapeCollider* create() = 0;
114 virtual void destroy(agxCollide::ShapeCollider *collider) = 0;
115 };
116
117 template <typename T>
118 class ShapeColliderPluginT : public ShapeColliderPlugin
119 {
120 public:
121 ShapeColliderPluginT()
122 {
123 PluginManager::instance()->registerPlugin(this);
124 }
125
126 virtual agxCollide::ShapeCollider* create() override
127 {
128 return new T();
129 }
130
131 virtual void destroy(agxCollide::ShapeCollider *collider) override
132 {
133 agxVerify(dynamic_cast<T *>(collider));
134 delete collider;
135 }
136
137 private:
138 };
139
140 #define AGX_SHAPE_COLLIDER(T) static agxCollide::ShapeColliderPluginT<T> s_colliderPlugin;
141
142
143
144 /* Implementation */
145 AGX_FORCE_INLINE ShapeCollider::TypePair ShapeCollider::getDescriptor() const
146 {
147 return m_descriptor;
148 }
149
150
151
152 AGX_FORCE_INLINE void ShapeCollider::calculateContacts(
153 agx::Physics::Geometry::ShapeInstance shape1, agx::Physics::Geometry::ShapeInstance shape2,
154 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
155 bool earlyOut, LocalContactPointVector& result)
156 {
157 agx::Vec3 foo;
158 this->calculateContacts(shape1, shape2, transform1, transform2, foo, foo, foo, foo, earlyOut, result);
159 }
160
161
162
164
165
166 AGX_FORCE_INLINE void ShapeCollider::calculateContacts(
167 agxCollide::Shape* shape1, agxCollide::Shape* shape2,
168 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
170 {
171 this->calculateContacts(shape1->getEntity(), shape2->getEntity(), transform1, transform2, false, result);
172 }
173
174
175
176 AGX_FORCE_INLINE void ShapeCollider::calculateContacts(
177 agxCollide::Shape* shape1, agxCollide::Shape* shape2,
178 const agx::AffineMatrix4x4& transform1, const agx::AffineMatrix4x4& transform2,
179 const agx::Vec3& linearVelocity1, const agx::Vec3& linearVelocity2,
180 const agx::Vec3& angularVelocity1, const agx::Vec3& angularVelocity2,
182 {
183 this->calculateContacts(
184 shape1->getEntity(), shape2->getEntity(), transform1, transform2, linearVelocity1, linearVelocity2,
185 angularVelocity1, angularVelocity2, false, result);
186 }
187
188
189
190 AGX_FORCE_INLINE void ShapeCollider::addContactPoint(
191 LocalContactPointVector& result, const agx::Vec3& point,
192 const agx::Vec3& normal, agx::Real depth)
193 {
194 agxAssert(agx::equivalent(normal.length2(), agx::Real(1), agx::Real(1.0e-4)));
195 agxAssert(depth >= agx::Real(0) && depth != agx::Infinity);
196 result.push_back(LocalContactPoint(point, (agx::Vec3f) normal, depth ) );
197 }
198
199
200
201 inline void ShapeCollider::addEarlyOutMarkerPoint(LocalContactPointVector& result)
202 {
203 result.push_back(LocalContactPoint(agx::Vec3(agx::Real(0.0)), agx::Vec3(agx::Real(0.0)), agx::Real(0.0)));
204 result.back().enabled() = false;
205 }
206}
207
208#ifdef _MSC_VER
209# pragma warning(pop)
210#endif
211
213#endif
214
#define AGXPHYSICS_EXPORT
Base class for a shape.
Definition Shape.h:54
agx::Physics::Geometry::ShapePtr getEntity() const
Definition Shape.h:396
Only use as member allocated variable.
Definition Value.h:285
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Real length2() const
Length squared of the vector = vec .
#define agxVerify(expr)
Definition debug.h:131
#define agxAssert(expr)
Definition debug.h:143
#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::VectorPOD< LocalContactPoint > LocalContactPointVector
AGXCORE_EXPORT const Real Infinity
double Real
Definition Real.h:42
uint8_t UInt8
Definition Integer.h:30
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)