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


C++ Vector2::DotProduct方法代码示例

本文整理汇总了C++中Vector2::DotProduct方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::DotProduct方法的具体用法?C++ Vector2::DotProduct怎么用?C++ Vector2::DotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2的用法示例。


在下文中一共展示了Vector2::DotProduct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoesCollide

/**********************************************************
		C# code from
		http://www.codeproject.com/Articles/15573/2D-Polyhedron-Collision-Detection
*/
bool Polyhedron::DoesCollide(Vector2* Velocity, Polyhedron* CheckWith)
{
	bool Intersect = true;
	bool WillIntersect = true;

	int edgeCountA = Edges->count;
	int edgeCountB = CheckWith->Edges->count;
	// float minIntervalDistance = 99999999;
	// Vector2* translationAxis = new Vector2( 0, 0 );
	Vector2* edge;

	// Loop through all the edges of both Polyhedrons
	for( int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++ )
	{
		if( edgeIndex < edgeCountA )
		{
			edge = Edges->ItemAt<Vector2*>(edgeIndex);
		} else {
			edge = CheckWith->Edges->ItemAt<Vector2*>(edgeIndex - edgeCountA);
		}

		// ===== 1. Find if the Polyhedrons are currently intersecting =====

		// Find the axis perpendicular to the current edge
		Vector2* axis = new Vector2(-edge->Y, edge->X);
		axis->Normalise();

		// Find the projection of the Polyhedron on the current axis
		float minA = 0; float minB = 0; float maxA = 0; float maxB = 0;
		Project(axis, &minA, &maxA);
		CheckWith->Project(axis, &minB, &maxB);

		// Check if the Polyhedron projections are currentlty intersecting
		if( IntervalDistance(minA, maxA, minB, maxB) > 0 )
		{
			Intersect = false;
		}

		// ===== 2. Now find if the Polyhedrons *will* intersect =====

		// Project the velocity on the current axis
		float velocityProjection = axis->DotProduct( Velocity );

		// Get the projection of Polyhedron A during the movement
		if( velocityProjection < 0 )
		{
			minA += velocityProjection;
		} else {
			maxA += velocityProjection;
		}

		// Do the same test as above for the new projection
		float intervalDistance = IntervalDistance( minA, maxA, minB, maxB );
		if( intervalDistance > 0 )
		{
			WillIntersect = false;
		}

		delete axis;

		// If the Polyhedrons are not intersecting and won't intersect, exit the loop
		if( !Intersect && !WillIntersect)
		{
			break;
		}

		/*
		// Check if the current interval distance is the minimum one. If so store
		// the interval distance and the current distance.
		// This will be used to calculate the minimum translation vector
		intervalDistance = Math.Abs(intervalDistance);
		if (intervalDistance < minIntervalDistance) {
			minIntervalDistance = intervalDistance;
			translationAxis = axis;

			Vector d = PolyhedronA.Center - PolyhedronB.Center;
			if (d.DotProduct(translationAxis) < 0) translationAxis = -translationAxis;
		}
		*/
		// int xcv = 1;

	}

	// The minimum translation vector can be used to push the Polyhedrons appart.
	// First moves the Polyhedrons by their velocity
	// then move PolyhedronA by MinimumTranslationVector.
	// if (result.WillIntersect) result.MinimumTranslationVector = translationAxis * minIntervalDistance;

	return (Intersect | WillIntersect);
}
开发者ID:pmprog,项目名称:JANE.v4,代码行数:94,代码来源:polygon.cpp

示例2: DotProduct

 double DotProduct( Vector2 const& i_lhs, Vector2 const& i_rhs )
 {
     return i_lhs.DotProduct( i_rhs );
 }
开发者ID:jpgaribotti,项目名称:libvector,代码行数:4,代码来源:Vector2.cpp


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