本文整理汇总了C++中Vector2::Dot方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::Dot方法的具体用法?C++ Vector2::Dot怎么用?C++ Vector2::Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2
的用法示例。
在下文中一共展示了Vector2::Dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool IntrSegment2Box2<Real>::Test ()
{
Vector2<Real> kDiff = m_rkSegment.Origin - m_rkBox.Center;
Real fAWdU[2], fADdU[2], fRhs;
fAWdU[0] = Math<Real>::FAbs(m_rkSegment.Direction.Dot(m_rkBox.Axis[0]));
fADdU[0] = Math<Real>::FAbs(kDiff.Dot(m_rkBox.Axis[0]));
fRhs = m_rkBox.Extent[0] + m_rkSegment.Extent*fAWdU[0];
if (fADdU[0] > fRhs)
{
return false;
}
fAWdU[1] = Math<Real>::FAbs(m_rkSegment.Direction.Dot(m_rkBox.Axis[1]));
fADdU[1] = Math<Real>::FAbs(kDiff.Dot(m_rkBox.Axis[1]));
fRhs = m_rkBox.Extent[1] + m_rkSegment.Extent*fAWdU[1];
if (fADdU[1] > fRhs)
{
return false;
}
Vector2<Real> kPerp = m_rkSegment.Direction.Perp();
Real fLhs = Math<Real>::FAbs(kPerp.Dot(kDiff));
Real fPart0 = Math<Real>::FAbs(kPerp.Dot(m_rkBox.Axis[0]));
Real fPart1 = Math<Real>::FAbs(kPerp.Dot(m_rkBox.Axis[1]));
fRhs = m_rkBox.Extent[0]*fPart0 + m_rkBox.Extent[1]*fPart1;
return fLhs <= fRhs;
}
示例2:
bool IntrRay2Box2<Real>::Test ()
{
Real WdU[2], AWdU[2], DdU[2], ADdU[2];
Vector2<Real> diff = mRay->Origin - mBox->Center;
WdU[0] = mRay->Direction.Dot(mBox->Axis[0]);
AWdU[0] = Math<Real>::FAbs(WdU[0]);
DdU[0] = diff.Dot(mBox->Axis[0]);
ADdU[0] = Math<Real>::FAbs(DdU[0]);
if (ADdU[0] > mBox->Extent[0] && DdU[0]*WdU[0] >= (Real)0)
{
return false;
}
WdU[1] = mRay->Direction.Dot(mBox->Axis[1]);
AWdU[1] = Math<Real>::FAbs(WdU[1]);
DdU[1] = diff.Dot(mBox->Axis[1]);
ADdU[1] = Math<Real>::FAbs(DdU[1]);
if (ADdU[1] > mBox->Extent[1] && DdU[1]*WdU[1] >= (Real)0)
{
return false;
}
Vector2<Real> perp = mRay->Direction.Perp();
Real LHS = Math<Real>::FAbs(perp.Dot(diff));
Real part0 = Math<Real>::FAbs(perp.Dot(mBox->Axis[0]));
Real part1 = Math<Real>::FAbs(perp.Dot(mBox->Axis[1]));
Real RHS = mBox->Extent[0]*part0 + mBox->Extent[1]*part1;
return LHS <= RHS;
}
示例3:
bool IntrSegment2Box2<Real>::Test ()
{
Vector2<Real> diff = mSegment->Center - mBox->Center;
Real AWdU[2], ADdU[2], RHS;
AWdU[0] = Math<Real>::FAbs(mSegment->Direction.Dot(mBox->Axis[0]));
ADdU[0] = Math<Real>::FAbs(diff.Dot(mBox->Axis[0]));
RHS = mBox->Extent[0] + mSegment->Extent*AWdU[0];
if (ADdU[0] > RHS)
{
return false;
}
AWdU[1] = Math<Real>::FAbs(mSegment->Direction.Dot(mBox->Axis[1]));
ADdU[1] = Math<Real>::FAbs(diff.Dot(mBox->Axis[1]));
RHS = mBox->Extent[1] + mSegment->Extent*AWdU[1];
if (ADdU[1] > RHS)
{
return false;
}
Vector2<Real> perp = mSegment->Direction.Perp();
Real LHS = Math<Real>::FAbs(perp.Dot(diff));
Real part0 = Math<Real>::FAbs(perp.Dot(mBox->Axis[0]));
Real part1 = Math<Real>::FAbs(perp.Dot(mBox->Axis[1]));
RHS = mBox->Extent[0]*part0 + mBox->Extent[1]*part1;
return LHS <= RHS;
}
示例4: ContOrientedBox
//----------------------------------------------------------------------------
bool Mgc::ContOrientedBox (int iQuantity, const Vector2* akPoint,
const bool* abValid, Box2& rkBox)
{
if ( !GaussPointsFit(iQuantity,akPoint,abValid,rkBox.Center(),
rkBox.Axes(),rkBox.Extents()) )
{
return false;
}
// Let C be the box center and let U0 and U1 be the box axes. Each input
// point is of the form X = C + y0*U0 + y1*U1. The following code
// computes min(y0), max(y0), min(y1), and max(y1). The box center is
// then adjusted to be
// C' = C + 0.5*(min(y0)+max(y0))*U0 + 0.5*(min(y1)+max(y1))*U1
// get first valid vertex
Vector2 kDiff;
Real fY0Min, fY0Max, fY1Min, fY1Max;
int i;
for (i = 0; i < iQuantity; i++)
{
if ( abValid[i] )
{
kDiff = akPoint[i] - rkBox.Center();
fY0Min = kDiff.Dot(rkBox.Axis(0));
fY0Max = fY0Min;
fY1Min = kDiff.Dot(rkBox.Axis(1));
fY1Max = fY1Min;
break;
}
}
for (i++; i < iQuantity; i++)
{
if ( abValid[i] )
{
kDiff = akPoint[i] - rkBox.Center();
Real fY0 = kDiff.Dot(rkBox.Axis(0));
if ( fY0 < fY0Min )
fY0Min = fY0;
else if ( fY0 > fY0Max )
fY0Max = fY0;
Real fY1 = kDiff.Dot(rkBox.Axis(1));
if ( fY1 < fY1Min )
fY1Min = fY1;
else if ( fY1 > fY1Max )
fY1Max = fY1;
}
}
rkBox.Center() += (0.5f*(fY0Min+fY0Max))*rkBox.Axis(0)
+ (0.5f*(fY1Min+fY1Max))*rkBox.Axis(1);
rkBox.Extent(0) = 0.5f*(fY0Max - fY0Min);
rkBox.Extent(1) = 0.5f*(fY1Max - fY1Min);
return true;
}
示例5: DoTrackPlayer
void CurrencyOrb::DoTrackPlayer(float delta)
{
mSineWaveProps.DoSineWave = false;
Player * player = GameObjectManager::Instance()->GetPlayer();
if (!player)
{
return;
}
// accelerate towards the target
Vector3 direction = Vector3(player->CollisionCentreX(), player->CollisionCentreY(), player->Z()) - m_position;
direction.Normalise();
m_direction = direction;
float multiplier = mTimeTracking > 2.0f ? 3.0f : 1.0f;
bool prioritiseX = false;
if (std::abs(m_direction.X) > std::abs(m_direction.Y))
{
AccelerateX(m_direction.X, kAccelerateRate * multiplier);
prioritiseX = true;
}
else
{
AccelerateY(m_direction.Y, kAccelerateRate * multiplier);
}
if (prioritiseX && ((m_direction.X < 0 && m_velocity.X > 0) ||
(m_direction.X > 0 && m_velocity.X < 0)))
{
// the velocity of the orb is still moving in the opposite x direction
// let's give it a helping hand to catch up by accelerating harshly
AccelerateX(m_direction.X, kHarshAccelerateRate * multiplier);
}
if (!prioritiseX && ((m_direction.Y < 0 && m_velocity.Y > 0) ||
(m_direction.Y > 0 && m_velocity.Y < 0)))
{
// the velocity of the orb is still moving in the opposite y direction
// let's give it a helping hand to catch up by accelerating harshly
AccelerateY(m_direction.Y, kHarshAccelerateRate * multiplier);
}
Vector2 dir = Vector2(m_velocity.X, m_velocity.Y);
dir.Normalise();
if (dir.X > 0)
{
SetRotationAngle(-acos(dir.Dot(Vector2(0, -1))));
}
else
{
SetRotationAngle(acos(dir.Dot(Vector2(0, -1))));
}
}
示例6:
bool IntrLine2Box2<Real>::Test ()
{
Vector2<Real> diff = mLine->Origin - mBox->Center;
Vector2<Real> perp = mLine->Direction.Perp();
Real LHS = Math<Real>::FAbs( perp.Dot( diff ) );
Real part0 = Math<Real>::FAbs( perp.Dot( mBox->Axis[0] ) );
Real part1 = Math<Real>::FAbs( perp.Dot( mBox->Axis[1] ) );
Real RHS = mBox->Extent[0] * part0 + mBox->Extent[1] * part1;
return LHS <= RHS;
}
示例7:
Real DistLine2Ray2<Real>::GetSquared ()
{
Vector2<Real> diff = mLine->Origin - mRay->Origin;
Real a01 = -mLine->Direction.Dot(mRay->Direction);
Real b0 = diff.Dot(mLine->Direction);
Real c = diff.SquaredLength();
Real det = Math<Real>::FAbs((Real)1 - a01*a01);
Real b1, s0, s1, sqrDist;
if (det >= Math<Real>::ZERO_TOLERANCE)
{
b1 = -diff.Dot(mRay->Direction);
s1 = a01*b0 - b1;
if (s1 >= (Real)0)
{
// Two interior points are closest, one on line and one on ray.
Real invDet = ((Real)1)/det;
s0 = (a01*b1 - b0)*invDet;
s1 *= invDet;
sqrDist = (Real)0;
}
else
{
// Origin of ray and interior point of line are closest.
s0 = -b0;
s1 = (Real)0;
sqrDist = b0*s0 + c;
// Account for numerical round-off errors.
if (sqrDist < (Real)0)
{
sqrDist = (Real)0;
}
}
}
else
{
// Lines are parallel, closest pair with one point at ray origin.
s0 = -b0;
s1 = (Real)0;
sqrDist = b0*s0 + c;
// Account for numerical round-off errors.
if (sqrDist < (Real)0)
{
sqrDist = (Real)0;
}
}
mClosestPoint0 = mLine->Origin + s0*mLine->Direction;
mClosestPoint1 = mRay->Origin + s1*mRay->Direction;
return sqrDist;
}
示例8:
bool IntrTriangle2Triangle2<Real>::Test (Real tmax,
const Vector2<Real>& velocity0, const Vector2<Real>& velocity1)
{
// Process as if V0-triangle is stationary and V1-triangle is moving.
Vector2<Real> W = velocity1 - velocity0;
int side = 0; // 0 = NONE, -1 = LEFT, +1 = RIGHT
Real tfirst = (Real)0;
Real tlast = Math<Real>::MAX_REAL;
Configuration cfg0, cfg1, tcfg0, tcfg1;
int i0, i1, i2;
Vector2<Real> D;
Real speed;
// Process edges of V0-triangle.
for (i0 = 1, i1 = 2, i2 = 0; i2 < 3; i0 = i1, i1 = i2++)
{
// Test axis V0[i1] + t*perp(V0[i2]-V0[i1]), perp(x,y) = (y,-x).
D.X() = mTriangle0->V[i2].Y() - mTriangle0->V[i1].Y();
D.Y() = mTriangle0->V[i1].X() - mTriangle0->V[i2].X();
speed = D.Dot(W);
ComputeTwo(cfg0, mTriangle0->V, D, i0, i1, i2);
ComputeThree(cfg1, mTriangle1->V, D, mTriangle0->V[i1]);
if (NoIntersect(cfg0, cfg1, tmax, speed, side, tcfg0, tcfg1,
tfirst, tlast))
{
return false;
}
}
// Process edges of V1-triangle.
for (i0 = 1, i1 = 2, i2 = 0; i2 < 3; i0 = i1, i1 = i2++)
{
// Test axis V1[i1] + t*perp(V1[i2]-V1[i1]), perp(x,y) = (y,-x).
D.X() = mTriangle1->V[i2].Y() - mTriangle1->V[i1].Y();
D.Y() = mTriangle1->V[i1].X() - mTriangle1->V[i2].X();
speed = D.Dot(W);
ComputeTwo(cfg1, mTriangle1->V, D, i0, i1, i2);
ComputeThree(cfg0, mTriangle0->V, D, mTriangle1->V[i1]);
if (NoIntersect(cfg0, cfg1, tmax, speed, side, tcfg0, tcfg1,
tfirst, tlast))
{
return false;
}
}
mContactTime = tfirst;
return true;
}
示例9: RayCast
float Circle::RayCast( Vector2 *start, Vector2 *end, bool invert ){
Vector2 *delta = start->Sub(m_pos);
Vector2 *d = end->Sub(start);
float a = d->Dot(delta);
float b = d->get_m_LenSqr();
float c = delta->get_m_LenSqr();
float roa = a * a - b * (c - m_radius * m_radius);
if (roa < 0){
// no intersection
return -1;
} else if (roa == 0) {
// ray tangent to circle, one intersection
float num = sqrt(roa);
float t0 = (-a + num) / b;
return t0;
} else {
// two intersection points
float num = sqrt(roa);
float t0 = (-a + num) / b;
float t1 = (-a - num) / b;
if (invert) {
return (float)_min(t1, t0);
} else {
return t0;
}
}
}
示例10: if
bool IntrLine2Circle2<Real>::Find (const Vector2<Real>& origin,
const Vector2<Real>& direction, const Vector2<Real>& center,
Real radius, int& rootCount, Real t[2])
{
// Intersection of a the line P+t*D and the circle |X-C| = R. The line
// direction is unit length. The t value is a root to the quadratic
// equation:
// 0 = |t*D+P-C|^2 - R^2
// = t^2 + 2*Dot(D,P-C)*t + |P-C|^2-R^2
// = t^2 + 2*a1*t + a0
// If two roots are returned, the order is T[0] < T[1].
Vector2<Real> diff = origin - center;
Real a0 = diff.SquaredLength() - radius*radius;
Real a1 = direction.Dot(diff);
Real discr = a1*a1 - a0;
if (discr > Math<Real>::ZERO_TOLERANCE)
{
rootCount = 2;
discr = Math<Real>::Sqrt(discr);
t[0] = -a1 - discr;
t[1] = -a1 + discr;
}
else if (discr < -Math<Real>::ZERO_TOLERANCE)
{
rootCount = 0;
}
else // discr == 0
{
rootCount = 1;
t[0] = -a1;
}
return rootCount != 0;
}
示例11: y
Real DistPoint2Ellipse2<Real>::GetSquared ()
{
// Compute coordinates of point in ellipse coordinate system.
Vector2<Real> diff = *mPoint - mEllipse->Center;
Vector2<Real> y(diff.Dot(mEllipse->Axis[0]), diff.Dot(mEllipse->Axis[1]));
Vector2<Real> x;
Real sqrDistance = SqrDistance(mEllipse->Extent, y, x);
mClosestPoint0 = *mPoint;
mClosestPoint1 = mEllipse->Center +
x[0]*mEllipse->Axis[0] +
x[1]*mEllipse->Axis[1];
return sqrDistance;
}
示例12: return
bool
collides( const Circle & c, const LineSegment & l)
{
Vector2 posToCenter = c.GetCenter() - l.GetStart();
Vector2 dirVec = l.GetEnd() - l.GetStart();
float segmentLength = dirVec.Length();
// direction vector must be unit vector (ie. length = 1) in this case!
// otherwise we would need another formula for scalar projection.
dirVec = dirVec / segmentLength;
// scalar projection of posToCenter to direction vector.
float d = dirVec.Dot(posToCenter);
// if d value exceeds original segment length, then we put a cap on it.
// if these two lines are dismissed, then algorithm sees line segment
// as a infinite line.
if ( d > segmentLength ) d = segmentLength;
if ( d < -segmentLength ) d = -segmentLength;
// compute closest point to circle center from line start
// along direction vector.
Vector2 closest_point =l.GetStart() + dirVec * d;
// vectorfrom circle center to closest point on line
Vector2 S = closest_point - c.GetCenter();
return (S.Length() <= c.GetRadius());
}
示例13: if
float Vector2::AngleBetween(Vector2 v) const {
if (this->Magnitude() == 0 || v.Magnitude() == 0) {
return 0;
}
Vector2 left = this->Normalize();
Vector2 right = v.Normalize();
if (left == right) {
return 0;
}
float dot = left.Dot(right);
// Floating points check
if (dot > 1.0f) {
dot = 1.0f;
}
else if (dot < -1.0f) {
dot = -1.0f;
}
float rot = acos(dot);
// http://stackoverflow.com/questions/11022446/direction-of-shortest-rotation-between-two-vectors
// Use cross vector3 to determine direction
Vector3 cross = Vector3(left.x, left.y).Cross(Vector3(right.x, right.y));
if (cross.z > 0) {
return -rot;
}
else {
return rot;
}
}
示例14: if
bool IntrLine2Circle2<Real>::Find (const Vector2<Real>& rkOrigin,
const Vector2<Real>& rkDirection, const Vector2<Real>& rkCenter,
Real fRadius, int& riRootCount, Real afT[2])
{
// Intersection of a the line P+t*D and the circle |X-C| = R. The line
// direction is unit length. The t value is a root to the quadratic
// equation:
// 0 = |t*D+P-C|^2 - R^2
// = t^2 + 2*Dot(D,P-C)*t + |P-C|^2-R^2
// = t^2 + 2*a1*t + a0
// If two roots are returned, the order is T[0] < T[1].
Vector2<Real> kDiff = rkOrigin - rkCenter;
Real fA0 = kDiff.SquaredLength() - fRadius*fRadius;
Real fA1 = rkDirection.Dot(kDiff);
Real fDiscr = fA1*fA1 - fA0;
if (fDiscr > Math<Real>::ZERO_TOLERANCE)
{
riRootCount = 2;
fDiscr = Math<Real>::Sqrt(fDiscr);
afT[0] = -fA1 - fDiscr;
afT[1] = -fA1 + fDiscr;
}
else if (fDiscr < -Math<Real>::ZERO_TOLERANCE)
{
riRootCount = 0;
}
else // fDiscr == 0
{
riRootCount = 1;
afT[0] = -fA1;
}
return riRootCount != 0;
}
示例15: if
int IntrTriangle2Triangle2<Real>::WhichSide (const Vector2<Real> V[3],
const Vector2<Real>& P, const Vector2<Real>& D)
{
// Vertices are projected to the form P+t*D. Return value is +1 if all
// t > 0, -1 if all t < 0, 0 otherwise, in which case the line splits the
// triangle.
int positive = 0, negative = 0, zero = 0;
for (int i = 0; i < 3; ++i)
{
Real t = D.Dot(V[i] - P);
if (t > (Real)0)
{
++positive;
}
else if (t < (Real)0)
{
++negative;
}
else
{
++zero;
}
if (positive > 0 && negative > 0)
{
return 0;
}
}
return (zero == 0 ? (positive > 0 ? 1 : -1) : 0);
}