2013-06-04 62 views
1

我目前试图做的是在屏幕上远离中心点展开一组点。我目前使用此代码(注意我已经修改这个代码更容易理解):从中心点移动坐标

#d_x - the x coordinate of the dot at its default position 
    #d_y - the y coordinate of the dot at its default position 
    #dis_x - the distance along the x grid the point is away from the centre point 
    #dis_y - the distance along the y grid the point is away from the centre point 
    #zoom_level - the zoom level increased or decreased depending on the mouse wheel 
z_x = (d_x + (dis_x * (1 + (zoom_level * 0.01)))) 
    z_y = (d_y + (dis_y * (1 + (zoom_level * 0.01)))) 
drawText("*",z_x,z_y,) 

此代码几乎工作,唯一的问题是,当zoom_level为0的点是在正确的位置,但是当我增加了缩放级别,使点沿着错误的方向扩展,而不是从中心点向外扩展,而是以相反的方式向中心点移动。

有关如何解决此问题的任何意见将不胜感激。

[编辑] - 我没有说这个,但是每个点都是围绕中心点随机点展开的。

+0

适用于我的机器。见[这里](http://pastebin.com/YvZV6Cxw)。执行100,000次试验时,当增加缩放级别时,点总会从中心点走得更远。 – Kevin

+0

你是如何计算'dis_x'和'dis_y'的? – Kevin

+0

魔法8球:当点向错误方向移动时,您的“缩放级别”具有错误的+/-符号。 – chux

回答

1

我们的中心点有坐标(c_x,c_y)。然后(使用默认缩放= 1)

z_x = c_x + (d_x - c_x) * Zoom 
z_y = c_y + (d_y - c_y) * Zoom 

实施例:中央点(黑色)(2,2),点(蓝色)(3,3)和(0,1) 变焦= 2:新的点(红色)(4,4)和(-2,0) enter image description here

+0

不是很抱歉,他们都聚集在一起,然后随着缩放级别的增加他们移动到屏幕的左上角。 – DeathorGlory9

+0

我确定这些公式是正确的。 – MBo

+0

我可能没有解释清楚,但每个点都散布在随机位置的中心点 – DeathorGlory9