AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ShapeContactEdge.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
20
21#define DEBUG_RENDER_SHAPE_CONTACTS 0
22
23#include <agx/Referenced.h>
24#include <agx/Vec3.h>
25#include <agxWire/Node.h>
26#include <agxCollide/Shape.h>
27
29
30namespace agxCollide
31{
32 class GeometryContactPtr;
33 class Geometry;
34}
35
36namespace agxWire
37{
38 class ShapeContactColliderUtils;
39
40 struct ShapeCurvature
41 {
42 ShapeCurvature()
43 {
44
45 }
46 ShapeCurvature(agx::Vec3 n, agx::Vec3 prev, agx::Vec3 next)
47 : normal(n), prevNormal(prev), nextNormal(next)
48 {
49 }
50
51 ShapeCurvature& operator=(const ShapeCurvature& rhs)
52 {
53 this->normal = rhs.normal;
54 this->prevNormal = rhs.prevNormal;
55 this->nextNormal = rhs.nextNormal;
56 return *this;
57 }
58
59 agx::Bool isFlat() const
60 {
61 return agx::equivalent(prevNormal*nextNormal, agx::Real(1));
62 }
63
64 agx::Vec3 calculateCurvatureOrthogonalNormal() const
65 {
66 agx::Vec3 orthoVector = prevNormal ^ nextNormal;
67 orthoVector.normalize();
68 return orthoVector;
69 }
70
71 void normalize()
72 {
73 normal.normalize();
74 prevNormal.normalize();
75 nextNormal.normalize();
76 }
77
78 void setNormal(agx::Vec3 n)
79 {
80 normal = n;
81 }
82
83 agx::Real getAngle() const
84 {
85 agx::Real angle = std::acos(agx::clamp(nextNormal *prevNormal, agx::Real(-1), agx::Real(1)));
86 return angle;
87 }
88
89 agx::Vec3 calculateMeanCurvature() const
90 {
91 agx::Vec3 totDir = prevNormal + nextNormal;
92 totDir.normalize();
93 return totDir;
94 }
95 agx::Vec3 normal;
96 agx::Vec3 prevNormal;
97 agx::Vec3 nextNormal;
98 };
99
100 class AGXPHYSICS_EXPORT ShapeContactEdge
101 {
102 public:
103
104 enum ClampDirection
105 {
106 NOT_CLAMPED = 0,
107 FORWARD = 1,
108 BACKWARD = 2,
109 BOTH = 3
110 };
111
112 ShapeContactEdge();
113
114 ShapeContactEdge& operator=(const ShapeContactEdge& rhs)
115 {
116 this->m_shape = rhs.m_shape;
117 this->m_edgeNormal = rhs.m_edgeNormal;
118 this->m_edgeStart = rhs.m_edgeStart;
119 this->m_edgeEnd = rhs.m_edgeEnd;
120 this->m_localShapeSurfaceProjectedPosition = rhs.m_localShapeSurfaceProjectedPosition;
121 this->m_previousLocalShapePosition = rhs.m_previousLocalShapePosition;
122 this->m_worldVectorFromLastProjection = rhs.m_worldVectorFromLastProjection;
123 this->getLocalCurvature() = rhs.m_localCurvature;
124 return *this;
125 }
126
127 static agx::Vec3 calculateEdgeDir(const ShapeCurvature& worldCurvature, const agx::Vec3& posPrev, const agx::Vec3& pos, const agx::Vec3& posNext);
128
129 static agx::Bool findLocalCurvature(
130 const ShapeContactColliderUtils* colliderUtils, const agx::Vec3& normal, const agx::Vec3& wpOnSurface,
131 const agx::Vec3& wp, const agx::Vec3& wpPrev, const agx::Vec3& wpNext,
132 const agx::Real& acceptedWireOverlap, const agxCollide::Shape* shape, ShapeCurvature& worldCurvature);
133
134 static agx::Vec3 transformPointToShape(const agxCollide::Shape* shape, const agx::Vec3& worldPoint);
135 static agx::Vec3 transformVectorToShape(const agxCollide::Shape* shape, const agx::Vec3& worldVector);
136 static agx::Vec3 transformPointToWorld(const agxCollide::Shape* shape, const agx::Vec3& shapePoint);
137 static agx::Vec3 transformVectorToWorld(const agxCollide::Shape* shape, const agx::Vec3& shapeVector);
138
139 void initialize(agxCollide::Shape* shape, const agx::Vec3& worldNormal, const agx::Vec3& surfacePos);
140
141 agx::Real getAngleAroundEdge(const agx::Vec3& wireBack, const agx::Vec3& wireForward) const;
142 agx::Bool findWorldPositionAndEdgeGivenLocalCurvature(const NodeConstIterator nIt, const agx::Real& wireRadius, const agx::Real& wirePrecision, agx::Vec3& newWireWorldPosition, agx::Vec3& newWireWorldEdge) const;
143 agx::Bool updateCurvature(const ShapeContactColliderUtils* colliderUtils,const NodeConstIterator nIt, const agx::Real acceptedWireOverlap);
144 ShapeCurvature transformCurvatureToWorld(const ShapeCurvature& localCurvature) const;
145 ShapeCurvature transformCurvatureToShape(const ShapeCurvature& worldCurvature) const;
146
147 ShapeCurvature getWorldCurvature() const;
148 ShapeCurvature getShapeLocalCurvature() const;
149
150
151 agx::Bool update(const NodeConstIterator nIt, const ShapeContactColliderUtils* cu, const agx::Real& wireRadius, const agx::Real& wirePrecision);
152
153 void addClampShape(agxCollide::Shape* shape);
154 void clearClampShapes();
155 const agxCollide::ShapeObserverVector& getClampShapes() const;
156
157 agx::Vec3 transformPointToShape(const agx::Vec3& worldPoint ) const;
158 agx::Vec3 transformVectorToShape(const agx::Vec3& worldVector) const;
159 agx::Vec3 transformPointToWorld(const agx::Vec3& shapePoint ) const;
160 agx::Vec3 transformVectorToWorld(const agx::Vec3& shapeVector) const;
161
162 void setWorldEdgeNormal(const agx::Vec3& worldEdgeDir);
163 void setShapeEdgeNormal(const agx::Vec3& shapeEdgeDir);
164 agx::Vec3 getShapeEdgeNormal() const;
165 agx::Vec3 getWorldEdgeNormal() const;
166
167
168 void resetEdgeLength(agx::Real edgeHalfLength);
169 agx::Bool isClamped(const agx::Real& edgeDefaultLength) const;
170 ShapeContactEdge::ClampDirection getClampDirection(agx::Real edgeDefaultLength) const;
171
172 void renderDebug(const agx::Vec4& color) const;
173
174 void setShape(agxCollide::Shape* shape);
175 agxCollide::Shape* getShape() const;
176
177 agx::Real getEdgeVelocity(const agx::Vec3& vel) const;
178
179 void setLocalEdgeNormal(agx::Vec3 dir);
180 agx::Vec3 getLocalEdgeNormal() const;
181
182 void setEdgeStart(const agx::Real& lengthToStartAlongEdgeDir);
183 agx::Real getEdgeStart() const;
184
185 void setEdgeEnd(const agx::Real& lengthToEndAlongEdgeDir);
186 agx::Real getEdgeEnd() const;
187
188 void setLocalShapeSurfaceProjectedPosition(agx::Vec3 pos);
189 agx::Vec3 getLocalShapeSurfaceProjectedPosition() const;
190
191 void setPreviousLocalShapePosition(agx::Vec3 pos);
192 agx::Vec3 getPreviousLocalShapePosition() const;
193
194 void setWorldPositionIfThisEdgeIsUsed(agx::Vec3 worldPos);
195 agx::Vec3 getWorldPositionIfThisEdgeIsUsed() const;
196
197 void setWorldVectorFromLastProjection(agx::Vec3 vec);
198 agx::Vec3 getWorldVectorFromLastProjection() const;
199
200 ShapeCurvature& getLocalCurvature();
201 const ShapeCurvature& getLocalCurvature() const;
202 void setLocalCurvature(ShapeCurvature& newLocalCurvature);
203
204 void setWorldNormal(const agx::Vec3& worldNormal);
205 agx::Vec3 getWorldNormal() const;
206
207 void setWorldSurfaceProjectedPosition(const agx::Vec3& worldPos);
208 agx::Vec3 getWorldSurfaceProjectedPosition() const;
209
210 agx::Bool hasValidShape() const;
211
212 private:
214 agx::Vec3 m_edgeNormal;
215 agx::Real m_edgeStart;
216 agx::Real m_edgeEnd;
217
218 agx::Vec3 m_localShapeSurfaceProjectedPosition;
219 agx::Vec3 m_previousLocalShapePosition;
220 agx::Vec3 m_worldVectorFromLastProjection;
221
222 ShapeCurvature m_localCurvature;
223
224 agxCollide::ShapeObserverVector m_shapesUsedToClamp;
225 };
226
227 typedef agx::Vector<ShapeContactEdge> ShapeContactEdgeVector;
228}
229
#define AGXPHYSICS_EXPORT
Base class for a shape.
Definition Shape.h:54
Real normalize()
Normalize the vector so that it has length unity.
A class holding 4 dimensional vectors and providing basic arithmetic.
Templated vector class.
Definition agx/Vector.h:53
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Implements a Wire model with adaptive resolution.
Definition MergedBody.h:40
Real getAngle(const Vec3 &a, const Vec3 &b, const Vec3 &c)
a and b should be orthogonal
bool Bool
Definition Integer.h:40
T1 clamp(T1 v, T2 minimum, T3 maximum)
Definition Math.h:318
double Real
Definition Real.h:42
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)