Thank you it is working. Maybe I forgot to compile. You are awesome. Now I am working on adding your formula to translate the lng/lat.
Hi again.
I am trying to convert the real world lng/lat to ue xy using your formula but I must be doing something wrong. I know you are busy but if you get a chance can you take a look. Thank you!
Video of problem:
lng lat ue4 - YouTube
Unreal Test Project:
Hey, you have to use this:
this.tile_info.rangeX = this.tile_info.bottomRight.lng-this.tile_info.bottomLeft.lng
this.tile_info.rangeY = this.tile_info.topLeft.lat-this.tile_info.bottomLeft.lat
this.tile_info.translatedXm= (landscapeSize/ this.tile_info.rangeX ) * this.tile_info.middleX
this.tile_info.translatedYm= (landscapeSize/ this.tile_info.rangeY ) * this.tile_info.middleY
The 0,2 was / is the range. Here you have another range when using
Top Left | 47,0401821448067 | -122,34375 |
---|---|---|
Bottom Left | 46,5588603031172 | -122,34375 |
Top Right | 47,0401821448067 | -121,640625 |
Bottom Right | 46,5588603031172 | -121,640625 |
rangeX = 0,703125
rangeY = 0,481321842
and
Xm=-349949,5
Ym=196115,418276882
Sry, I think I did not clarify that correctly.
Another thing: Will the origin of the imported map always be at the right top of the map?
I am not sure. I am importing the map the same way you would if you manually imported the heightmap. I am rotating the heightmap -90 so North lines up with the default way the landscape imports
Adjusted formula
let landscapeSize = this.unrealLandscape.value
//Range
this.tile_info.rangeX = this.tile_info.bottomRight.lng - this.tile_info.bottomLeft.lng
this.tile_info.rangeY = this.tile_info.topLeft.lat - this.tile_info.bottomLeft.lat
//Middle point
this.tile_info.middleX = (this.tile_info.bottomLeft.lng + this.tile_info.bottomRight.lng) / 2
this.tile_info.middleY = (this.tile_info.bottomLeft.lat + this.tile_info.topLeft.lat) / 2
//Translated
this.tile_info.translatedXm = (landscapeSize / this.tile_info.rangeX) * this.tile_info.middleX
this.tile_info.translatedYm = (landscapeSize / this.tile_info.rangeY) * this.tile_info.middleY
//UE XY
this.tile_info.UEx = (landscapeSize / this.tile_info.rangeX) * (this.tile_info.pointLng - this.tile_info.translatedXm)
this.tile_info.UEy = (landscapeSize / this.tile_info.rangeY) * (this.tile_info.pointLat - this.tile_info.translatedYm)
Something is still off.
Yes, i adjust the formula.
Right now, if you rotate your map you’ll get
Map X+ => Unreal Y-
Map Y+ => Unreal X-
I do not have to rotate the heigthmap image. I did this because when you create a new landscape in Unreal it defaults to X up Y right, the opposite of your picture. Because of this default I rotate it so visually it is in the same direction as on the Map.
So I should not rotate the landscape?
I did some further testing. When I create any new level besides the Basic then Y is left and X is up. However, when I create a Basic Level X is up and Y is right. Strange.
Well, in the context of usability:
I think it is easier for the user to just do
Map Y+ = Unreal Y-
instead of
Map X+ => Unreal Y-
Map Y+ => Unreal X-
That could maybe confuse some users
Aaaand: The map size is not 2017x2017 but (2016 * Scale)x(2016 * Scale)
The map size shows the vertices so the one in the middle does not count, sry, but I’ll adjust it.
You just have to tell me if you will rotate or not.
I will change it to not rotate. TY
Ok, can I change this for my instance to? Where do you rotate the map?
I do it when I create the heightmap. I am actually rotating the png file. Give me 5 minutes, and I will change the code and upload a new file.
Here is the new project without rotation
Also Mapbox access key
pk.eyJ1IjoiZGVsZWJhc2giLCJhIjoiY2tzcHQ3OTBuMDY1cTJ1bzV2NWthZ283ZSJ9.9GUzQ2OwKCEuLrLfRNhxbQ
MapOrignUE = Where you set the origin in UE for your landscape
MapsizeUE = number of vertices, here 2017
Scale = scale of the landscape, here 100
MapRangeX = the range in X of the real world map
MapRangeY = the range in Y of the real world map
MapXm, MapYm = Long + Lat of the real world middle
Long=longitude of the point you want to translate
Lat=latitude of the point you want to translate
Xm, Ym = middle of the landscape plane to calculate the new position
XOffset = MapOriginXUE+(((MapSizeUE-1)*Scale)/2)
YOffset = MapOriginYUE+(((MapSizeUE-1)*Scale)/2)
Xm=(((MapSizeUE-1)*Scale)/MapRangeX)*MapXm - XOffset
Ym=(((MapSizeUE-1)*Scale)/MapRangeY)*MapYm + YOffset
Xnew=((MapSizeUE-1)*Scale)/MapRangeX)*Long-Xm
Ynew=(((MapSizeUE-1)*Scale)/MapRangeY)*Lat-Ym)*-1
When we use this map area:
Top Left:
Lat: 47.04018214480666 Lng: -122.34375
Bottom Left:
Lat: 46.55886030311718 Lng: -122.34375
Top Right:
Lat: 47.04018214480666 Lng: -121.640625
Bottom Right:
Lat: 46.55886030311718 Lng: -121.640625
And want to translate Ashford with
46.759758883834984, -122.03424227469101
The new location would be
Xnew=89992.376320
Ynew=117995.321219
when the landscape origin is at
MapOriginXUE=0
MapOriginYUE=0
Thank you let me give it a go.
I tried,
let MapOriginXUE = 0
let MapOriginYUE = 0
let Scale = 100
let MapSizeUE = this.unrealLandscape.value
//Offset XY
let XOffset = MapOriginXUE + (((MapSizeUE - 1) * Scale) / 2)
let YOffset = MapOriginYUE + (((MapSizeUE - 1) * Scale) / 2)
//Real world range XY
let MapRangeX = this.tile_info.bottomRight.lng - this.tile_info.bottomLeft.lng
let MapRangeY = this.tile_info.topLeft.lat - this.tile_info.bottomLeft.lat
// Lat/Lng Center of Bounding Box
let MapXm = this.tile_info.center.lat
let MapYm = this.tile_info.center.lng
//Middle of Landscape plane
let Xm = (((MapSizeUE - 1) * Scale) / MapRangeX) * MapXm - XOffset
let Ym = (((MapSizeUE - 1) * Scale) / MapRangeY) * MapYm + YOffset
//Points to translate
let Lat = this.tile_info.pointLat
let Long = this.tile_info.pointLng
//Lng/Lat Points converted to UE XY
let Xnew = (((MapSizeUE - 1) * Scale) / MapRangeX) * (Long - Xm)
let Ynew = (((MapSizeUE - 1) * Scale) / MapRangeY) * (Lat - Ym) * -1
this.tile_info.UEx = Xnew
this.tile_info.UEy = Ynew
Box is approx. location that point should be at.
I don’t understand the last part. Does it work? Which coordinates did you use?
No. The Unreal X/Y are the Xnew and Ynew. When I input that for the Box coordinates it is way off. Outside of the landscape bounds.