void BuildMechanism(CompManager &cm, GroupManager &gm) { XMLLoader::SetManagers(&cm, &gm); XMLSaver::SetManagers(&cm, &gm); bool i_want_load_this = false; string mname = "invars"; if (i_want_load_this) XMLLoader::Load("xmls\\"+mname+".xml"); else { cm.AddSegment("Ground", 10000, 0); cm.AddConnectorSlidingD("s0c1","Ground",0.0,-0.150, pi/2); cm.AddConnectorTurnD("s0c2", "Ground", 0.20,0.10); cm.AddConnectorTurnD("s0c3", "Ground", 0.20,0.10); cm.AddSegment("s1"); cm.AddConnectorTurnD("s1c2", "s1", 0.0,0.0); cm.AddConnectorSliding("s1c1","s1",0.0,0.0, 0); cm.AddConnectorSliding("s1c3","s1",0.0,0.0, pi/2); cm.AddConnectorTurnD("s1c4", "s1", 0.0,0.0); cm.AddSegment("s2"); cm.AddConnectorTurn("s2c1", "s2", 0, 0.0); cm.AddConnectorTurn("s2c2", "s2", 0.3, 0.0); cm.AddConnectorTurn("s2c3", "s2", 0.3, 0.0); cm.AddSegment("s3"); cm.AddConnectorTurn("s3c1", "s3", 0, 0.0); cm.AddConnectorTurn("s3c2", "s3", 0.3, 0.0); cm.AddSegment("s4"); cm.AddConnectorTurn("s4c1", "s4", 0, 0); cm.AddConnectorTurn("s4c2", "s4", 0.3, 0); cm.AddConnectorTurn("s4c3", "s4", 0.3, 0); cm.AddSegment("s5"); cm.AddConnectorTurn("s5c1", "s5", 0.0, 0); cm.AddConnectorTurn("s5c2", "s5", 0.3, 0); cm.AddSegment("s6"); cm.AddConnectorTurn("s6c1", "s6", 0, 0); cm.AddConnectorSliding("s6c2", "s6", 0, 0, 0); cm.AddSegment("s7"); cm.AddConnectorTurn("s7c1", "s7", 0, 0); cm.AddConnectorSliding("s7c2", "s7", 0, 0, 0); cm.AddConnectorSliding("s7c3", "s7", 0, 0, 0); cm.AddSegment("s8"); cm.AddConnectorTurn("s8c1", "s8", 0, 0); cm.AddConnectorSliding("s8c2", "s8", 0, 0, 0); cm.AddSegment("s9"); cm.AddConnectorTurn("s9c1", "s9", 0, 0); cm.AddConnectorSliding("s9c2", "s9", 0, 0, 0); cm.AddKPSliding("O", "s0c1", "s1c1"); cm.AddKPTurn("A", "s1c2", "s2c1"); cm.AddKPTurn("B", "s2c2", "s3c1"); cm.AddKPTurn("S", "s3c2", "s0c2"); cm.AddKPTurn("E", "s1c4", "s4c1"); cm.AddKPTurn("D", "s4c2", "s5c1"); cm.AddKPTurn("C", "s5c2", "s0c3"); cm.AddKPSliding("G", "s6c2", "s7c2"); cm.AddKPTurn("F", "s2c3", "s6c1"); cm.AddKPTurn("H", "s4c3", "s7c1"); cm.AddKPSliding("L", "s1c3", "s9c2"); cm.AddKPTurn("M", "s9c1", "s8c1"); cm.AddKPSliding("N", "s8c2", "s7c3"); gm.SetStepSize(0.005); gm.SetMinGC(0); gm.SetMaxGC(6.28); gm.SetJump(true); gm.BuildEdgesSets(); gm.AddFirstGroupByName("O", "Ground", "s1"); gm.Analyze(); XMLSaver::Save("xmls\\"+mname+".xml"); } }
void ProcessAppEvents(sf::RenderWindow &App, sf::View &v, GroupManager &gm) { sf::Event Event; while (App.GetEvent(Event)) { switch (Event.Type) { case sf::Event::Closed: App.Close(); break; case sf::Event::KeyPressed: { switch (Event.Key.Code) { case sf::Key::Escape: App.Close(); break; case sf::Key::Right: case sf::Key::Left: case sf::Key::Up: case sf::Key::Down: { const int step = 5; v = App.GetView(); int hor = 0, ver = 0; if (Event.Key.Code == sf::Key::Left) hor+=step; if (Event.Key.Code == sf::Key::Right) hor-=step; if (Event.Key.Code == sf::Key::Up) ver+=step; if (Event.Key.Code == sf::Key::Down) ver-=step; v.Move(hor, ver); App.SetView(v); break; } case sf::Key::S: case sf::Key::D: { //if (Event.Key.Code == sf::Key::S) // wanna_step_per_second-= wanna_step_per_second/10 - 1; //if (Event.Key.Code == sf::Key::D) // wanna_step_per_second+= wanna_step_per_second/10 + 1; //if (wanna_step_per_second <= 0) // step_per_second = 1; //if (wanna_step_per_second >= 250) // step_per_second = 250; //step_time = 1.0/wanna_step_per_second; break; } case sf::Key::W: case sf::Key::E: { if (Event.Key.Code == sf::Key::E) gm.SetStepSize(gm.GetStepSize() + 0.005); if (Event.Key.Code == sf::Key::W) gm.SetStepSize(gm.GetStepSize() - 0.005); break; } case sf::Key::Z: case sf::Key::X: { if (Event.Key.Code == sf::Key::Z) v.Zoom(1.01); if (Event.Key.Code == sf::Key::X) v.Zoom(1.0/1.01); break; } case sf::Key::A: { step_mode = (STEP_MODE) ((int)SM_HARD_STEPS_CNT + (int)SM_FREE_STEPS_CNT - step_mode); break; } default: break; } break; } case sf::Event::Resized: { int h = Event.Size.Height; int w = Event.Size.Width; v.SetHalfSize(w/2, h/2); break; } default: break; } } }