b2_distance.h
Go to the documentation of this file.
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #ifndef B2_DISTANCE_H
24 #define B2_DISTANCE_H
25 
26 #include "b2_api.h"
27 #include "b2_math.h"
28 
29 class b2Shape;
30 
34 {
35  b2DistanceProxy() : m_vertices(nullptr), m_count(0), m_radius(0.0f) {}
36 
39  void Set(const b2Shape* shape, int32 index);
40 
43  void Set(const b2Vec2* vertices, int32 count, float radius);
44 
46  int32 GetSupport(const b2Vec2& d) const;
47 
49  const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
50 
52  int32 GetVertexCount() const;
53 
55  const b2Vec2& GetVertex(int32 index) const;
56 
57  b2Vec2 m_buffer[2];
60  float m_radius;
61 };
62 
66 {
67  float metric;
69  uint8 indexA[3];
70  uint8 indexB[3];
71 };
72 
77 {
82  bool useRadii;
83 };
84 
87 {
90  float distance;
92 };
93 
98  b2SimplexCache* cache,
99  const b2DistanceInput* input);
100 
103 {
109 };
110 
113 {
116  float lambda;
118 };
119 
122 B2_API bool b2ShapeCast(b2ShapeCastOutput* output, const b2ShapeCastInput* input);
123 
125 
127 {
128  return m_count;
129 }
130 
131 inline const b2Vec2& b2DistanceProxy::GetVertex(int32 index) const
132 {
133  b2Assert(0 <= index && index < m_count);
134  return m_vertices[index];
135 }
136 
138 {
139  int32 bestIndex = 0;
140  float bestValue = b2Dot(m_vertices[0], d);
141  for (int32 i = 1; i < m_count; ++i)
142  {
143  float value = b2Dot(m_vertices[i], d);
144  if (value > bestValue)
145  {
146  bestIndex = i;
147  bestValue = value;
148  }
149  }
150 
151  return bestIndex;
152 }
153 
154 inline const b2Vec2& b2DistanceProxy::GetSupportVertex(const b2Vec2& d) const
155 {
156  int32 bestIndex = 0;
157  float bestValue = b2Dot(m_vertices[0], d);
158  for (int32 i = 1; i < m_count; ++i)
159  {
160  float value = b2Dot(m_vertices[i], d);
161  if (value > bestValue)
162  {
163  bestIndex = i;
164  bestValue = value;
165  }
166  }
167 
168  return m_vertices[bestIndex];
169 }
170 
171 #endif
d
b2Transform transformB
Definition: b2_distance.h:107
b2DistanceProxy proxyA
Definition: b2_distance.h:104
float b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
Definition: b2_math.h:395
f
unsigned short uint16
Definition: b2_types.h:30
#define B2_API
Definition: b2_api.h:49
b2DistanceProxy proxyA
Definition: b2_distance.h:78
Input parameters for b2ShapeCast.
Definition: b2_distance.h:102
int32 iterations
number of GJK iterations used
Definition: b2_distance.h:91
A 2D column vector.
Definition: b2_math.h:41
b2Vec2 pointB
closest point on shapeB
Definition: b2_distance.h:89
B2_API bool b2ShapeCast(b2ShapeCastOutput *output, const b2ShapeCastInput *input)
signed int int32
Definition: b2_types.h:28
b2Vec2 pointA
closest point on shapeA
Definition: b2_distance.h:88
int32 GetSupport(const b2Vec2 &d) const
Get the supporting vertex index in the given direction.
Definition: b2_distance.h:137
int32 GetVertexCount() const
Get the vertex count.
Definition: b2_distance.h:126
b2Transform transformA
Definition: b2_distance.h:80
b2Transform transformB
Definition: b2_distance.h:81
b2Transform transformA
Definition: b2_distance.h:106
Output results for b2ShapeCast.
Definition: b2_distance.h:112
const b2Vec2 * m_vertices
Definition: b2_distance.h:58
B2_API void b2Distance(b2DistanceOutput *output, b2SimplexCache *cache, const b2DistanceInput *input)
unsigned char uint8
Definition: b2_types.h:29
Output for b2Distance.
Definition: b2_distance.h:86
const b2Vec2 & GetSupportVertex(const b2Vec2 &d) const
Get the supporting vertex in the given direction.
Definition: b2_distance.h:154
const b2Vec2 & GetVertex(int32 index) const
Get a vertex by index. Used by b2Distance.
Definition: b2_distance.h:131
#define b2Assert(A)
Definition: b2_common.h:37
b2DistanceProxy proxyB
Definition: b2_distance.h:105
b2DistanceProxy proxyB
Definition: b2_distance.h:79
float metric
length or area
Definition: b2_distance.h:67


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:19