scenex.utils.projections#
scenex.utils.projections
#
Utilities for creating projection matrices.
Functions:
-
orthographic–Creates an orthographic projection matrix.
-
perspective–Creates a perspective projection matrix.
-
zoom_to_fit–Adjusts the Camera to fit the entire scene.
orthographic
#
Creates an orthographic projection matrix.
Note that the resulting projection matrix provides no positional offset; this would be out of scope, as such is the job of a camera's transform parameter.
TODO: Consider passing bounds (i.e. a tuple[float, float]) for each parameter. Unfortunately, though, this would effectively allow positional offsets for width and height.
Parameters:
-
(width#float, default:1) –The width of the camera rectangular prism. Must be positive. Default 1 (mirroring the side length of a unit cube).
-
(height#float, default:1) –The height of the camera rectangular prism. Must be positive. Default 1 (mirroring the side length of a unit cube).
-
(depth#float, default:1) –The depth of the camera rectangular prism. Must be positive. The near and far clipping planes of the resulting matrix become (-depth / 2) and (depth / 2) respectively. Default 1, increase (to render things farther away) or decrease (to increase performance) as needed.
TODO: Is this a good default? May want to consider some large number (1000?) instead
Returns:
-
projection(Transform) –A Transform matrix creating an orthographic camera view
Source code in src/scenex/utils/projections.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
perspective
#
Creates a perspective projection matrix.
Note that the resulting projection matrix provides no positional offset; this would be out of scope, as such is the job of a camera's transform parameter.
Parameters:
-
(fov#float) –The field of view of the camera rectangle.
-
(near#float) –The distance from the camera to the near clipping plane.
-
(far#float) –The distance from the camera to the far clipping plane.
Returns:
-
projection(Transform) –A Transform matrix creating a perspective camera view
Source code in src/scenex/utils/projections.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
zoom_to_fit
#
zoom_to_fit(view: View, type: Literal['perspective', 'orthographic'] = 'orthographic', zoom_factor: float = 1.0, letterbox: bool = False) -> None
Adjusts the Camera to fit the entire scene.
Parameters:
-
(view#View) –The view to adjust. Contains the camera, whose parameters will be adjusted, and the scene, whose elements will be considered in the adjustment.
-
(type#Literal['perspective', 'orthographic'], default:'orthographic') –The type of canvas projection to use. Orthographic by default.
-
(zoom_factor#float, default:1.0) –The amount to zoom the scene after adjusting camera parameters. The default, 1.0, will leave the scene touching the edges of the view. As the zoom factor approaches 0, the scene will linearly decrease in size. As the zoom factor increases beyond 1.0, the bounds of the scene will expand linearly beyond the view.
-
(letterbox#bool, default:False) –Whether to letterbox/pillarbox to prevent anisotropic distortion. When True, squares will appear as squares regardless of view dimensions. When False, content may be stretched to fill the view. Default False.
Source code in src/scenex/utils/projections.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |