sl@cccfr.de 2 years ago
parent
commit
8ee759fe9f
8 changed files with 68 additions and 43 deletions
  1. 25 9
      ChunkSystem.gd
  2. 3 3
      Main.gd
  3. 13 9
      Main.tscn
  4. 9 9
      Player.gd
  5. 4 2
      Tile.gd
  6. 8 7
      TopoLoader.gd
  7. 4 2
      chunk.gd
  8. 2 2
      downloader.gd

+ 25 - 9
ChunkSystem.gd

@@ -4,8 +4,9 @@ var Chunk = preload("res://chunk.tscn")
 onready var Player = $"../Player"
 
 var resolution = 512
-var radius = 1737.4
-var renderDistance = 1
+var scaleFact = 1000
+var radius = 1737.4*scaleFact
+var renderDistance = 0.2
 
 var chunkIndex = {}
 
@@ -17,14 +18,29 @@ func _ready():
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 func _process(delta):
 	var playerSpos = Player.getSpos()
-	var playerRoundSpos = playerSpos.round()
-	var playerChunkPos = Vector2(int(playerRoundSpos.x), int(playerRoundSpos.y))
+	var playerChunkPos = Vector2(int(playerSpos.x), int(playerSpos.y))
 	var playerInterChunkPos = Vector2(playerSpos.x - playerChunkPos.x, playerSpos.y - playerChunkPos.y)
 	
-	for i in [Vector2(1,0),Vector2(1,1),Vector2(0,1),Vector2(-1,0),Vector2(0,-1),Vector2(-1,-1),Vector2(1,-1),Vector2(-1,1)]:
-		var dist = Vector2(playerSpos.x, playerSpos.y).distance_to(playerChunkPos+i+Vector2(0.5,0.5))
-		if dist < renderDistance:
-			add_chunk(playerChunkPos+i)
+	var dir = Vector2()
+	
+	if playerInterChunkPos.x < renderDistance:
+		dir = dir+Vector2(-1,0)
+	elif playerInterChunkPos.x > 1-renderDistance:
+		dir = dir+Vector2(1,0)
+	
+	if playerInterChunkPos.y < renderDistance:
+		dir = dir+Vector2(0,-1)
+	elif playerInterChunkPos.y > 1-renderDistance:
+		dir = dir+Vector2(0,1)
+		
+	add_chunk(playerChunkPos+dir)
+	add_chunk(playerChunkPos+Vector2(0,dir.y))
+	add_chunk(playerChunkPos+Vector2(dir.x,0))
+	
+	#for i in [Vector2(1,0),Vector2(1,1),Vector2(0,1),Vector2(-1,0),Vector2(0,-1),Vector2(-1,-1),Vector2(1,-1),Vector2(-1,1)]:
+	#	var dist = Vector2(playerSpos.x, playerSpos.y).distance_to(playerChunkPos+i)
+	#	if dist < renderDistance:
+	#		add_chunk(playerChunkPos+i)
 
 
 func add_chunk(chunkPos = Vector2()):
@@ -33,7 +49,7 @@ func add_chunk(chunkPos = Vector2()):
 	if chunkIndex.has(lon) and chunkIndex[lon].has(lat):
 		return
 	var chunk = Chunk.instance()
-	chunk.setParams(lat,lat+1,lon,lon+1,resolution,radius)
+	chunk.setParams(lat,lat+1,lon,lon+1,resolution,radius,scaleFact)
 	#moontile.scale=Vector3(1000,1000,1000)
 	.add_child(chunk)
 	if not chunkIndex.has(lon):

+ 3 - 3
Main.gd

@@ -15,8 +15,8 @@ extends Spatial
 #var steplon = 1
 
 #var resolution = 512
-var radius = 1737.4#*1000
-var startPos = Vector3(20,308,radius)
+var radius = 1737.4*1000
+var startPos = Vector3(24,312,radius)
 
 #var curlat = 0
 #var curlon = 0
@@ -44,7 +44,7 @@ func _process(delta):
 	#		curlon = 0
 	#		if curlat >= maxlat:
 	#			print("loading complete")
-
+"background_sky_rotation_degrees"
 
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.

+ 13 - 9
Main.tscn

@@ -1,16 +1,18 @@
-[gd_scene load_steps=10 format=2]
+[gd_scene load_steps=11 format=2]
 
 [ext_resource path="res://Main.gd" type="Script" id=1]
 [ext_resource path="res://Player.gd" type="Script" id=2]
 [ext_resource path="res://ChunkSystem.gd" type="Script" id=3]
+[ext_resource path="res://tex/eso.jpg" type="Texture" id=4]
 
-[sub_resource type="ProceduralSky" id=4]
-sun_latitude = 135.0
-sun_energy = 4.66
+[sub_resource type="PanoramaSky" id=9]
+panorama = ExtResource( 4 )
 
-[sub_resource type="Environment" id=2]
+[sub_resource type="Environment" id=10]
 background_mode = 2
-background_sky = SubResource( 4 )
+background_sky = SubResource( 9 )
+ambient_light_color = Color( 1, 1, 1, 1 )
+glow_enabled = true
 
 [sub_resource type="CapsuleShape" id=8]
 
@@ -31,14 +33,14 @@ __meta__ = {
 }
 
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
-environment = SubResource( 2 )
+environment = SubResource( 10 )
 
 [node name="Player" type="KinematicBody" parent="."]
 script = ExtResource( 2 )
 
 [node name="Camera" type="Camera" parent="Player"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.978945, -0.910777 )
-far = 500.0
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.67414, 0 )
+far = 50000.0
 
 [node name="CollisionShape" type="CollisionShape" parent="Player"]
 transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 )
@@ -57,6 +59,8 @@ material/0 = null
 [node name="SpotLight" type="SpotLight" parent="Player/MeshInstance"]
 transform = Transform( 1, 0, 0, 0, 0.573905, -0.818922, 0, 0.818922, 0.573905, -0.00356923, 0.433873, 1.27676 )
 light_energy = 7.3
+spot_range = 179.547
+spot_angle = 33.3247
 
 [node name="Chunks" type="Spatial" parent="."]
 script = ExtResource( 3 )

+ 9 - 9
Player.gd

@@ -11,7 +11,7 @@ extends KinematicBody
 export (bool) var can_move = true #Alow player to input movment.
 export (bool) var can_sprint = true #Alow player to toggle sprint movment.
 export (float) var move_speed = 8 #Players movement speed
-export (float) var move_speed_sprint = 16 #Players sprint movement speed
+export (float) var move_speed_sprint = 600#16 #Players sprint movement speed
 export (bool) var move_sprint = false #Player sprinting toggle
 export (float) var move_acceleration = 7 #Players acceleration to movment speed
 export (float) var move_deacceleration = 10 #Players deacceleration from movment speed
@@ -27,8 +27,8 @@ export (float) var max_slides = 4 #Maximum of slides
 export (float) var floor_max_angle = 60 #Maximum slop angle player can traverse
 export (bool) var infinite_inertia = false #Toggle infinite inertia
 export (float) var gravaty = 1.625 #9.81 #Gravaty acceleration
-export (Vector3) var gravaty_vector = Vector3(0, -1, 0) #Gravaty normal direction vector
-export (Vector3) var floor_normal = Vector3(0, 1, 0) #Floor normal direction vector
+#export (Vector3) var gravaty_vector = Vector3(0, -1, 0) #Gravaty normal direction vector
+#export (Vector3) var floor_normal = Vector3(0, 1, 0) #Floor normal direction vector
 export (Vector3) var jump_vector = Vector3(0, 1, 0) #Jump normal direction vector
 export (Vector3) var velocity = Vector3(0, 0, 0) #Initial velocity
 
@@ -54,11 +54,11 @@ func getSpos():
 func _process(delta):
 	var pos = self.global_transform.origin
 	.get_parent().get_node("UI/1").text="x:%s y:%s z:%s" %[pos.x, pos.y, pos.z]
-	.get_parent().get_node("UI/2").text="latlonhight: "+str(Common.globalToLatLon(pos))+","+str(pos.length())
+	.get_parent().get_node("UI/2").text="latlonhight: "+str(getSpos())+","+str(pos.length())
 	#.get_parent().get_node("UI/4").text="chunkDist: %s" % get_node("/Tiles").get_child(0).get_global_transform().origin
 
-	floor_normal = pos.normalized()
-	gravaty_vector = floor_normal * -1
+	#floor_normal = pos.normalized()
+	#gravaty_vector = floor_normal * -1
 	#self.transform.basis.y = floor_normal
 	#rotation_degrees.x = 90
 	
@@ -108,10 +108,10 @@ func _physics_process(delta):
 
 	velocity = velocity.linear_interpolate(dir * (move_speed_sprint if move_sprint else move_speed), move_acceleration * delta)
 	if !is_on_floor():
-		velocity += gravaty_vector * gravaty * delta
+		velocity += -up * gravaty * delta
 	velocity = move_and_slide(velocity, up)
 	
-	transform = transform.looking_at(global_transform.origin + forward, up)
+	transform = transform.looking_at(transform.origin + forward, up)
 	
 	
 	#Smooth movement
@@ -137,7 +137,7 @@ func _physics_process(delta):
 func _input(event):
 	#Mouse movement
 	if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
-		rotate_y(deg2rad(-event.relative.x * 0.3))
+		#rotate_y(deg2rad(-event.relative.x * mouse_sensitivity_x))
 		forward = forward.rotated(up, deg2rad(-event.relative.x * mouse_sensitivity_x))
 		#rotate_y(deg2rad(-event.relative.x * mouse_sensitivity_x))
 		#self.rotation_degrees.y += -event.relative.x * mouse_sensitivity_x

+ 4 - 2
Tile.gd

@@ -11,16 +11,18 @@ var lonMin:float = 0.0
 var lonMax:float = 1.0
 var resolution:int = 512
 var radius:float = 10
+var scaleFact:int = 1
 
 var origin:Vector3
 
-func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float):	
+func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float, scaleIN):	
 	latMin = latMinIN
 	latMax = latMaxIN
 	lonMin = lonMinIN
 	lonMax = lonMaxIN
 	resolution = resolutionIN
 	radius = radiusIN
+	scaleFact = scaleIN
 
 func _ready():
 	pass
@@ -138,7 +140,7 @@ func genSphereCoords():
 		for x in range(0,resolution+1):
 			var lat = latMin+latStep*y
 			var lon = lonMin+lonStep*x
-			verts[v_idx] = Vector3(lat, lon, radius+tl.read(lat,lon))
+			verts[v_idx] = Vector3(lat, lon, radius+tl.read(lat,lon)*scaleFact)
 			v_idx+=1
 	tl.close()
 	return verts

+ 8 - 7
TopoLoader.gd

@@ -2,13 +2,13 @@ extends Node
 
 var Downloader = preload("res://downloader.gd")
 
-var filePrefix = "user://topo"
-var formatString = "%s/SLDEM2015_%s_%02d%s_%02d%s_%03d_%03d_FLOAT.IMG"
+var filePrefix = "user://topo/"
+var formatString = "SLDEM2015_%s_%02d%s_%02d%s_%03d_%03d_FLOAT.IMG"
 #              example sldem2015_512_00n_30n_000_045_float.img
 var datafile = "user://topo/sldem2015_512_00n_30n_000_045_float.img"
 var samplesPerLine = 23040
 var lines = 15360
-var offset = 1737.4#*1000
+var offset = 1737.4*1000
 var scaleFact = 1
 var resolution = 512
 
@@ -27,9 +27,10 @@ func open(latMinIN, lonMinIn):
 	lonMin = (int(lonMinIn)/45) * 45
 	lonMax = lonMin+45
 	file = File.new()
-	print("opening topo: "+getFilename())
-	file.open(getFilename(), File.READ)
-	
+	print("opening topo: "+filePrefix+getFilename())
+	var err = file.open(filePrefix+getFilename(), File.READ)
+	if err != 0:
+		Downloader.download(getFilename(), "topo")
 func close():
 	file.close()
 	#queue_free()
@@ -80,7 +81,7 @@ func getFilename():
 		orientation = "N"
 	else:
 		orientation = "S"
-	var properties = [filePrefix, resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
+	var properties = [resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
 	return formatString % properties
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.

+ 4 - 2
chunk.gd

@@ -10,18 +10,20 @@ var lonMin:float = 0.0
 var lonMax:float = 1.0
 var resolution:int = 512
 var radius:float = 10
+var scaleFact:int = 1
 
-func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float):
+func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float, scaleFactIN):
 	latMin = latMinIN
 	latMax = latMaxIN
 	lonMin = lonMinIN
 	lonMax = lonMaxIN
 	resolution = resolutionIN
 	radius = radiusIN
+	scaleFact = scaleFactIN
 	
 # Called when the node enters the scene tree for the first time.
 func _ready():
-	.get_node("Mesh").setParams(latMin, latMax, lonMin, lonMax, resolution, radius)
+	.get_node("Mesh").setParams(latMin, latMax, lonMin, lonMax, resolution, radius, scaleFact)
 	.get_node("Mesh").genMesh()
 	#.translate(.get_node("Mesh").origin)
 

+ 2 - 2
downloader.gd

@@ -1,7 +1,7 @@
 extends HTTPRequest
 
 var kinds = {
-	"height": "http://imbrium.mit.edu/DATA/SLDEM2015/TILES/FLOAT_IMG/%s",
+	"topo": "http://imbrium.mit.edu/DATA/SLDEM2015/TILES/FLOAT_IMG/%s",
 	"color": "" 
 }
 
@@ -11,7 +11,7 @@ func ensureFolder(kind):
 	if not dir.dir_exists(kind):
 		dir.make_dir(kind)
 
-func load(file, kind):
+func download(file, kind):
 	if not kinds.has(kind):
 		print("don't know kind %s"%kind)
 		return