common.gd 707 B

1234567891011121314151617181920212223242526
  1. extends Node
  2. func latLonToGlobal(latPos, lonPos, height=1737.4, offset=Vector3()):
  3. height = height + offset.z
  4. var lat = float(latPos+offset.x)*PI/180
  5. var w = cos(lat)
  6. var y = sin(lat)
  7. var u = float(lonPos) / 360
  8. var lon = float(lonPos+offset.y)*PI/180
  9. var x = sin(lon)
  10. var z = cos(lon)
  11. return Vector3(x * height * w, y*height, z * height * w)
  12. func globalToLatLon(x, y, z, height=1737.4, offset=Vector3()):
  13. height = height + offset.z
  14. var lon = 0
  15. if z != 0: #and abs(x/z) < 1:
  16. lon = atan(x/z)*180/PI
  17. var lat = sign(y)*90
  18. if abs(y) < height:
  19. lat = asin(y/height)*180/PI
  20. #print("x:"+str(x)+" y:"+str(y)+" z:"+str(z)))
  21. #print("lat:"+str(lat)+" lon:"+str(lon))
  22. return Vector2(lat, lon)