pub struct Camera {
pub projection: ProjectionType,
pub aspect_ratio: f32,
pub z_near: f32,
pub z_far: f32,
pub is_active: bool,
}Expand description
A component that defines a camera’s projection parameters.
This component is used to configure how the 3D world is projected onto the 2D screen. It supports both perspective and orthographic projections.
Fields§
§projection: ProjectionTypeThe type of projection (perspective or orthographic).
aspect_ratio: f32The aspect ratio of the viewport (width / height). This is typically updated when the window is resized.
z_near: f32The distance to the near clipping plane. Objects closer than this will not be rendered. Should be a small positive value (e.g., 0.1).
z_far: f32The distance to the far clipping plane.
Objects farther than this will not be rendered.
Should be larger than z_near (e.g., 1000.0).
is_active: boolWhether this camera is the active/primary camera. Only one camera should be active at a time.
Implementations§
Source§impl Camera
impl Camera
Sourcepub fn new_perspective(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
z_far: f32,
) -> Self
pub fn new_perspective( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, ) -> Self
Creates a new perspective camera with the given parameters.
Sourcepub fn new_orthographic(
width: f32,
height: f32,
z_near: f32,
z_far: f32,
) -> Self
pub fn new_orthographic( width: f32, height: f32, z_near: f32, z_far: f32, ) -> Self
Creates a new orthographic camera with the given parameters.
Sourcepub fn default_perspective() -> Self
pub fn default_perspective() -> Self
Creates a default perspective camera suitable for most 3D applications.
- FOV: 60 degrees (~1.047 radians)
- Aspect ratio: 16:9 (~1.777)
- Near plane: 0.1
- Far plane: 1000.0
Sourcepub fn default_orthographic() -> Self
pub fn default_orthographic() -> Self
Creates a default orthographic camera.
- Width: 1920.0
- Height: 1080.0
- Near plane: -1.0
- Far plane: 1000.0
Sourcepub fn projection_matrix(&self) -> Mat4
pub fn projection_matrix(&self) -> Mat4
Calculates the projection matrix for this camera.
This uses a right-handed coordinate system with a [0, 1] depth range, which is standard for modern rendering APIs like Vulkan and WebGPU.
Sourcepub fn set_aspect_ratio(&mut self, width: u32, height: u32)
pub fn set_aspect_ratio(&mut self, width: u32, height: u32)
Updates the aspect ratio, typically called when the window is resized.
Trait Implementations§
impl Component for Camera
impl Copy for Camera
impl StructuralPartialEq for Camera
Auto Trait Implementations§
impl Freeze for Camera
impl RefUnwindSafe for Camera
impl Send for Camera
impl Sync for Camera
impl Unpin for Camera
impl UnwindSafe for Camera
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<C1> ComponentBundle for C1where
C1: Component,
impl<C1> ComponentBundle for C1where
C1: Component,
Source§fn type_ids() -> Vec<TypeId>
fn type_ids() -> Vec<TypeId>
TypeIds for the components in this bundle. Read moreSource§fn create_columns() -> HashMap<TypeId, Box<dyn AnyVec>>
fn create_columns() -> HashMap<TypeId, Box<dyn AnyVec>>
Vec<T> columns required to store
this bundle’s components. Read moreSource§fn update_metadata(
metadata: &mut EntityMetadata,
location: PageIndex,
registry: &ComponentRegistry,
)
fn update_metadata( metadata: &mut EntityMetadata, location: PageIndex, registry: &ComponentRegistry, )
EntityMetadata struct to point
to the location of this bundle’s data. Read moreSource§unsafe fn add_to_page(self, page: &mut ComponentPage)
unsafe fn add_to_page(self, page: &mut ComponentPage)
ComponentPage. Read more