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

2019-09-15 07:46发布

问题:

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.