12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- extends Node
- var datafile = "user://SLDEM2015_256_60S_60N_000_360_FLOAT.IMG"
- var samplesPerLine = 92160
- var lines = 30720
- var offset = 1737.4
- var scaleFact = 1
- var resolution = 256
- var latMin = -60
- var latMax = 60
- var lonMin = 0
- var lonMax = 360
- var cache = {}
- var file: File
- # Called when the node enters the scene tree for the first time.
- func open():
- file = File.new()
- file.open(datafile, File.READ)
-
- func close():
- file.close()
- queue_free()
-
- func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN):
- if not _validate(latMinIN,lonMinIN) and not _validate(latMaxIN,lonMaxIN) :
- print("out of scope!")
- return
-
- var lat = latMinIN
- while lat <= latMaxIN:
- cache[lat]={}
- file.seek(lat*resolution*samplesPerLine*4 + lonMinIN*resolution*4)
- var lon = lonMinIN
- while lon <= lonMaxIN:
- cache[lat][lon] = file.get_float()
- lon += 1.0/float(resolution)
- lat += 1.0/float(resolution)
- return
-
- func read(lat,lon):
- if _validate(lat,lon):
- return cache[lat][lon]
- else:
- print("out of scope!")
- func _validate(lat,lon):
- if lat <= latMax and lat >= latMin and lon <= lonMax and lon >= lonMin:
- return true
- return false
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- #func _process(delta):
- # pass
|