28 template <
typename Real>
42 template <
typename Real>
68 template <
typename Real>
84 Real absA0dA1[2][2], rSum;
89 rSum = E0[0] + E1[0] * absA0dA1[0][0] + E1[1] * absA0dA1[0][1];
92 result.intersect =
false;
93 result.separating = 0;
100 rSum = E0[1] + E1[0] * absA0dA1[1][0] + E1[1] * absA0dA1[1][1];
103 result.intersect =
false;
104 result.separating = 1;
109 rSum = E1[0] + E0[0] * absA0dA1[0][0] + E0[1] * absA0dA1[1][0];
112 result.intersect =
false;
113 result.separating = 2;
118 rSum = E1[1] + E0[0] * absA0dA1[0][1] + E0[1] * absA0dA1[1][1];
121 result.intersect =
false;
122 result.separating = 3;
126 result.intersect =
true;
130 template <
typename Real>
136 result.intersect =
true;
140 std::array<Vector2<Real>, 4> vertex;
141 box0.GetVertices(vertex);
142 result.polygon.push_back(vertex[0]);
143 result.polygon.push_back(vertex[1]);
144 result.polygon.push_back(vertex[3]);
145 result.polygon.push_back(vertex[2]);
150 box1.GetVertices(vertex);
151 std::array<Vector2<Real>, 4> normal =
153 box1.axis[1], -box1.axis[0], box1.axis[0], -box1.axis[1]
156 for (
int i = 0; i < 4; ++i)
158 if (Outside(vertex[i], normal[i], result.polygon))
161 result.intersect =
false;
162 result.polygon.clear();
170 template <
typename Real>
177 int const numVertices =
static_cast<int>(polygon.size());
178 std::vector<Real>
distance(numVertices);
179 int positive = 0, negative = 0, positiveIndex = -1;
180 for (
int i = 0; i < numVertices; ++i)
182 distance[i] =
Dot(normal, polygon[i] - origin);
183 if (distance[i] > (Real)0)
186 if (positiveIndex == -1)
191 else if (distance[i] < (Real)0)
211 std::vector<Vector2<Real>> clipPolygon;
216 if (positiveIndex > 0)
219 curr = positiveIndex;
221 t = distance[curr] / (distance[curr] - distance[prev]);
222 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
223 clipPolygon.push_back(vertex);
226 while (curr < numVertices && distance[curr] > (Real)0)
228 clipPolygon.push_back(polygon[curr++]);
232 if (curr < numVertices)
239 prev = numVertices - 1;
241 t = distance[curr] / (distance[curr] - distance[prev]);
242 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
243 clipPolygon.push_back(vertex);
249 while (curr < numVertices && distance[curr] > (Real)0)
251 clipPolygon.push_back(polygon[curr++]);
256 t = distance[curr] / (distance[curr] - distance[prev]);
257 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
258 clipPolygon.push_back(vertex);
261 while (curr < numVertices && distance[curr] <= (Real)0)
267 if (curr < numVertices)
270 t = distance[curr] / (distance[curr] - distance[prev]);
271 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
272 clipPolygon.push_back(vertex);
275 while (curr < numVertices && distance[curr] > (Real)0)
277 clipPolygon.push_back(polygon[curr++]);
283 prev = numVertices - 1;
284 t = distance[curr] / (distance[curr] - distance[prev]);
285 vertex = polygon[curr] + t * (polygon[prev] - polygon[curr]);
286 clipPolygon.push_back(vertex);
290 polygon = clipPolygon;
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
std::vector< Vector2< Real > > polygon
GLsizei GLsizei GLfloat distance
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)