Struct Camera
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§
§impl Camera
impl Camera
pub fn new_perspective(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
z_far: f32,
) -> Camera
pub fn new_perspective( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, ) -> Camera
Creates a new perspective camera with the given parameters.
pub fn new_orthographic(
width: f32,
height: f32,
z_near: f32,
z_far: f32,
) -> Camera
pub fn new_orthographic( width: f32, height: f32, z_near: f32, z_far: f32, ) -> Camera
Creates a new orthographic camera with the given parameters.
pub fn default_perspective() -> Camera
pub fn default_perspective() -> Camera
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
pub fn default_orthographic() -> Camera
pub fn default_orthographic() -> Camera
Creates a default orthographic camera.
- Width: 1920.0
- Height: 1080.0
- Near plane: -1.0
- Far plane: 1000.0
pub 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.
pub 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 Component for Camera
§fn make_column() -> Box<dyn AnyVec>where
Self: Sized,
fn make_column() -> Box<dyn AnyVec>where
Self: Sized,
Vec<Self>.§fn push_into_column(self, column: &mut (dyn AnyVec + 'static))where
Self: Sized,
fn push_into_column(self, column: &mut (dyn AnyVec + 'static))where
Self: Sized,
self as a new row into its column. Read more§fn copy_row_between(
src: &(dyn AnyVec + 'static),
src_row: usize,
dst: &mut (dyn AnyVec + 'static),
)where
Self: Sized,
fn copy_row_between(
src: &(dyn AnyVec + 'static),
src_row: usize,
dst: &mut (dyn AnyVec + 'static),
)where
Self: Sized,
src_row from src into dst (used when an entity migrates
between pages on a structural change). Both columns are this component’s
column type. Read more§fn clone_from_column(column: &(dyn AnyVec + 'static), row: usize) -> Selfwhere
Self: Sized,
fn clone_from_column(column: &(dyn AnyVec + 'static), row: usize) -> Selfwhere
Self: Sized,
row of column as an owned value — the uniform by-value
access path that works for both AoS (clone the &T) and field-SoA
(gather the fields) layouts. Used by World::clone_component, the
Soa<T> query, and the serialization recipe. Read more§fn set_in_column(self, column: &mut (dyn AnyVec + 'static), row: usize)where
Self: Sized,
fn set_in_column(self, column: &mut (dyn AnyVec + 'static), row: usize)where
Self: Sized,
row of column with self — the uniform by-value write
path for both layouts (AoS assigns the slot; field-SoA scatters into the
lanes). Used by World::set_component. Read moreimpl 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 UnsafeUnpin for Camera
impl UnwindSafe for Camera
Blanket Implementations§
§impl<T> AppLifecycle for Twhere
T: ?Sized,
impl<T> AppLifecycle for Twhere
T: ?Sized,
§fn on_start(&mut self, ctx: &mut dyn AppContext)
fn on_start(&mut self, ctx: &mut dyn AppContext)
update. Apps install their theme / fonts here.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,
§impl<C1> ComponentBundle for C1where
C1: Component,
impl<C1> ComponentBundle for C1where
C1: Component,
§fn type_ids() -> Vec<TypeId>
fn type_ids() -> Vec<TypeId>
TypeIds for the components in this bundle. Read more§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 more§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 more§unsafe fn add_to_page(self, page: &mut ComponentPage)
unsafe fn add_to_page(self, page: &mut ComponentPage)
ComponentPage. Read more§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.