本文整理汇总了C++中Vector2D::subtract方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2D::subtract方法的具体用法?C++ Vector2D::subtract怎么用?C++ Vector2D::subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2D
的用法示例。
在下文中一共展示了Vector2D::subtract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cohesion
void Boid::cohesion(deque<Boid*>& neighbours) {
Vector2D vForce;
float neighborCount = 0;
Vector2D vCenterOfMass;
deque<Boid*>::iterator itBoid;
for(itBoid = neighbours.begin(); itBoid != neighbours.end(); ++itBoid) {
if(*itBoid == this) continue;
vCenterOfMass.add((*itBoid)->getVelocity());
++neighborCount;
}
if(neighborCount > 0) {
vCenterOfMass.devide(neighborCount);
if(vCenterOfMass.distanceToSQ(getVelocity()) > 5.0f * 5.0f) {
Vector2D vel = vCenterOfMass;
Vector2D pos = position;
pos.normalize();
vel.subtract(pos);
vel.subtract(getVelocity());
vel.scale(0.1);
velocity.add(vel);
}
}
}
示例2: 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;
}