本文整理汇总了C++中Vector2D::magnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2D::magnitude方法的具体用法?C++ Vector2D::magnitude怎么用?C++ Vector2D::magnitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2D
的用法示例。
在下文中一共展示了Vector2D::magnitude方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CircleToAABB
bool Collision::CircleToAABB(Circle &a, Box &b, bool &hitFloor,bool &hitSide, bool &hitUnder)
{
Vector2D extents(b.getWidth()/2,b.getHeight()/2);//!< puts the extents of the box into a vector2d.
Vector2D disti = b.getPosition().subtract(a.getPosition());//!< Finds the distance between the two origins.
Vector2D clamp = clamp.minMax(disti,extents);//!<Clamp closet point?
disti = disti.subtract(clamp);//!< Calculates the distance from the box. In the X and Y.
distance = disti.magnitude() - a.getRadius();//!< Gets the length between the two objects.
if(distance > 0)
{
return false; //!<Exits if the distance is greater than 0
}
//return true;
normal2 = disti.getUnitVector();//!< Calculates the normal
//!Used to find out if ive hit top side or under
if(normal2.getY() > 0.2f)
{
hitFloor = true;
}
else hitFloor = false;
if(normal2.getY() < -0.5f)
{
hitUnder = true;
}
if(normal2.getX() == -1.f || normal2.getX() == 1.f )
{
hitSide = true;
}
return true;
}
示例2: updateForce
void ParticleUplift::updateForce(Particle *particle, real duration) {
// Determine if the particle is within range of the origin
Vector2D relativePos = particle->getPosition() - origin;
if (relativePos.magnitude() > range) return;
// Particle is in range; apply uplift force
particle->addForce(uplift * particle->getMass());
}
示例3: CircleToLine
bool Collision::CircleToLine(Circle &a, Line &b)
{
Vector2D normal = b.lineNormal();//!< Gets the normal of the line and sets to a new Vector2D
float mag = normal.magnitude();//!< Finds the magnitude of the normal.
float c = b.lineOrigin();//!< Find the origin value of the line.
c /= mag;//!< Normalises the origin value.
Vector2D normal2 = normal.getUnitVector();//!< normalises the normal.
float distance = (a.getPosition().dotProduct(normal2) + (c));//!< Finds the distance away from the point. distance = p.n +
return (distance >= 0 - a.getRadius()); //!< If the distance is 0 or less than 0. Return true.
}
示例4: CircleToCircle
void Collision::CircleToCircle(Circle &a, Circle &b)
{
ManifoldCtoC m;
Vector2D diff = a.getPosition().subtract(b.getPosition());//!< Origin of position subtracting origin of other position;
float dist = diff.magnitude();//!< Gets the length between the two origins.
float sumOfRadii = a.getRadius() + b.getRadius();//!< Sum of the radii
if (dist > sumOfRadii)//!< Exits early if no collision detection.
{
return;
}
//!send circles and the calculated distance to the manifold.
m.Initialize(a,b, dist);//!< Initializes the manifold.
m.ApplyImpulse(a,b);
}
示例5: magnitude
int Vector2D::compareTo(Vector2D& v, Vector2D::comparison_type ct) const
{
double result;
switch (ct) {
case BY_X:
result = x-v.x;
case BY_Y:
result = y-v.y;
case BY_XY:
if (x-v.x < 0) result = -1;
if (x-v.x > 0) result = 1;
result = y-v.y;
case BY_YX:
if (y-v.y < 0) result = -1;
if (y-v.y > 0) result = 1;
result = x-v.x;
case BY_MAGNITUDE:
result = magnitude()-v.magnitude();
}
return static_cast<int>(result);
}
示例6: circle_test
// *****************************************************************************
// *****************************************************************************
int TriangleMeshSLK::circle_test(Point2D t1, Point2D t2, Point2D t3, Point2D t) {
int flag = 0;
Point2D p1, p2, p3, p;
// scale incoming triangle to unit max length
Point2D lo, hi;
lo[0] = MIN(t1[0], MIN(t2[0], t3[0]));
lo[1] = MIN(t1[1], MIN(t2[1], t3[1]));
hi[0] = MAX(t1[0], MAX(t2[0], t3[0]));
hi[1] = MAX(t1[1], MAX(t2[1], t3[1]));
double dm = MAX(hi[0] - lo[0], hi[1] - lo[1]);
p1[0] = (t1[0] - lo[0]) / dm;
p1[1] = (t1[1] - lo[1]) / dm;
p2[0] = (t2[0] - lo[0]) / dm;
p2[1] = (t2[1] - lo[1]) / dm;
p3[0] = (t3[0] - lo[0]) / dm;
p3[1] = (t3[1] - lo[1]) / dm;
p[0] = (t[0] - lo[0]) / dm;
p[1] = (t[1] - lo[1]) / dm;
//
// compute circumscribing radius
//
Point2D cc;
double m[3][3];
double a, bx, by, c;
m[0][0] = p1[0];
m[1][0] = p2[0];
m[2][0] = p3[0];
m[0][1] = p1[1];
m[1][1] = p2[1];
m[2][1] = p3[1];
m[0][2] = 1.0;
m[1][2] = 1.0;
m[2][2] = 1.0;
a = DetMat3X3(m);
m[0][0] = p1[0] * p1[0] + p1[1] * p1[1];
m[1][0] = p2[0] * p2[0] + p2[1] * p2[1];
m[2][0] = p3[0] * p3[0] + p3[1] * p3[1];
bx = DetMat3X3(m);
m[0][1] = p1[0];
m[1][1] = p2[0];
m[2][1] = p3[0];
by = DetMat3X3(m);
m[0][2] = p1[1];
m[1][2] = p2[1];
m[2][2] = p3[1];
c = DetMat3X3(m);
cc = Point2D(0.5 * bx / a, -0.5 * by / a);
double rc, rp;
Vector2D vp;
vp = Vector2D(cc, p);
rp = vp.magnitude();
rc = 0.5 * sqrt(bx * bx + by * by + 4.0 * a * c) / fabs(a);
if (rp <= rc)
flag = 1;
return (flag);
}