本文整理汇总了C++中Simplex::isPointInSimplex方法的典型用法代码示例。如果您正苦于以下问题:C++ Simplex::isPointInSimplex方法的具体用法?C++ Simplex::isPointInSimplex怎么用?C++ Simplex::isPointInSimplex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simplex
的用法示例。
在下文中一共展示了Simplex::isPointInSimplex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: algorithm
/**
* @param includeMargin Indicate whether algorithm operates on objects with margin
*/
template<class T> std::unique_ptr<GJKResult<T>> GJKAlgorithm<T>::processGJK(const CollisionConvexObject3D &convexObject1,
const CollisionConvexObject3D &convexObject2, bool includeMargin) const
{ //GJK algorithm (see http://mollyrocket.com/849)
//get point which belongs to the outline of the shape (Minkowski difference)
Vector3<T> initialDirection = Vector3<T>(1.0, 0.0, 0.0);
Point3<T> initialSupportPointA = convexObject1.getSupportPoint(initialDirection, includeMargin);
Point3<T> initialSupportPointB = convexObject2.getSupportPoint(-initialDirection, includeMargin);
Point3<T> initialPoint = initialSupportPointA - initialSupportPointB;
Vector3<T> direction = initialPoint.vector(Point3<T>(0.0, 0.0, 0.0));
Point3<T> closestPointOnSimplex = initialPoint;
Simplex<T> simplex;
simplex.addPoint(initialSupportPointA, initialSupportPointB);
simplex.setBarycentric(0, 1.0);
simplex.setClosestPointToOrigin(closestPointOnSimplex);
T minimumToleranceMultiplicator = (T)1.0;
for(unsigned int iterationNumber=0; iterationNumber<maxIteration; ++iterationNumber)
{
Point3<T> supportPointA = convexObject1.getSupportPoint(direction, includeMargin);
Point3<T> supportPointB = convexObject2.getSupportPoint(-direction, includeMargin);
Point3<T> newPoint = supportPointA - supportPointB;
const Vector3<T> &vClosestPoint = -direction; //vector from origin to closest point of simplex
T closestPointSquareDistance = vClosestPoint.dotProduct(vClosestPoint);
T closestPointDotNewPoint = vClosestPoint.dotProduct(newPoint.toVector());
//check termination conditions: new point is not more extreme that existing ones OR new point already exist in simplex
T distanceTolerance = std::max(minimumTerminationTolerance*minimumToleranceMultiplicator, relativeTerminationTolerance*closestPointSquareDistance);
if((closestPointSquareDistance-closestPointDotNewPoint) <= distanceTolerance || simplex.isPointInSimplex(newPoint))
{
if(closestPointDotNewPoint <= 0.0)
{ //collision detected
return std::unique_ptr<GJKResultCollide<T>>(new GJKResultCollide<T>(simplex));
}else
{
return std::unique_ptr<GJKResultNoCollide<T>>(new GJKResultNoCollide<T>(std::sqrt(closestPointSquareDistance), simplex));
}
}
simplex.addPoint(supportPointA, supportPointB);
updateSimplex(simplex);
closestPointOnSimplex = simplex.getClosestPointToOrigin();
direction = closestPointOnSimplex.vector(Point3<T>(0.0, 0.0, 0.0));
minimumToleranceMultiplicator += percentageIncreaseOfMinimumTolerance;
}
#ifdef _DEBUG
logMaximumIterationReach();
#endif
return std::unique_ptr<GJKResultInvalid<T>>(new GJKResultInvalid<T>());
}