Explorar el Código

simplification

sl@cccfr.de hace 3 años
padre
commit
db4e93fba5
Se han modificado 6 ficheros con 134 adiciones y 33 borrados
  1. 24 15
      Main.gd
  2. 46 0
      Main.tscn
  3. 12 1
      Player.gd
  4. 16 10
      Tile.gd
  5. 25 0
      common.gd
  6. 11 7
      project.godot

+ 24 - 15
Main.gd

@@ -6,27 +6,36 @@ extends Spatial
 # var b = "text"
 var tileGenScene = preload("res://TileGenerator.tscn")
 
-# Called when the node enters the scene tree for the first time.
+
+var minlat = 0
+var maxlat = 10
+var minlon = 0
+var maxlon = 5
+
+var curlat = 0
+var curlon = 0
+
 func _ready():
-	for y in range(0,10):
-		for x in range(0,5):
+	curlat = minlat
+	curlon = minlon
+
+func _process(delta):
+	if curlat < maxlat:
+		if curlon < maxlon:
 			var moontile = tileGenScene.instance()
-			moontile.init(y,x)
+			moontile.init(curlat,curlon)
 			#moontile.scale=Vector3(1000,1000,1000)
 			$Tiles.add_child(moontile)
+			.get_node("UI/3").text="LatLon=="+str(Common.latLonToGlobal(curlat,curlon))
+			curlon += 1
+		else:
+			curlat +=1
+			curlon = 0
+			if curlat >= maxlat:
+				print("loading complete")
 
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 #func _process(delta):
 #	pass
-func latLonToGlobal(latPos, lonPos, offset=Vector3()):
-	var height = 1737.4 + offset.z
-	var lat = float(latPos+offset.x)*PI/180
-	var w = cos(lat)
-	var y = sin(lat)
-	var u = float(lonPos) / 360
-	var lon = float(lonPos+offset.y)*PI/180
-	var x = sin(lon)
-	var z = cos(lon)
-	return Vector3(x * height * w, y*height, z * height * w)
-			
+

+ 46 - 0
Main.tscn

@@ -37,3 +37,49 @@ light_energy = 11.83
 
 [node name="Tiles" type="Spatial" parent="."]
 transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -96.8491, 0, 3.33984 )
+
+[node name="UI" type="Control" parent="."]
+margin_right = 40.0
+margin_bottom = 40.0
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="1" type="TextEdit" parent="UI"]
+margin_right = 333.0
+margin_bottom = 40.0
+rect_pivot_offset = Vector2( 186, 75 )
+text = "1"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="2" type="TextEdit" parent="UI"]
+margin_left = 397.0
+margin_top = 1.0
+margin_right = 789.0
+margin_bottom = 41.0
+rect_pivot_offset = Vector2( 33, 74 )
+text = "2"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="3" type="TextEdit" parent="UI"]
+margin_top = 44.0
+margin_right = 331.0
+margin_bottom = 84.0
+text = "3"
+__meta__ = {
+"_edit_use_anchors_": false
+}
+
+[node name="4" type="TextEdit" parent="UI"]
+margin_left = 396.0
+margin_top = 47.0
+margin_right = 789.0
+margin_bottom = 87.0
+text = "4"
+__meta__ = {
+"_edit_use_anchors_": false
+}

+ 12 - 1
Player.gd

@@ -9,6 +9,8 @@ var minLookAngle : float = -90.0
 var maxLookAngle : float = 90.0
 var lookSensitivity : float = 10.0
 
+var ray: RayCast
+
 # vectors
 var vel : Vector3 = Vector3()
 var mouseDelta : Vector2 = Vector2()
@@ -16,7 +18,9 @@ var mouseDelta : Vector2 = Vector2()
 onready var camera : Camera = get_node("Camera")
 
 func _ready():
-	move_and_slide(Vector3(60.503445, 30.231335, 1734.286987) + Vector3(0,0,10), Vector3.UP)
+	move_and_slide(Common.latLonToGlobal(0,0,1800.4), Vector3.UP)
+	ray = RayCast.new()
+	.get_parent().add_child(ray)
 
 func _process(delta):
 	# rotate the camera along the x axis
@@ -78,5 +82,12 @@ func _physics_process(delta):
 	
 	# move the player
 	vel = move_and_slide(vel, Vector3.UP)
+	#ray = ray.look_at(self.global_transform.origin, Vector3.UP)
+	
+	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]
+	var polPos = Common.globalToLatLon(pos.x,pos.y,pos.z)
+	.get_parent().get_node("UI/2").text="lat:%s lon:%s" %[polPos.x, polPos.y]
+	#.get_node("UI/3").text="LatLonPos=="+str(latLonToGlobal( self.global_transform.origin.x,self.global_transform.origin.y))
 	

+ 16 - 10
Tile.gd

@@ -38,6 +38,8 @@ func _ready():
 	var material=SpatialMaterial.new()
 	material.albedo_texture = texture
 	.set_material_override(material)
+	#print("creating collition...")
+	#.create_trimesh_collision()
 		
 func genMesh():
 	var file = File.new()
@@ -85,7 +87,8 @@ func genMesh():
 
 	var vert = Vector3()
 	# Loop over rings.
-	for latPos in range(latMin*resolution, latMax*resolution):
+	for latPos in range(float(latMin)*resolution, float(latMax)*resolution):
+		var latCur = float(latPos)/float(resolution)
 		#jump to    last line in file   -   current local lat    -      local startLat     +  local startLon
 		file.seek(lines*samplesPerLine*4-latPos*samplesPerLine*4 - latMin*samplesPerLine*4 + lonMin*resolution*4)
 		#file.seek(latPos*samplesPerLine*4 + latMin*samplesPerLine*4 + lonMin*resolution*4)
@@ -93,20 +96,23 @@ func genMesh():
 		#file.seek(((latMax*resolution-1-latPos)*samplesPerLine + lonMin*resolution)*4)
 		#var v = float(latPos-latMin*resolution) / ((latMax-latMin) * resolution)
 		var v = float(latPos-latMin*resolution) / ((latMax-latMin) * resolution)
-		var lat = float(latPos)*PI/(resolution*180)
-		var w = cos(lat)
-		var y = sin(lat)
+		#var lat = float(latPos)*PI/(resolution*180)
+		#var w = cos(lat)
+		#var y = sin(lat)
 		#print(v*100, "%")
 
 		# Loop over segments in ring.
-		for lonPos in range(lonMin*resolution, lonMax*resolution):
+		for lonPos in range(float(lonMin)*resolution, float(lonMax)*resolution):
+			var lonCur = float(lonPos)/float(resolution)
 			var u = float(lonPos-lonMin*resolution) / ((lonMax - lonMin) * resolution)
-			var lon = float(lonPos)*PI/(resolution*180)
-			var x = sin(lon)
-			var z = cos(lon)
+			#var lon = float(lonPos)*PI/(resolution*180)
+			#var x = sin(lon)
+			#var z = cos(lon)
 			#print("Lon: ", lon)
-			var height = file.get_float()/offset*radius+radius
-			vert = Vector3(scaleFact * x * height * w, scaleFact * y*height, scaleFact * z * height * w)
+			#var height = file.get_float()/offset*radius+radius
+			var height = file.get_float()+radius
+			vert = Common.latLonToGlobal(latCur, lonCur, height)
+			#vert = Vector3(scaleFact * x * height * w, scaleFact * y*height, scaleFact * z * height * w)
 			verts[point] = vert
 			normals[point] = vert.normalized()
 			uvs[point] = Vector2(u, 1-v)

+ 25 - 0
common.gd

@@ -0,0 +1,25 @@
+extends Node
+
+
+func latLonToGlobal(latPos, lonPos, height=1737.4, offset=Vector3()):
+	height = height + offset.z
+	var lat = float(latPos+offset.x)*PI/180
+	var w = cos(lat)
+	var y = sin(lat)
+	var u = float(lonPos) / 360
+	var lon = float(lonPos+offset.y)*PI/180
+	var x = sin(lon)
+	var z = cos(lon)
+	return Vector3(x * height * w, y*height, z * height * w)
+			
+func globalToLatLon(x, y, z, height=1737.4, offset=Vector3()):
+	height = height + offset.z
+	var lon = 0
+	if z != 0: #and abs(x/z) < 1:
+		lon = atan(x/z)*180/PI
+	var lat = sign(y)*90
+	if abs(y) < height:
+		lat = asin(y/height)*180/PI
+	#print("x:"+str(x)+" y:"+str(y)+" z:"+str(z)))
+	#print("lat:"+str(lat)+" lon:"+str(lon))
+	return Vector2(lat, lon)

+ 11 - 7
project.godot

@@ -14,41 +14,45 @@ config/name="Moon"
 run/main_scene="res://Main.tscn"
 config/icon="res://icon.png"
 
+[autoload]
+
+Common="*res://common.gd"
+
 [input]
 
 move_forward={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }
 move_backward={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }
 move_left={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }
 move_right={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }
 move_up={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }
 move_down={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777238,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777238,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }
 sprint={
 "deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
  ]
 }