[英]When image size change, how do you calculate to counter the real-size coordinate value?
Unity3D中可能有更簡單的方法-我在那里沒有任何經驗-但這聽起來像是一個相當簡單的縮放問題。
您需要了解以下內容:
(width/2, height/2)
1.33f
) 鑒於以上所述,您可以使用簡單的數學計算要觸摸的像素:
public Vector2Int ScaleTouch(Vector2Int imgCentre, Vector2Int dispCentre, float scale, Vector2Int touch)
{
var x = imgCentre.x + (touch.x - dispCentre.x) * scale;
var y = imgCentre.y + (touch.y - dispCentre.y) * scale;
return Vector2Int.RoundToInt(new Vector2(x, y));
}
或者使用Vector2
和Vector2Int
的方法,您可以執行以下操作:
public Vector2Int ScaleTouch(Vector2Int imgCentre, Vector2Int dispCentre, float scale, Vector2Int touch)
{
var offset = Vector2.Scale(touch - dispCentre, new Vector2(scale, scale));
return offset + imgCentre;
}
兩者都假定您的比例在x
和y
是均勻的。 如果希望它靈活地在不同軸上縮放,則可以提供一個縮放向量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.