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


C++ Vector2D::subtract方法代码示例

本文整理汇总了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);
		}
	}
	
	
}
开发者ID:Gerjo,项目名称:NintendoDS-Flocking,代码行数:31,代码来源:Boid.cpp

示例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;
}
开发者ID:Zzy-ZhangZeyu,项目名称:SmallGame,代码行数:31,代码来源:Collision.cpp


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