@@ -70,14 +70,24 @@ pub struct ComputedCameraValues {
70
70
target_info : Option < RenderTargetInfo > ,
71
71
}
72
72
73
+ /// The defining component for camera entities, storing information about how and what to render
74
+ /// through this camera.
75
+ ///
76
+ /// The [`Camera`] component is added to an entity to define the properties of the viewpoint from
77
+ /// which rendering occurs. It defines the position of the view to render, the projection method
78
+ /// to transform the 3D objects into a 2D image, as well as the render target into which that image
79
+ /// is produced.
80
+ ///
81
+ /// Adding a camera is typically done by adding a bundle, either the `Camera2dBundle` or the
82
+ /// `Camera3dBundle`.
73
83
#[ derive( Component , Debug , Reflect , FromReflect , Clone ) ]
74
84
#[ reflect( Component ) ]
75
85
pub struct Camera {
76
86
/// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`].
77
87
pub viewport : Option < Viewport > ,
78
88
/// Cameras with a lower priority will be rendered before cameras with a higher priority.
79
89
pub priority : isize ,
80
- /// If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this
90
+ /// If this is set to ` true` , this camera will be rendered to its specified [`RenderTarget`]. If ` false` , this
81
91
/// camera will not be rendered.
82
92
pub is_active : bool ,
83
93
/// Computed values for this camera, such as the projection matrix and the render target size.
@@ -305,6 +315,21 @@ impl RenderTarget {
305
315
}
306
316
}
307
317
318
+ /// System in charge of updating a [`Camera`] when its window or projection changes.
319
+ ///
320
+ /// The system detects window creation and resize events to update the camera projection if
321
+ /// needed. It also queries any [`CameraProjection`] component associated with the same entity
322
+ /// as the [`Camera`] one, to automatically update the camera projection matrix.
323
+ ///
324
+ /// The system function is generic over the camera projection type, and only instances of
325
+ /// [`OrthographicProjection`] and [`PerspectiveProjection`] are automatically added to
326
+ /// the app, as well as the runtime-selected [`Projection`]. The system runs during the
327
+ /// [`CoreStage::PostUpdate`] stage.
328
+ ///
329
+ /// [`OrthographicProjection`]: crate::camera::OrthographicProjection
330
+ /// [`PerspectiveProjection`]: crate::camera::PerspectiveProjection
331
+ /// [`Projection`]: crate::camera::Projection
332
+ /// [`CoreStage::PostUpdate`]: bevy_app::CoreStage::PostUpdate
308
333
pub fn camera_system < T : CameraProjection + Component > (
309
334
mut window_resized_events : EventReader < WindowResized > ,
310
335
mut window_created_events : EventReader < WindowCreated > ,
@@ -317,19 +342,18 @@ pub fn camera_system<T: CameraProjection + Component>(
317
342
) > ,
318
343
) {
319
344
let mut changed_window_ids = Vec :: new ( ) ;
320
- // handle resize events. latest events are handled first because we only want to resize each
321
- // window once
322
- for event in window_resized_events . iter ( ) . rev ( ) {
345
+
346
+ // Collect all unique window IDs of changed windows by inspecting created windows
347
+ for event in window_created_events . iter ( ) {
323
348
if changed_window_ids. contains ( & event. id ) {
324
349
continue ;
325
350
}
326
351
327
352
changed_window_ids. push ( event. id ) ;
328
353
}
329
354
330
- // handle resize events. latest events are handled first because we only want to resize each
331
- // window once
332
- for event in window_created_events. iter ( ) . rev ( ) {
355
+ // Collect all unique window IDs of changed windows by inspecting resized windows
356
+ for event in window_resized_events. iter ( ) {
333
357
if changed_window_ids. contains ( & event. id ) {
334
358
continue ;
335
359
}
0 commit comments