Advertisement
Ober3550

Random satellite

Aug 8th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. void AddRandomSatellite(int id) {
  2. if (PlanetOption temp = GetPlanet(id))
  3. {
  4. Planet parent = temp;
  5. const int angles = (360 * 8);
  6. const int steps = 1000;
  7. const float min_dis = 500.f;
  8. const float max_dis = 10000.f;
  9. const float dif_dis = max_dis - min_dis;
  10. const float min_prop = 0.05;
  11. const float max_prop = 0.5f;
  12. const float dif_prop = max_prop - min_prop;
  13. const int mas_step = 1000;
  14. float new_mass = min_prop + float(rand() % mas_step) / mas_step * dif_prop * (*parent.mass);
  15. float angle = float(rand() % angles) / float(angles);
  16. float magni = (min_dis + float(rand() % steps) / float(steps) * dif_dis) * (*parent.mass);
  17. float new_x = (*parent.x) + cos(angle * 2.f * pi) * magni;
  18. float new_y = (*parent.y) + sin(angle * 2.f * pi) * magni;
  19. float new_dx;
  20. float new_dy;
  21. if (rand() & 1)
  22. {
  23. new_dx = (*parent.dx) + cos(angle * 2.f * pi + pi * 0.5f) * 2.f;
  24. new_dy = (*parent.dy) + sin(angle * 2.f * pi + pi * 0.5f) * 2.f;
  25. }
  26. else
  27. {
  28. new_dx = (*parent.dx) + cos(angle * 2.f * pi + pi * 0.5f) * 2.f;
  29. new_dy = (*parent.dy) + sin(angle * 2.f * pi + pi * 0.5f) * 2.f;
  30. }
  31.  
  32. AddPlanet(new_x, new_y, new_dx, new_dy, new_mass);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement