int main(void) { e_init_port(); e_init_motors(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); int selector=getselector(); switch (selector) { case 0:robot_off();break; case 1:aggressive();break; case 2:fear();break; case 3:curious();break; case 4:love();break; case 5:robot_off();break; default:/*own high level behaviour*/break; } }
void Boid::update(std::vector<Boid *> *boids, ofVec2f * people, int numPeople) { // track positions if (tailLen > 0) { for (int i = tailLen - 1; i > 0; i--) lastPos[i] = lastPos[i-1]; lastPos[0] = pos; } neighbors.clear(); for (int i = 0; i < boids->size(); i++) { Boid *other = (*boids)[i]; if (other != this && pos.squareDistance(other->pos) < maxDist*maxDist) { neighbors.push_back(other); } } int neighborCount = neighbors.size(); if (neighborCount > 0) { ofVec2f v1, v2, v3; if (neighborCount < 4) { if (!personNearby && stayOn) v1 = cohesion(cohesionScalar); else v1 = cohesion(-cohesionScalar*2); v2 = alignment(alignmentScalar); } v3 = separation(separationScalar, minDist); vel += v1 + v2 + v3; } if (numPeople > 0) { if (!personNearby && stayOn) { runAwayVec = people[0]; //cout << "run away vec " << runAwayVec.x << ", " << runAwayVec << "\n\n\n"; personNearby = true; } ofVec2f v4 = fear(fearScalar, runAwayVec); vel += v4; } else personNearby = false; if (!stayOn) { ofVec2f v5 = stayOff(tableCenter); vel += v5; } strutVel = strut(strutScalar * vel.length(), strutFreq); //ofLog(OF_LOG_NOTICE, "%f %f is strutvel", strutVel.x, strutVel.y); if (!personNearby && stayOn) { if (pos.x > maxX - 1.1 * radius) vel.x -= (pos.x - (maxX - 1.1 * radius)) * 0.09; if (pos.x < minX + 1.1 * radius) vel.x += ((minX + 1.1 * radius) - pos.x) * 0.09; if (pos.y > maxY - 1.1 * radius) vel.y -= (pos.y - (maxY - 1.1 * radius)) * 0.09; if (pos.y < minY + 1.1 * radius) vel.y += ((minY + 1.1 * radius) - pos.y) * 0.09; // maintain a max speed vel.limit(0.8f); } else vel.limit(2.5f); if (pos.distanceSquared(tableCenter) > maxDistFromTable*maxDistFromTable) { ofVec2f difference = pos - tableCenter; difference.rescale(maxDistFromTable); pos = tableCenter + difference; } }