Advertisement
Guest User

Untitled

a guest
Mar 17th, 2015
1,402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. clearscreen.
  2.  
  3. LIST ENGINES in engines.
  4. SET vectors to LIST().
  5.  
  6. set i to 0.
  7. until i = engines:length {
  8. print i.
  9. set pos to engines[i]:position.
  10. vectors:add(VECDRAWARGS(
  11. pos,
  12. engines[i]:facing:forevector * engines[i]:thrust,
  13. RGB(1, 0, 0),
  14. "",
  15. 1.0,
  16. TRUE
  17. )).
  18. set engines[i]:thrustlimit to 100.
  19. set i to i + 1.
  20. }
  21.  
  22. on AG1 {
  23. for vec in vectors {
  24. set vec:show to not (vec:show).
  25. }
  26. set torquevec:show to not (torquevec:show).
  27. PRESERVE.
  28. }
  29.  
  30. set torquevec to VECDRAWARGS(V(0, 0, 0), V(0, 0, 0), RGB(0, 0, 1), "torque", 1.0, TRUE).
  31.  
  32. set exit to false.
  33. on AG9 { set exit to true. }
  34.  
  35. set torques to LIST().
  36. for eng in engines { torques:add(0). }
  37.  
  38. until exit {
  39. set total_torque to V(0, 0, 0).
  40. set i to 0.
  41. until i = engines:length {
  42. set thrust to engines[i]:facing:forevector * engines[i]:maxthrust * engines[i]:thrustlimit / 100.
  43. set torques[i] to VCRS(thrust, engines[i]:position).
  44. set total_torque to total_torque + torques[i].
  45. set vectors[i]:VEC to thrust.
  46. set vectors[i]:START to engines[i]:position.
  47. set i to i + 1.
  48. }
  49.  
  50. set reset to true.
  51. until total_torque:MAG < 1.0 {
  52. if reset {
  53. set total_torque to V(0, 0, 0).
  54. set i to 0.
  55. until i = engines:length {
  56. set engines[i]:thrustlimit to 100.
  57. set thrust to engines[i]:facing:forevector * engines[i]:maxthrust * engines[i]:thrustlimit / 100.
  58. set torques[i] to VCRS(thrust, engines[i]:position).
  59. set total_torque to total_torque + torques[i].
  60. set i to i + 1.
  61. }
  62. set reset to false.
  63. print "Recalculating thrusts".
  64. }
  65. // get engine with lowest angle to current torque, and reduce it's throttle
  66. set lowestAngle to 360.
  67. set lowestEngine to 0.
  68. set i to 0.
  69. until i = engines:length {
  70. set angle to ARCCOS(total_torque * torques[i] / (total_torque:MAG * torques[i]:MAG)).
  71. if angle < lowestAngle {
  72. set lowestAngle to angle.
  73. set lowestEngine to i.
  74. }
  75. set i to i+1.
  76. }
  77.  
  78. set factor to 1 - (total_torque:MAG / (torques[lowestEngine]:mag * COS(lowestAngle))).
  79. //set deltaTorque to torques[i] * (factor - 1).
  80. set engines[lowestEngine]:thrustlimit to engines[lowestEngine]:thrustlimit * factor.
  81. set thrust to engines[lowestEngine]:facing:forevector * engines[lowestEngine]:maxthrust * engines[lowestEngine]:thrustlimit / 100.
  82. set deltaTorque to VCRS(thrust, engines[lowestEngine]:position) - torques[lowestEngine].
  83. set torques[lowestEngine] to torques[lowestEngine] + deltaTorque.
  84. set total_torque to total_torque + deltaTorque.
  85. //set torques[lowestEngine] to VCRS(thrust, engines[lowestEngine]:position).
  86. }
  87.  
  88. set torquevec:VEC to total_torque. // visual
  89. wait 0.1.
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement