本文整理汇总了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);
}
示例2: DotProduct
double DotProduct( Vector2 const& i_lhs, Vector2 const& i_rhs )
{
return i_lhs.DotProduct( i_rhs );
}