Pārlūkot izejas kodu

fix topoloader southern hemisphere

sl@cccfr.de 2 gadi atpakaļ
vecāks
revīzija
ccb6c805ac
1 mainītis faili ar 26 papildinājumiem un 9 dzēšanām
  1. 26 9
      TopoLoader.gd

+ 26 - 9
TopoLoader.gd

@@ -11,6 +11,7 @@ var lines = 15360
 var offset = 1737.4*1000
 var scaleFact = 1
 var resolution = 512
+var orientation: String = "N"
 
 var latMin = 0
 var latMax = 30
@@ -26,6 +27,11 @@ func open(latMinIN, lonMinIn):
 	latMax = latMin+30
 	lonMin = (int(lonMinIn)/45) * 45
 	lonMax = lonMin+45
+	if latMinIN >= 0:
+		orientation = "N"
+	else:
+		orientation = "S"
+		
 	file = File.new()
 	print("opening topo: "+filePrefix+getFilename())
 	var err = file.open(filePrefix+getFilename(), File.READ)
@@ -47,7 +53,7 @@ func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN):
 	var lat = latMinIN
 	while lat <= latMaxIN:
 		cache[lat]={}
-		var line = lat*resolution*samplesPerLine*4
+		var line = abs(lat)*resolution*samplesPerLine*4
 		# the origin of each .img file lies in it's upper left corner
 		# so we need to read the files from the end on the northern hemisphere
 		if lat >= 0:
@@ -69,19 +75,30 @@ func read(lat,lon):
 		print("out of scope!")
 
 func _validate(lat,lon):
-	if lat <= latMax and lat >= latMin and lon <= lonMax and lon >= lonMin:
-		return true
-	return false
+	var condition = true
+	if abs(lat) > latMax:
+		condition = false
+	if abs(lat) < latMin:
+		condition = false
+	if lon > lonMax:
+		condition = false
+	if lon < lonMin:
+		condition = false
+		
+	return condition
+		
+	#if abs(lat) <= latMax and abs(lat) >= latMin and lon <= lonMax and lon >= lonMin:
+	#	return true
+	#return false
 
 func getFilename():
 	# example sldem2015_512_00n_30n_000_045_float.img
 	#     "%s/sldem2015_%s_%0*d%s_%0*d%s_%00*d_%00*d_float.img"
-	var orientation: String
-	if latMin >= 0:
-		orientation = "N"
+	var properties
+	if orientation == "S":
+		properties = [resolution, latMax, orientation, latMin, orientation, lonMin, lonMax]
 	else:
-		orientation = "S"
-	var properties = [resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
+		properties = [resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
 	return formatString % properties
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.