Draw 2.5D or 3D Map with C# from lines

十年热恋 提交于 2019-12-13 05:46:20

问题


I'm developing a turn-by-turn navigation software for Windows Mobile using C# and .NET CF. I'm able to draw a 2D maps by drawing lines. My problem is I would like to get a 2.5D map like in the picture. I tried non-affine transformation on the 2D rendered image but it is too slow for the Windows Mobile device we are targeting. Could anyone give me a clue on my problem?


(source: cartotype.com)


回答1:


Use a perspective transformation, because it will map straight lines to straight lines. More details in this answer.




回答2:


A very basic linear transformation may be sufficient as the viewport is always going to have the same orientation (i.e. "tilt").

Something like:

# assuming 0,0 is top left of screen
w = 320 # screen width
h = 480 # screen height

t1 = 0.75 # scale at top of screen
t2 = 1.25 # scale at bottom of screen

# x,y is the initial point
# x_,y_ is the transformed result
x_ = (x - w/2)*(t1+(y/h)*(t2-t1)) + w/2
y_ = y

This will multiple x by a smaller factor the higher up the screen it is, going from 0.75*x at the top (when y=0) to 1.25*x at the bottom (when y=h). Note that we need to scale x relative to the center of the screen.

This could be made almost as fast as directly drawing the lines, if necessary factoring out the constant expressions and maybe making it use a lookup table.



来源:https://stackoverflow.com/questions/2808393/draw-2-5d-or-3d-map-with-c-sharp-from-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!