本文整理汇总了C++中Organism::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Organism::size方法的具体用法?C++ Organism::size怎么用?C++ Organism::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Organism
的用法示例。
在下文中一共展示了Organism::size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createOrganism
void DynamicController::createOrganism(double &left, double &right, int desired_size, double speed) {
DynamicAgentWorldModel* worldModel = dynamic_cast<DynamicAgentWorldModel*> (_wm);
RobotAgentPtr agent = gWorld->getAgent(worldModel->_agentId);
// You are only eager to connect when your current organism is not large enough according to your standards.
if (agent->isPartOfOrganism()){
Organism *o = agent->getOrganism();
if (o->size() < desired_size){
agent->setConnectToOthers(Agent::POSITIVE);
}else{
agent->setConnectToOthers(Agent::NEUTRAL);
}
}else{
agent->setConnectToOthers(Agent::POSITIVE);
}
if (agent->getConnectToOthers() == Agent::NEGATIVE) {
avoidObstacles(left, right, speed);
return;
}
Point2d posRobot = worldModel->getPosition();
double closestDistance = getMaximumDistance();
bool found = false;
Point2d closestPoint;
RobotAgentPtr closest;
vector<RobotAgentPtr> close = agent->getNearRobots();
// find robots that we can connect to
vector<RobotAgentPtr>::iterator it;
for (it = close.begin(); it != close.end(); it++) {
if ((*it)->getConnectToOthers() == Agent::POSITIVE) {
Point2d closeRobot = (*it)->getWorldModel()->getPosition();
double distance = getEuclidianDistance(posRobot, closeRobot);
if (distance < closestDistance) {
found = true;
closestDistance = distance;
closestPoint = closeRobot;
closest = (*it);
}
}
}
// No robots that want to connect are close
if (!found) {
avoidObstacles(left, right, speed);
} else {
// steer towards the closest robot that wants to connect
double angle = (atan2(closestPoint.y - posRobot.y, closestPoint.x - posRobot.x) / M_PI) * 180.0;
double diffAngle = angle - _wm->_agentAbsoluteOrientation;
if (diffAngle < -180.0) {
diffAngle += 360.0;
}
if (diffAngle > 180.0) {
diffAngle -= 360.0;
}
followAngle(diffAngle, left, right);
left *= speed;
right *= speed;
}
}