Reputation: 17866
I'm making sort of a sim city app. In the app, there would be events happening at random times. I want the user to be able to zoom in on that event to get a detailed view.
Without zooming in, the location of the events is just marked an X. If the user zoomed in, user would be able to see more details of the event; ie if it was a car crash, zoomed in the user would see maybe 2+ cars crashing and some animation etc.
The way I want the zoom to work is have user be able to pause the app, move the mouse to the location of the event, the scroll to zoom in/out.
Upvotes: 0
Views: 2296
Reputation: 1179
You could use a 3D to 2D projection function (method) that takes care of zooming (and perspective too), e.g.:
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)
In this case the parameter viewer_distance is used for zooming.
Upvotes: 2