common.gd 959 B

123456789101112131415161718192021222324252627282930313233
  1. extends Node
  2. # spos.x = lat, spos.y=lon, spos.z=height
  3. func latLonToGlobal(spos: Vector3, offset:=Vector3(), origin:=Vector3()):
  4. var height = spos.z + offset.z
  5. var latPos = spos.x
  6. var lonPos = spos.y
  7. var lat = float(latPos+offset.x)*PI/180
  8. var w = cos(lat)
  9. var y = sin(lat)
  10. var lon = float(lonPos+offset.y)*PI/180
  11. var x = sin(lon)
  12. var z = cos(lon)
  13. return Vector3(x * height * w, y*height, z * height * w)-origin
  14. func globalToLatLon(pos: Vector3, offset=Vector3()):
  15. var height=pos.length()
  16. height = height + offset.z
  17. var lon = 0
  18. if pos.z != 0: #and abs(x/z) < 1:
  19. lon = atan(pos.x/pos.z)*180/PI
  20. var lat = sign(pos.y)*90
  21. if abs(pos.y) < height:
  22. lat = asin(pos.y/height)*180/PI
  23. #print("x:"+str(x)+" y:"+str(y)+" z:"+str(z)))
  24. #print("lat:"+str(lat)+" lon:"+str(lon))
  25. return Vector3(lat, lon, height)
  26. #func globalToRad(pos: Vector3):
  27. # var floor_normal = pos - Vector3()
  28. # floor_normal = floor_normal.normalized()
  29. # floor_normal.basis.