bool Environment::initRobots(const Formation f) { for (GLint i = 0; i < N_CELLS; ++i) if (!addCell(gXPos[i], gYPos[i], gHeading[i])) return false; // initialize each robot's neighborhood if (!initNbrs()) return false; setColor(BLACK); return (getNCells() == N_CELLS) && sendMsg(new Formation(f), f.getSeedID(), ID_OPERATOR, CHANGE_FORMATION); }
// // bool initCells(n, f) // Last modified: 28Aug2006 // // Initializes each cell to the parameterized values, // returning true if successful, false otherwise. // // Returns: true if successful, false otherwise // Parameters: // n in the initial number of cells // f in the initial formation // bool Environment::initCells(const GLint n, const Formation f) { srand(time(NULL)); for (GLint i = 0; i < n; ++i) if (!addCell()) return false; // initialize each robot's neighborhood if (!initNbrs()) return false; // organizes the cells into an initial formation (default line) Cell *c = NULL; for (GLint i = 0; i < getNCells(); ++i) { if (!cells.getHead(c)) return false; c->x = f.getRadius() * ((GLfloat)i - (GLfloat)(getNCells() - 1) / 2.0f); c->y = 0.0f; c->setColor(DEFAULT_ROBOT_COLOR); c->setHeading(f.getHeading()); ++cells; } return (getNCells() == n) && sendMsg(new Formation(f), f.getSeedID(), ID_OPERATOR, CHANGE_FORMATION); } // initCells(const GLint, const Formation f)
const GLfloat SELECT_RADIUS = 1.5f * DEFAULT_ROBOT_RADIUS; const GLint N_CELLS = 0; const GLint MIDDLE_CELL = 0;//(N_CELLS - 1) / 2; const Formation DEFAULT_FORMATION = Formation(formations[0], DEFAULT_ROBOT_RADIUS * FACTOR_COLLISION_RADIUS, Vector(), MIDDLE_CELL, 0, 90.0f); // simulation global variables Environment *g_env = NULL; GLint g_nRobots = 0; GLfloat g_fRadius = DEFAULT_FORMATION.getRadius(); GLint g_sID = DEFAULT_FORMATION.getSeedID(); GLint g_fID = DEFAULT_FORMATION.getFormationID(); GLfloat g_fHeading = DEFAULT_FORMATION.getHeading(); GLint g_fIndex = 0; GLint g_selectedIndex = g_sID; GLint g_dt = 50; // time interval (in milliseconds) bool g_prop_toggle = false; // // GLint main(argc, argv) // Last modified: 04Sep2006 // // Uses the OpenGL Utility Toolkit to set the // window up to display the window and its contents.