views:

305

answers:

2

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?

example image

+1  A: 

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.

Tom
I'm facing a new problem with your answer. It works very well when y >= 0 and y <= h. But there are situations when y < 0 or y > h then the line become irregular. Could you please help me with this again?
VOX
Maybe try `x_ = (x - w/2)*min(t2,max(t1, t1+(y/h)*(t2-t1))) + w/2` or something similar to prevent x_ being warped too much when y is off the screen.
Tom
A: 

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

brainjam