Advertisement
Guest User

Untitled

a guest
May 30th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. function horizontalLine {
  2. parameter line.
  3. local i is 0.
  4. until i = terminal:width {
  5. print "-" at (i,line).
  6. set i to i + 1.
  7. }
  8. }
  9. function vecs_clear {
  10. if vecs:length > 0 {
  11. for vd in vecs {
  12. set vd:SHOW TO false.
  13. }
  14. vecs:clear.
  15. }
  16. }
  17. // set [variable] to vecs_add([position],[vector],[color],[string]).
  18. // returns: list index.
  19. // example:
  20. // Create a vecdraw:
  21. // set velocityVec to vecs_add(ship:position,velocity:orbit,blue,round(velocity:orbit:mag) + " m/s").
  22. // Update it's starting position:
  23. // set vecs[velocityVec]:start to ship:position.
  24. function vecs_add {
  25. parameter p,v,c,descr.
  26. vecs:add(VECDRAWARGS(p, v, c, descr, 1, true)).
  27. return vecs:length - 1.
  28. }
  29.  
  30. global vecs is list().
  31. if vecs:length > 0 vecs_clear().
  32.  
  33. ////////////////////// end of library functions ////////////////////////////
  34.  
  35.  
  36. clearscreen. ag1 off.
  37. print " ".
  38. print " ".
  39. print " ".
  40. horizontalLine(3).
  41. print " ".
  42. print " ".
  43.  
  44. //vecs initialize
  45. local northV is vxcl(up:vector,north:vector):normalized.
  46. local eastV is -vcrs(northV,up:vector):normalized.
  47. //local markN is vecs_add(v(0,0,0),northV*3,rgb(0,0.8,1),"N").
  48. //local markE is vecs_add(v(0,0,0),eastV*3,rgb(0,0.5,1),"E").
  49. //local markCP is vecs_add(v(0,0,0),v(0,0,0),rgb(1,1,0),"CP").
  50. local markGeo is vecs_add(v(0,0,0),v(0,0,0),rgb(1,1,1),"GeoPos").
  51. //local markCPn is vecs_add(v(0,0,0),v(0,0,0),rgb(1,0.5,0),"CPn").
  52. //local markCPe is vecs_add(v(0,0,0),v(0,0,0),rgb(1,0.5,0),"CPe").
  53. local markPole is vecs_add(v(0,0,0),v(0,0,0),rgb(1,0.0,0),"POLE").
  54. local markLaser is vecs_add(v(0,0,0),v(0,0,0),rgb(1,0,0),"").
  55. local markNormal is vecs_add(v(0,0,0),v(0,0,0),rgb(1,0,1),"").
  56. local markP1 is vecs_add(v(0,0,0),v(0,0,0),rgb(1,1,1),"").
  57. local markP2 is vecs_add(v(0,0,0),v(0,0,0),rgb(1,1,1),"").
  58.  
  59. function getPlaneNormal {
  60. parameter p1,p2,p3.
  61. local vec1 is p2-p1.
  62. local vec2 is p3-p1.
  63. return vcrs(vec1,vec2):normalized.
  64. }
  65.  
  66. function getGeoPosition {
  67. parameter checkpos. //position relative to ship at which to check terrain height
  68. local northV is vxcl(up:vector,north:vector):normalized.
  69. local eastV is -vcrs(north:vector,up:vector):normalized.
  70.  
  71. local checkposN is northV * vdot(checkpos, northV). // above split into north and east vectors
  72. local checkposE is eastV * vdot(checkpos, eastV).
  73. local angN is vang(up:vector, checkposN-body:position).
  74. local angE is vang(vxcl(body:angularvel,up:vector), vxcl(body:angularvel,(checkposE-body:position))).
  75.  
  76. if vdot(checkpos, northV) < 0 set angN to angN * -1. //negative lat change if heading south
  77. if vdot(checkpos, eastV) < 0 set angE to angE * -1. //negative lng change if heading west
  78.  
  79. //checkposition's lat and lng
  80. local cpLat is latitude + angN.
  81. local cpLng is longitude + angE.
  82. //overshoot protection:
  83. //if cpLat > 90 { set cpLat to 90 - (cpLat-90). set cpLng to 1 * cpLng. }
  84. //else if cpLat < -90 { set cpLat to -90 - (cpLat+90). set cpLng to 1 * cpLng.}
  85. if cpLng > 180 set cpLng to -180 + (cpLng - 180).
  86. else if cpLng < -180 set cpLng to 180 + (cpLng + 180).
  87.  
  88. //return geoposition
  89. return latlng(cpLat,cpLng).
  90. }
  91.  
  92. until ag1 {
  93.  
  94. local horV is vxcl(up:vector,velocity:surface).
  95. local checkpos is ship:position + (horV * 10). //position at which to check terrain height
  96.  
  97. local cpGeoPos is getGeoPosition(checkpos). //geoposition structure
  98. local cpHeight is cpGeoPos:terrainheight. //terrain height above/below sealevel
  99.  
  100. //terrain normal stuff
  101. local posUp is (cpGeoPos:position - body:position):normalized.
  102. local forwardV is vxcl(posUp,velocity:surface):normalized.
  103. local rightV is vcrs(forwardV,posUp):normalized.
  104.  
  105. local point1 is getGeoPosition(checkpos + forwardV * 45 + rightV * 30).
  106. local point2 is getGeoPosition(checkpos + forwardV * 45 - rightV * 30).
  107. local terrainNormal is getPlaneNormal(cpGeoPos:position,point1:position,point2:position).
  108.  
  109.  
  110. //vecs debug
  111. //set vecs[markN]:start to facing:starvector:normalized * 10.
  112. //set vecs[markE]:start to facing:starvector:normalized * 10.
  113.  
  114. //set vecs[markCP]:vec to checkpos.
  115. //set vecs[markCPn]:vec to checkposN.
  116. //set vecs[markCPe]:vec to checkposE.
  117.  
  118. set vecs[markPole]:start to body:position - (body:angularvel:normalized * (body:radius + 50000)).
  119. set vecs[markPole]:vec to body:angularvel:normalized * (body:radius*2 + 100000).
  120.  
  121. set vecs[markGeo]:vec to posUp * 5. //(checkpos - cpGeoPos:position):mag.
  122. set vecs[markGeo]:start to cpGeoPos:position.
  123. set vecs[markGeo]:label to round(cpHeight-altitude) + "m".
  124.  
  125. set vecs[markP1]:vec to posUp * 5.
  126. set vecs[markP2]:vec to posUp * 5.
  127. set vecs[markP1]:start to point1:position.
  128. set vecs[markP2]:start to point2:position.
  129.  
  130. set vecs[markLaser]:vec to cpGeoPos:position.
  131. set vecs[markNormal]:vec to terrainNormal*300.
  132. set vecs[markNormal]:start to cpGeoPos:position.
  133. set vecs[markNormal]:label to round(vang(posUp,terrainNormal),1) + " deg".
  134.  
  135. //Terminal window readouts
  136. print "Lat: " + latitude + " " at (0,0).
  137. //print "Ang: " + angN + " " at (round(terminal:width/2),0).
  138.  
  139. print "Lng: " + longitude + " " at (0,1).
  140. //print "Ang: " + angE + " " at (round(terminal:width/2),1).
  141. //---
  142. print "Alt Rad: " + round(alt:radar/1000,3) + "km " at (0,4).
  143.  
  144. print "Alt CP: " + round((altitude-cpHeight)/1000,3) + "km " at (0,5).
  145. print "Ter Hgt: " + round(cpHeight/1000,3) + "km " at (round(terminal:width/2),5).
  146.  
  147.  
  148.  
  149. wait 0.
  150. }
  151. vecs_clear().
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement