Advertisement
Guest User

je_2

a guest
Apr 1st, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.38 KB | None | 0 0
  1. #include "pugixml.hpp"
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <conio.h>
  8.  
  9.  
  10.  
  11. using namespace std;
  12. using namespace pugi;
  13.  
  14.  
  15.  
  16. struct Frame
  17. {
  18.     //Pozycja
  19. struct Pos
  20. {
  21. float x;
  22. float y;
  23. float w;
  24. } pos;
  25. //Prędkosc
  26. struct Vel
  27. {
  28. float vx;
  29. float vy;
  30. float vw;
  31. } vel;
  32. //Przyspieszenie
  33. struct Acc
  34. {
  35. float accx;
  36. float accy;
  37. float accw;
  38. } acc;
  39.  
  40. string opis;
  41. };
  42. //KONIEC STRUKTUR
  43.  
  44. //Predkosc maksymalna
  45. int vmax(vector<Frame> w)
  46. {
  47. double a=0;
  48. int b=0;
  49. int x=0;
  50. for (unsigned i=0; i<w.size(); i++)
  51. {
  52. if(w[i].vel.vw>a)
  53. {
  54. a=w[i].vel.vw;
  55. x=b;
  56. }
  57. b++;
  58. }
  59. return x;}
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. class Samochod
  67. {
  68. public:
  69. vector<Frame> ramki; //Wektor ramek samochodu
  70. static const int dt=40; //Co 40ms
  71. int numer; //Numer pojazdu
  72. double v_max;
  73.  
  74. //Wczytanie z pliku i sorawdzanie -if
  75. bool load(string name)
  76. {
  77. xml_document doc;
  78. xml_parse_result result;
  79. result=doc.load_file(name.c_str());
  80. if(result.status!=status_ok)
  81. return false;
  82. xml_node root=doc.first_child();
  83. xml_node frames=root.first_child();
  84. xml_node frame=frames.first_child();
  85. xml_node pos=frame.child("pos");
  86.  
  87. Frame ramka;
  88. unsigned i=0;
  89.  
  90.  
  91. //Wczytanie XML'a
  92. while(true)
  93. {
  94. if (i)frame=frame.next_sibling();
  95. pos=frame.child("pos");
  96. i++;
  97.  
  98. if(!frame) break;
  99. ramka.pos.x=atof( pos.child("x").child_value() );
  100. ramka.pos.y=atof( pos.child("y").child_value() );
  101. ramka.pos.w=sqrt( ramka.pos.x*ramka.pos.x + ramka.pos.y*ramka.pos.y); //wypadkowa
  102. ramki.push_back(ramka);
  103. }
  104. return true;
  105. }
  106.  
  107.  
  108. bool wprint(unsigned a, unsigned b)
  109.     {
  110.         if( a>b || a>ramki.size() || b>=ramki.size() )
  111.             return false;
  112.         for (unsigned i=a;i<=b;i++)
  113.             cout<<ramki[i].pos.x<<" \t "<<ramki[i].pos.y<<" \t "<<ramki[i].vel.vx<<" \t "<<ramki[i].vel.vy<<" \t "<<ramki[i].vel.vw<<" \t "<<ramki[i].opis<<endl;
  114.         return true;
  115.     }
  116.  
  117.     void wprint()
  118.     {
  119.         for (unsigned i=0;i<ramki.size();i++)
  120.             cout<<ramki[i].pos.x<<" \t "<<ramki[i].pos.y<<" \t "<<ramki[i].vel.vx<<" \t "<<ramki[i].vel.vy<<" \t "<<ramki[i].vel.vw<<" \t "<<ramki[i].opis<<endl;
  121.     }
  122.  
  123. //Policzenie predkosci
  124. void calc_inst_vel()
  125. {
  126. ramki[0].vel.vx=0;
  127. ramki[0].vel.vy=0;
  128. ramki[0].vel.vw=0;
  129.  
  130. for (unsigned i=1; i<ramki.size(); i++)
  131. {
  132. ramki[i].vel.vx=25*(ramki[i].pos.x-ramki[i-1].pos.x)/dt;
  133. ramki[i].vel.vy=25*(ramki[i].pos.y-ramki[i-1].pos.y)/dt;
  134. double a = ramki[i].vel.vx*ramki[i].vel.vx +
  135. ramki[i].vel.vy*ramki[i].vel.vy;
  136. ramki[i].vel.vw=sqrt(a);
  137. }
  138. }
  139.  
  140.  
  141. //Predkosc maksymalna
  142. void calc_max_vel()
  143. {
  144. v_max=ramki[vmax(ramki)].vel.vw;
  145. }
  146.  
  147.  
  148.  
  149. bool nowy_pojazd(string name, int number)
  150. {
  151. if(!load(name)) return false;
  152. numer=number;
  153. calc_inst_vel();
  154. calc_max_vel();
  155. //calc_acc();
  156. //zmiany_ruchu();
  157. return true;
  158. }
  159.  
  160.  
  161.  
  162. };
  163. //KONIEC KLASY SAMOCHOD
  164.  
  165. bool sortuj_1(Samochod a, Samochod b)
  166. {
  167. return a.v_max<b.v_max;
  168. }
  169.  
  170.  
  171. void sortuj_2(vector<Samochod> &samochody)
  172. {
  173. sort(samochody.begin(), samochody.end(), sortuj_1);
  174. }
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. int main()
  182. {
  183.     cout<<"hello";
  184.  
  185.  
  186.     vector<Samochod> pojazdy;
  187.  
  188.     //Odczytanie XML'i
  189.     for (unsigned i=0;;i++)
  190. {
  191. Samochod pojazd;
  192. string name=" pojazd";
  193. name+=to_string(i+1);
  194. name+=".xml";
  195. if(!pojazd.nowy_pojazd(name.c_str(), i+1)) break;
  196. pojazdy.push_back(pojazd);
  197. }
  198.  
  199.  
  200.     //Wywolanie sortowania
  201.     sortuj_2 (pojazdy);
  202.  
  203.  
  204.     //Wyswietlenie
  205.     for (int j=0; j>=pojazdy.size(); j++)
  206.     {
  207.         pojazdy[j].wprint();
  208.         _getch();
  209.     }
  210.    
  211.  
  212.  
  213.     _getch();
  214. return 0;
  215.  
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement