Rectangle::Rectangle(wle::AABB bounds): shape_(0), bounds_(bounds){ shape_ = new sf::RectangleShape(pointToVec(bounds.getSize())); shape_->setPosition(pointToVec(bounds.getCenter())); shape_->setFillColor(sf::Color(rand()%255, rand()%255, rand()%255)); direction_ = new sf::Vector2i(rand()%2?-1:1, rand()%2?-1:1); speed_ = new sf::Vector2f(rand()/double(RAND_MAX) + 0.1, rand()/double(RAND_MAX) + 0.1); }
Vec2f Animal::getCohesionForce(vector<Animal> animals, float dist) { float neighbourDist = dist; Vec2f sum = Vec2f(0, 0); int count = 0; for (vector<Animal>::iterator it = animals.begin(); it != animals.end(); ++it) { if (isNear(*it, neighbourDist)) { sum = sum + pointToVec(it->getPos()); count++; } } if (count > 0) { sum = sum / count; return getSeek(sum); } else { return Vec2f(0, 0); } }
Vec2f Animal::getSeek (Vec2f target) { Vec2f desired = target - pointToVec(Object::getPos()); return getSteer(desired); }