common.gd 705 B

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