pygfx.cameras.Camera
- class pygfx.cameras.Camera
Bases:
WorldObject
Abstract base camera.
Camera’s are world objects and be placed in the scene, but this is not required.
The purpose of a camera is to define the viewpoint for rendering a scene. This viewpoint consists of its position and orientation (in the world) and its projection.
In other words, it covers the projection of world coordinates to normalized device coordinates (NDC), by the (inverse of) the camera’s own world matrix and the camera’s projection transform. The former represent the camera’s position, the latter is specific to the type of camera.
- set_view_size(width, height)
Sets the logical size of the target. Set by the renderer; you should typically not use this.
- set_view_offset(full_width: float, full_height: float, x: float, y: float, width: float, height: float)
Set the offset in a larger viewing frustrum and override the logical size.
This is useful for advanced use-cases such as multi-window setups or taking tiled screenshots. It is the responsibility of the caller to make sure that the ratio of the
width
andheight
match that of the canvas/viewport being rendered to, so that the effectivepixel_ratio
is isotropic.# Assuming a canvas with a logical size of 640x480 ... # Use a custom logical size camera.set_view_offset(320, 240, 0, 0, 320, 240) # Render the bottom-left corner, sizes in screen-space become larger (relative to the screen) camera.set_view_offset(640, 480, 0, 240, 320, 240) # Render the bottom-left corner, sizes in screen-space stay the same (relative to the screen) camera.set_view_offset(1280, 960, 0, 480, 640, 480)
- Parameters:
(float) (height)
(float)
(float)
(float)
(float)
(float)
- clear_view_offset()
Remove the currently set view offset, returning to a normal view.
- get_state()
Get the state of the camera as a dict.
- set_state(state)
Set the state of the camera from a dict.