开发者

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

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 transfo开发者_JS百科rmation 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?

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

(source: cartotype.com)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜