I want to map google map images to 3d planes using world coordinates.
So first i convert lat/lon to world coords and then i create plane/mesh/material/texture/entity for all the images.
Finaly i place the 3D camera x/y position to the actual world coordinates.
Problem is the Y axis seems to be flipped in 3D, see this example, line 49 MoveEntity (commented) should be right but using this line it get's flipped:
Code: Select all
; Maps Engine3D coords test
InitEngine3D(): InitSprite(): InitKeyboard(): InitMouse(): UseJPEGImageDecoder()
; structure
Structure maps
img.l
ent.l
mat.l
txt.l
EndStructure
Global NewMap map3d.maps()
; open window/screen
If OpenWindow(0, 0, 0, 1024, 768, "Maps test 3D Engine", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered )
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #True, 0, 0, #PB_Screen_NoSynchronization )
; define some vars ..
pathmaps.s = "https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}"
zoom.l = 18
lat.d = 52.370216
lon.d = 4.895168
camzoom = 0
; convert lat/lon to world coords
n.d = Pow(2.0, zoom)
LatRad.d = Radian(lat)
px.d = n * (Mod( lon + 180.0, 360) / 360.0 )
py.d = n * ( 1.0 - Log(Tan(LatRad) + (1.0/Cos(LatRad))) / #PI ) / 2.0
; create 3d stuff
CreateCamera(0, 0, 0, 100, 100)
msh.l = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
num.l = 2 ; amount of tiles left/right above/below
For y = -num To num
For x = -num To num
id.s = "" + Int(px) + x + "x" + Int(py) + y
url.s = ReplaceString(pathmaps.s, "{z}", ""+zoom+"")
url.s = ReplaceString(url.s, "{x}", ""+Int(px+x)+"")
url.s = ReplaceString(url.s, "{y}", ""+Int(py+y)+"")
HttpRequest = HTTPRequestMemory(#PB_HTTP_Get, url.s)
If HttpRequest
*Response = HTTPMemory(HTTPRequest)
map3d(id.s)\img = CatchImage(#PB_Any, *Response, MemorySize(*Response))
FreeMemory(*Response)
If IsImage(map3d(id.s)\img)
map3d(id.s)\txt = CreateTexture(#PB_Any, 256, 256)
StartDrawing(TextureOutput(map3d(id.s)\txt))
DrawImage(ImageID(map3d(id.s)\img), 0, 0)
StopDrawing()
map3d(id.s)\mat = CreateMaterial(#PB_Any, TextureID(map3d(id.s)\txt))
DisableMaterialLighting(map3d(id.s)\mat, #True)
map3d(id.s)\ent = CreateEntity(#PB_Any, MeshID(msh), MaterialID(map3d(id.s)\mat))
RotateEntity(map3d(id.s)\ent, -90.0, 0.0, 180.0, #PB_Absolute)
;MoveEntity(map3d(id.s)\ent, Int(px) + x, Int(py) + y, 0, #PB_Absolute) ; THIS SHOULD BE USED BUT THEN ALL Y LINES ARE FLIPPED
MoveEntity(map3d(id.s)\ent, Int(px) + x, Int(py) - y, 0, #PB_Absolute)
EndIf
FinishHTTP(HTTPRequest)
EndIf
Next
Next
; loop ..
Repeat
wevent = WindowEvent()
If ExamineMouse()
mw = MouseWheel(): camzoom = camzoom + (-MouseWheel() * 2)
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
wevent = #PB_Event_CloseWindow
EndIf
EndIf
MoveCamera(0, px, py, 10 + camzoom, #PB_Absolute)
RenderWorld()
FlipBuffers()
Until wevent = #PB_Event_CloseWindow
EndIf
End
I could add a example of that also if needed, help!