1234567891011121314151617181920212223242526272829303132333435363738 |
- extends Node
- # spos.x = lat, spos.y=lon, spos.z=height
- func latLonToGlobal(spos: Vector3, offset:=Vector3(), origin:=Vector3()):
- var height = spos.z + offset.z
- var latPos = spos.x
- var lonPos = spos.y
- var lat = float(latPos+offset.x)*PI/180.0
- var w = cos(lat)
- var y = sin(lat)
- var lon = float(lonPos+offset.y)*PI/180.0
- var x = sin(lon)
- var z = cos(lon)
- return Vector3(x * height * w, y*height, z * height * w)-origin
-
- func globalToLatLon(pos: Vector3, offset=Vector3()):
- var height=pos.length()
- height = height + offset.z
- var lon : float = 0.0
- if pos.z != 0: #and abs(x/z) < 1:
- lon = atan2(pos.x,pos.z)*180.0/PI
- var lat : float = sign(pos.y)*90.0
- if abs(pos.y) < height:
- lat = asin(pos.y/height)*180.0/PI
- #print("x:"+str(x)+" y:"+str(y)+" z:"+str(z)))
- #print("lat:"+str(lat)+" lon:"+str(lon))
- return Vector3(lat, lon, height)
-
- func relativeToAbsolute(rel = float()):
- var absolute = float()
- absolute = rel+180-(sign(rel)*180)
- return absolute
- #func globalToRad(pos: Vector3):
- # var floor_normal = pos - Vector3()
- # floor_normal = floor_normal.normalized()
- # floor_normal.basis.
|