![](/img/trans.png)
[英]How to zoom in and out of an image pygame and using the mousposition as the center of the zoom
[英]how to zoom in/out using pygame?
我正在制作一個sim城市應用程序。 在應用程序中,會有隨機時間發生的事件。 我希望用戶能夠放大該事件以獲得詳細視圖。
在不放大的情況下,事件的位置僅標記為X.如果用戶放大,用戶將能夠看到事件的更多細節; 即如果是車禍,放大用戶會看到可能有2輛以上的車撞毀,還有一些動畫等。
我希望縮放工作的方式是讓用戶能夠暫停應用程序,將鼠標移動到事件的位置,滾動以放大/縮小。
您可以使用3D到2D投影功能(方法)來處理縮放(和透視),例如:
class Point3D:
def __init__(self, x = 0, y = 0, z = 0):
self.x, self.y, self.z = float(x), float(y), float(z)
...
def project(self, win_width, win_height, fov, viewer_distance, perspective):
"""
Transforms this 3D point to 2D using a perspective projection.
"""
if perspective:
factor = fov / (viewer_distance + self.z)
else:
factor = fov / viewer_distance
x = self.x * factor + win_width / 2
y = -self.y * factor + win_height / 2
return Point3D(x, y, self.z)
在這種情況下,參數viewer_distance用於縮放。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.