Ejemplo n.º 1
0
tuple<bool, Pvector> Boid::CalcLJ(Boid b, sf::Vector2f playerPos)
{
	Pvector	R;
	Pvector p(playerPos.x, playerPos.y);


	float neighbordist = 500;
	float neighbordist2 = 200;
	float A = 100;
	float B = 5000;
	float N = 1;
	float M = 2;

	float d = location.distance(b.location);
	float d2 = location.distance(p);

	if ((d2 > 0) && (d2 < neighbordist2))
	{
		R = location;
		R.subVector(p);

		float D = R.magnitude();
		float U = -A / pow(D, N) + B / pow(D, M);
		R.normalize();

		R.mulScalar(U);
		return tuple<bool, Pvector>(true, R);
	}
	else if ((d > 0) && (d < neighbordist)) // 0 < d < 500
	{
		R = location;
		R.subVector(b.location);

		float D = R.magnitude();
		float U = -A / pow(D, N) + B / pow(D, M);
		R.normalize();

		R.mulScalar(U);
		return tuple<bool, Pvector>(true, R);
	}
	else
		return tuple<bool, Pvector>(false, R);
}
Ejemplo n.º 2
0
// Limits the maxSpeed, finds necessary steering force and
// normalizes vectors
Pvector Boid::seek(Pvector v)
{
	Pvector desired;
	desired.subVector(v);  // A vector pointing from the location to the target
	// Normalize desired and scale to maximum speed
	desired.normalize();
	desired.mulScalar(maxSpeed);
	// Steering = Desired minus Velocity
	acceleration.subTwoVector(desired, velocity);
	acceleration.limit(maxForce);  // Limit to maximum steering force
	return acceleration;
}