Last active
August 29, 2015 13:57
-
-
Save bilke/9801439 to your computer and use it in GitHub Desktop.
WorldComposer Coordinate Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma strict | |
var global_script: global_settings_tc; | |
var latlong_center: latlong_class = new latlong_class(); | |
var terrain_scaling: float = 1.0; | |
var latlong: latlong_class[]; | |
var offset: Vector2 = new Vector2(0,-27); | |
function Start() | |
{ | |
var counter : int = 0; | |
for(var p in latlong){ | |
var pos = calc_position(p.latitude, p.longitude); | |
var go = GameObject.CreatePrimitive(PrimitiveType.Cube); | |
go.transform.position = new Vector3(pos.x, 0, pos.y); | |
Debug.Log(calc_latlong(go.transform.position).x + " : " + calc_latlong(go.transform.position).y); | |
go.name = "Test point " + counter; | |
counter ++; | |
} | |
} | |
function calc_latlong(pos : Vector3) : Vector2 | |
{ | |
var map_pixel: map_pixel_class = new map_pixel_class(); | |
var map_pixel_center: map_pixel_class = global_script.latlong_to_pixel2(latlong_center,19); | |
var map_resolution: double = global_script.calc_latlong_area_resolution(latlong_center,19); | |
map_pixel.x = ((pos.x / terrain_scaling - offset.x) / map_resolution) + map_pixel_center.x; | |
map_pixel.y = (-(pos.z / terrain_scaling - offset.y) / map_resolution) + map_pixel_center.y; | |
var returnVal : latlong_class = global_script.pixel_to_latlong2(map_pixel,19); | |
return Vector2(returnVal.longitude, returnVal.latitude); | |
} | |
function calc_position(lat : double, lon : double) : Vector2 | |
{ | |
var latlong = new latlong_class(lat, lon); | |
var returnVal : Vector2; | |
var map_pixel: map_pixel_class = global_script.latlong_to_pixel2(latlong,19); | |
var map_pixel_center: map_pixel_class = global_script.latlong_to_pixel2(latlong_center,19); | |
var map_resolution: double = global_script.calc_latlong_area_resolution(latlong_center,19); | |
returnVal.x = (map_pixel.x-map_pixel_center.x) * map_resolution * terrain_scaling; | |
returnVal.y = (-map_pixel.y+map_pixel_center.y) * map_resolution * terrain_scaling; | |
returnVal += offset; | |
return returnVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment