当前位置: 首页>>代码示例>>C++>>正文


C++ Simplex::isPointInSimplex方法代码示例

本文整理汇总了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>());
	}
开发者ID:ServerGame,项目名称:UrchinEngine,代码行数:61,代码来源:GJKAlgorithm.cpp


注:本文中的Simplex::isPointInSimplex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。