本文整理汇总了C++中Simplex::ContainsOrigin方法的典型用法代码示例。如果您正苦于以下问题:C++ Simplex::ContainsOrigin方法的具体用法?C++ Simplex::ContainsOrigin怎么用?C++ Simplex::ContainsOrigin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simplex
的用法示例。
在下文中一共展示了Simplex::ContainsOrigin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsColliding
bool IsColliding(const Collider &collider_a, const Collider &collider_b, Contacts &contacts)
{
// quick check with the individual collider AABBs for a quick out
if (!collider_a.aabb.Overlap(collider_b.aabb))
return false;
// our simplex for this collision test
Simplex simplex;
// Set initial search direction to the difference of centers
Vector2 d = Vector2(1, -1);//Vector2(collider_b.root_trans.PositionWC() - collider_a.root_trans.PositionWC());
// get the first minkowski difference point
simplex.Add(Support(collider_a, collider_b, d));
// negate the support point, giving us a vector in the direction of the origin
d = -simplex.A().vert;
int count = 0;
// start looping
while (count < 100)
{
// add a new point to the simplex because we haven't terminated yet
simplex.Add(Support(collider_a, collider_b, d));
// see if the simplex is on the correct side of the origin
if (Vector2::OppositeDirection(simplex.A().vert, d))
{
// if the point added last was not past the origin in the direction of d
// then the Minkowski Sum cannot possibly contain the origin since
// the last point added is on the edge of the Minkowski Difference
return false;
}
else
{
// oterwise we need to determine if the origin is in the current simplex
// this function will set the next search direction for us if it fails.
if (simplex.ContainsOrigin(d))
{
// if it does then we know there is a collision
// handle the collision with the EPA algorithm
EPAHandle(collider_a, collider_b, simplex, contacts);
// find the incident edge.
if (contacts.size())
{
auto &it = contacts.back();
it.info.e.edge_a = collider_a.FindIndex(it.normal);
it.info.e.edge_b = collider_b.FindIndex(-it.normal);
}
return true;
}
}
++count;
}
return false;
}