2010-05-11 105 views

回答

0

使用透视变换,因为它会将直线映射到直线。更多详情,请参阅this answer

1

一个非常基本的线性变换可以是足够的视口总是要具有相同的方向(即“倾斜”)。

是这样的:

# 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 

这将多个x通过一个较小的因数越往上屏幕是,在顶部(当y=0)至1.25*x0.75*x打算在底部(当y=h)。请注意,我们需要相对于屏幕中心缩放x

这可以做得几乎和直接绘制直线一样快,如果有必要的话,可以分解常量表达式,也可以使用查找表。

+0

我正面临一个新的问题与您的答案。当y> = 0且y <= h时,它工作得很好。但有时候y < 0 or y > h则线条变得不规则。你能帮我解决这个问题吗? – VOX 2010-09-05 19:26:03

+0

也许尝试'x_ =(x-w/2)* min(t2,max(t1,t1 +(y/h)*(t2-t1)))+ w/2'或类似的东西来防止x_也被扭曲当y离开屏幕的时候很多。 – Tom 2010-09-06 08:40:00