void SoundplaneZoneView::renderZones() { if (!mpModel) return; const ScopedLock lock(*(mpModel->getZoneLock())); const std::vector<ZonePtr>& zoneList = mpModel->getZones(); int viewW = getBackingLayerWidth(); int viewH = getBackingLayerHeight(); int viewScale = getRenderingScale(); // float viewAspect = (float)viewW / (float)viewH; int gridWidth = 30; // Soundplane A TODO get from tracker int gridHeight = 5; int lineWidth = viewW / 200; int thinLineWidth = viewW / 400; // int margin = lineWidth*2; // put origin in lower left. MLGL::orthoView2(viewW, viewH); MLRange xRange(0, gridWidth, 1, viewW); MLRange yRange(0, gridHeight, 1, viewH); Vec4 lineColor; Vec4 darkBlue(0.3f, 0.3f, 0.5f, 1.f); Vec4 gray(0.6f, 0.6f, 0.6f, 1.f); Vec4 lightGray(0.9f, 0.9f, 0.9f, 1.f); Vec4 blue2(0.1f, 0.1f, 0.5f, 1.f); float smallDotSize = xRange(1.f); // float strokeWidth = viewW / 100; std::vector<ZonePtr>::const_iterator it; for(it = zoneList.begin(); it != zoneList.end(); ++it) { const Zone& zone = **it; int t = zone.getType(); MLRect zr = zone.getBounds(); const char * name = zone.getName().c_str(); int offset = zone.getOffset(); // affine transforms TODO for better syntax: MLRect zrd = zr.xform(gridToView); MLRect zoneRectInView(xRange.convert(zr.x()), yRange.convert(zr.y()), xRange.convert(zr.width()), yRange.convert(zr.height())); zoneRectInView.shrink(lineWidth); // color idx = type + port offset. Vec4 zoneStroke(MLGL::getIndicatorColor(t + offset)); Vec4 zoneFill(zoneStroke); zoneFill[3] = 0.1f; Vec4 activeFill(zoneStroke); activeFill[3] = 0.25f; Vec4 dotFill(zoneStroke); dotFill[3] = 0.5f; // draw box common to all kinds of zones glColor4fv(&zoneFill[0]); MLGL::fillRect(zoneRectInView); glColor4fv(&zoneStroke[0]); glLineWidth(lineWidth); MLGL::strokeRect(zoneRectInView, 2.0f*viewScale); glLineWidth(1); // draw name // all these rect calculations read upside-down here because view origin is at bottom MLGL::drawTextAt(zoneRectInView.left() + lineWidth, zoneRectInView.top() + lineWidth, 0.f, 0.1f, viewScale, name); // draw any zone-specific things float x, y; int toggle; switch(t) { case kNoteRow: for(int i = 0; i < kSoundplaneMaxTouches; ++i) { const ZoneTouch& uTouch = zone.getTouch(i); const ZoneTouch& touch = zone.touchToKeyPos(uTouch); if(touch.isActive()) { glColor4fv(&dotFill[0]); float dx = xRange(touch.pos.x()); float dy = yRange(touch.pos.y()); float dz = touch.pos.z(); MLGL::drawDot(Vec2(dx, dy), dz*smallDotSize); } } break; case kControllerX: x = xRange(zone.getXKeyPos()); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); MLGL::strokeRect(MLRect(x, zoneRectInView.top(), 0., zoneRectInView.height()), viewScale); glColor4fv(&activeFill[0]); MLGL::fillRect(MLRect(zoneRectInView.left(), zoneRectInView.top(), x - zoneRectInView.left(), zoneRectInView.height())); break; case kControllerY: y = yRange(zone.getYKeyPos()); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); MLGL::strokeRect(MLRect(zoneRectInView.left(), y, zoneRectInView.width(), 0.), viewScale); glColor4fv(&activeFill[0]); MLGL::fillRect(MLRect(zoneRectInView.left(), zoneRectInView.top(), zoneRectInView.width(), y - zoneRectInView.top())); break; case kControllerXY: x = xRange(zone.getXKeyPos()); y = yRange(zone.getYKeyPos()); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); // cross-hairs centered on dot MLGL::strokeRect(MLRect(x, zoneRectInView.top(), 0., zoneRectInView.height()), viewScale); MLGL::strokeRect(MLRect(zoneRectInView.left(), y, zoneRectInView.width(), 0.), viewScale); glColor4fv(&dotFill[0]); MLGL::drawDot(Vec2(x, y), smallDotSize*0.25f); break; case kControllerZ: y = yRange(zone.mYRange(zone.getValue(0))); // look at z value over y range glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); MLGL::strokeRect(MLRect(zoneRectInView.left(), y, zoneRectInView.width(), 0.), viewScale); glColor4fv(&activeFill[0]); MLGL::fillRect(MLRect(zoneRectInView.left(), zoneRectInView.top(), zoneRectInView.width(), y - zoneRectInView.top())); break; case kToggle: toggle = zone.getToggleValue(); glColor4fv(&zoneStroke[0]); glLineWidth(thinLineWidth); if(toggle) { MLRect toggleFill = zoneRectInView; Vec2 zoneCenter = zoneRectInView.getCenter(); glColor4fv(&activeFill[0]); MLGL::fillRect(zoneRectInView); glColor4fv(&dotFill[0]); MLGL::drawDot(zoneCenter, smallDotSize*0.25f); } break; } } }
int main(int argc, char *argv[]){ ////// start generatora liczb losowych //// srand(time(0) + getpid()); /// /////////////////////////////////////////// //if (argc==1 && strcmp(argv[1],"-d")==0) log4cxx::PropertyConfigurator::configure("../config/log4cxx.properties"); //AI robotAI2(AppConfig::instance().team2[0], TEAM2); VideoServer::instance().update(); Robot red0(AppConfig::instance().team1[0], TEAM1); Robot red1(AppConfig::instance().team1[1], TEAM1); Robot red2(AppConfig::instance().team1[2], TEAM1); Robot red3(AppConfig::instance().team1[3], TEAM1); Robot blue0(AppConfig::instance().team2[0], TEAM2); Robot blue1(AppConfig::instance().team2[1], TEAM2); Robot blue2(AppConfig::instance().team2[2], TEAM2); Robot blue3(AppConfig::instance().team2[3], TEAM2); while(true){ //cout<<"Update\n"; VideoServer::instance().update(); // VideoServer::instance().display(); red0.makeMove(); // red1.makeMove(); // red2.makeMove(); // red3.makeMove(); // // // blue0.makeMove(); // blue1.makeMove(); // blue2.makeMove(); // blue3.makeMove(); /*Vector2d dest(2,2); Vector2d res; std::cout<<"Planning start\n"; clock_t t1 = clock(); for (long i = 0; i < 1000000; i++){ RRT2 rrt2(AppConfig::instance().team1[0]); rrt2.plan(dest, res); } clock_t t2 = (double) clock() - t1; std::cout<<"Time: "<<(double)t2 / CLOCKS_PER_SEC<<std::endl;*/ } cout<<"While is broken\n"; // // RRTTree rrtTree; // // rrtTree.addNode(Vector2d(0,0), 0); // rrtTree.addNode(Vector2d(2,3), rrtTree.getRoot()); // RRTTreeNode * tmp = rrtTree.addNode(Vector2d(1,0), rrtTree.getRoot()); // rrtTree.addNode(Vector2d(2,1), tmp); // rrtTree.addNode(Vector2d(2,2), tmp); // // RRTTreeNode * node = rrtTree.findNearest(Vector2d(3,3)); // std::cout<<"Nearest: \n"; // std::cout<<node->position<<std::endl; /*GameState gameState("../config/models.xml"); gameState.update(); gameState.display(); std::cout<<"Robot r:\n"; Robot r("omni_red0",TEAM_1, &gameState); LOG4CXX_DEBUG(logger, "( ** START ** ) "); LOG4CXX_DEBUG(logger, "Start time: "<< SimControl::getInstance().getSimTime()); while(true){ //update stanu gry if (gameState.update()) // gameState.display(); r.doTest(); // else usleep(100); //w zaleznosci od stanu gry -> decyzje arbitra //gol -> restart //aut -> ustawienie pilki itp //algorytm robota, oceniajacy stan gry i obliczajacy mozliwe posuniecia //dla kazdego z robotow z mojej druzyny - > obliczanie ruchow //ruch robotow przeciwnika }*/ }