-
-
Notifications
You must be signed in to change notification settings - Fork 56
Closed
Description
It would be useful to have a way to automatically scale the camera to fill a world object on the canvas, for example if we plot a sine wave with small amplitudes it barely shows up unless the camera is scaled appropriately. Doing this automatically would be useful for dynamic scientific plots! I think I can add this functionality to camera.show_object()
and controller.show_object()
, but I couldn't figure out how to map from canvas coordinates to world coordinates w.r.t. the camera.
import numpy as np
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx
canvas = WgpuCanvas()
renderer = gfx.WgpuRenderer(canvas)
scene = gfx.Scene()
xs = np.linspace(0, 30, 100)
ys = np.sin(xs) / 10
zs = np.ones(100)
positions = np.dstack([xs, ys, zs])[0].astype(np.float32)
line = gfx.Line(
gfx.Geometry(positions=positions),
gfx.LineMaterial(thickness=2.0, color=(1, 1, 1, 1)),
)
scene.add(line)
camera = gfx.OrthographicCamera()
controller = gfx.PanZoomController()
controller.add_default_event_handlers(renderer, camera)
controller.show_object(camera, line)
def animate():
controller.update_camera(camera)
renderer.render(scene, camera)
if __name__ == "__main__":
canvas.request_draw(animate)
run()
if you set camear.scale.y = 0.1
:
Metadata
Metadata
Assignees
Labels
No labels