Ejemplo n.º 1
0
CFVec2 CSteeringAgent::GetRepulsionBearingEffect() const
{
	CFVec2 vCumulativeRepulsionEffect = fv2EMPTY;

	const vector<CCircle>& krRepulsionZones = CBlackboard::GetInstance().GetRepulsionZones();
	for (unsigned int uiIndex = 0; uiIndex < krRepulsionZones.size(); uiIndex++)
	{
		CFVec2 vRepulsionEffect = m_krCat.GetPosition() - krRepulsionZones.at(uiIndex).Centre();
		FLOAT32 fDistanceBetweenCenters = vRepulsionEffect.Magnitude();

		FLOAT32 fDistanceBetweenBorders = fDistanceBetweenCenters - m_krCat.GetRadius() -
			krRepulsionZones.at(uiIndex).Radius();

		if (m_krCat.GetHeadingVector().DotProduct(vRepulsionEffect) < 0.0f &&
			fDistanceBetweenBorders < m_fRepulsionBufferStatic)
		{
			FLOAT32 fDistanceIntoRepulsionBuffer = (m_fRepulsionBufferStatic - fDistanceBetweenBorders) /
				m_fRepulsionBufferStatic;
			vRepulsionEffect.Normalise();
			vRepulsionEffect *= fDistanceIntoRepulsionBuffer;
			vCumulativeRepulsionEffect += vRepulsionEffect;
		}
	}

	const vector<const CCat*>& krCats = CBlackboard::GetInstance().GetCats();
	for (unsigned int uiIndex = 0; uiIndex < krCats.size(); uiIndex++)
	{
		CFVec2 vRepulsionEffect = m_krCat.GetPosition() - krCats.at(uiIndex)->GetPosition();
		FLOAT32 fDistanceBetweenCenters = vRepulsionEffect.Magnitude();

		// We don't want the cat to repel itself...
		if (fDistanceBetweenCenters == 0.0f)
		{
			continue;
		}

		FLOAT32 fDistanceBetweenBorders = fDistanceBetweenCenters - m_krCat.GetRadius() * 2.0f;

		if (m_krCat.GetHeadingVector().DotProduct(vRepulsionEffect) < 0.0f &&
			fDistanceBetweenBorders < m_fRepulsionBufferDynamic)
		{
			FLOAT32 fDistanceIntoRepulsionBuffer = (m_fRepulsionBufferDynamic - fDistanceBetweenBorders) /
				m_fRepulsionBufferDynamic;
			vRepulsionEffect.Normalise();
			vRepulsionEffect *= fDistanceIntoRepulsionBuffer;
			vCumulativeRepulsionEffect += vRepulsionEffect;
		}
	}

	if (vCumulativeRepulsionEffect.Magnitude() > 1.0f)
	{
		vCumulativeRepulsionEffect.Normalise();
	}

	return vCumulativeRepulsionEffect;
}
Ejemplo n.º 2
0
CFVec2 CSteeringAgent::GetAbsoluteWhiskerStart(const CFVec2& _krvRelativeWhisker) const
{
	CFVec2 vAbsoluteWhiskerStart = GetAdjustedWhisker(_krvRelativeWhisker);

	if (vAbsoluteWhiskerStart.Magnitude() != 0.0f)
	{
		vAbsoluteWhiskerStart.Normalise();
		vAbsoluteWhiskerStart *= m_krCat.GetRadius();
	}

	vAbsoluteWhiskerStart += m_krCat.GetPosition();

	return vAbsoluteWhiskerStart;
}