2013-06-04 63 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