common.gd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.0
  8. var w = cos(lat)
  9. var y = sin(lat)
  10. var lon = float(lonPos+offset.y)*PI/180.0
  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 : float = 0.0
  18. if pos.z != 0: #and abs(x/z) < 1:
  19. lon = atan2(pos.x,pos.z)*180.0/PI
  20. var lat : float = sign(pos.y)*90.0
  21. if abs(pos.y) < height:
  22. lat = asin(pos.y/height)*180.0/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 relativeToAbsolute(rel = float()):
  27. var absolute = float()
  28. absolute = rel+180-(sign(rel)*180)
  29. return absolute
  30. #func globalToRad(pos: Vector3):
  31. # var floor_normal = pos - Vector3()
  32. # floor_normal = floor_normal.normalized()
  33. # floor_normal.basis.