Skip to main content

CameraFrame

Struct CameraFrame 

Source
pub struct CameraFrame {
    pub pos: DVec3,
    pub up: DVec3,
    pub facing: DVec3,
    pub near: f64,
    pub far: f64,
    pub perspective_blend: f64,
    pub frame_height: f64,
    pub scale: f64,
    pub fovy: f64,
}
Expand description

The data of a camera

The CameraFrame has a CameraFrame::perspective_blend property (default is 0.0), which is used to blend between orthographic and perspective projection.

Fields§

§pos: DVec3

The position

§up: DVec3

The up unit vec

§facing: DVec3

The facing unit vec

§near: f64

The near pane

§far: f64

The far pane

§perspective_blend: f64

The perspective blend value in [0.0, 1.0]

§frame_height: f64

Ortho: Top - Bottom

§scale: f64

Ortho: The scaling factor

§fovy: f64

Perspective: The field of view angle, used in perspective projection

Implementations§

Source§

impl CameraFrame

Source

pub fn new() -> Self

Create a new CameraFrame at the origin facing to the negative z-axis and use Y as up vector with default projection settings.

Source§

impl CameraFrame

Source

pub fn set_view_matrix(&mut self, view_matrix: DMat4)

Set the view matrix of the camera.

Source

pub fn with_view_matrix(self, view_matrix: DMat4) -> Self

Set the view matrix of the camera and return the modified Self.

Source

pub fn view_matrix(&self) -> DMat4

The view matrix of the camera

Source

pub fn orthographic_mat(&self, aspect_ratio: f64) -> DMat4

Use the given frame size as left, right, bottom, top to construct an orthographic matrix

Source

pub fn perspective_mat(&self, aspect_ratio: f64) -> DMat4

Use the given frame aspect ratio to construct a perspective matrix

Source

pub fn projection_matrix(&self, aspect_ratio: f64) -> DMat4

Use the given frame size to construct projection matrix

Source

pub fn view_projection_matrix(&self, aspect_ratio: f64) -> DMat4

Use the given frame size to construct view projection matrix

Source§

impl CameraFrame

Source

pub fn from_spherical(phi: f64, theta: f64, distance: f64) -> Self

Create a perspective camera positioned using spherical coordinates (Z-up), looking at the origin.

  • phi: polar angle from +Z axis in radians (0 = straight up along +Z, π/2 = XY plane)
  • theta: azimuth angle in radians (0 = +X direction, π/2 = +Y direction)
  • distance: distance from the origin
Source

pub fn set_spherical( &mut self, phi: f64, theta: f64, distance: f64, target: DVec3, ) -> &mut Self

Position the camera using spherical coordinates (Z-up) around a target point.

  • phi: polar angle from +Z axis in radians (0 = straight up along +Z, π/2 = XY plane)
  • theta: azimuth angle in radians (0 = +X direction, π/2 = +Y direction)
  • distance: distance from target
  • target: the point the camera looks at
Source

pub fn look_at(&mut self, target: DVec3) -> &mut Self

Set the camera to look at a target point.

Source

pub fn orbit( &mut self, target: DVec3, total_angle: f64, ) -> impl Eval<Output = Self> + Placeable + use<>

Create an orbit animation that rotates the camera around target by total_angle radians in the XY plane (Z-up).

The camera’s current position is used to derive the spherical coordinates (distance, elevation) which are kept constant during the orbit.

§Example
use std::f64::consts::TAU;

let mut cam = CameraFrame::from_spherical(phi, theta, distance);
r.play(
    cam.orbit(DVec3::ZERO, TAU)
        .with_duration(8.0)
        .with_rate_func(linear),
);
Source§

impl CameraFrame

Source

pub fn center_canvas_in_frame( &mut self, center: DVec3, width: f64, height: f64, up: DVec3, normal: DVec3, aspect_ratio: f64, ) -> &mut Self

Center the canvas in the frame when CameraFrame::perspective_blend is 1.0

Trait Implementations§

Source§

impl Alignable for CameraFrame

Source§

fn is_aligned(&self, _other: &Self) -> bool

Checking if two items are aligned
Source§

fn align_with(&mut self, _other: &mut Self)

Aligning two items
Source§

impl Clone for CameraFrame

Source§

fn clone(&self) -> CameraFrame

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for CameraFrame
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have [Component<Mutability = Mutable>], while immutable components will instead have [Component<Mutability = Immutable>]. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>

Returns [ComponentRelationshipAccessor] required for working with relationships in dynamic contexts. Read more
§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add [ComponentHook] for this [Component] if one is defined.
§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert [ComponentHook] for this [Component] if one is defined.
§

fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_discard [ComponentHook] for this [Component] if one is defined.
§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove [ComponentHook] for this [Component] if one is defined.
§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn [ComponentHook] for this [Component] if one is defined.
§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given [EntityMapper]. This is used to remap entities in contexts like scenes and entity cloning. When deriving [Component], this is populated by annotating fields containing entities with #[entities] Read more
Source§

impl Debug for CameraFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CameraFrame

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Extract for CameraFrame

Source§

type Target = CoreItem

Extraction target.
Source§

fn extract_into(&self, buf: &mut Vec<Self::Target>)

Append extracted values to buf.
Source§

fn extract(&self) -> Vec<Self::Target>

Extract into a newly allocated vector.
Source§

impl Interpolatable for CameraFrame

Source§

fn lerp(&self, target: &Self, t: f64) -> Self

Lerping between values
Source§

impl PartialEq for CameraFrame

Source§

fn eq(&self, other: &CameraFrame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CameraFrame

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<C> Bundle for C
where C: Component,

§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>

§

fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>

Return a iterator over this [Bundle]’s component ids. This will be None if the component has not been registered.
§

impl<C> BundleFromComponents for C
where C: Component,

§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Discard for T

Source§

fn discard(&self)

Simply returns ()
Source§

impl<T> DynClone for T
where T: Clone,

§

impl<C> DynamicBundle for C
where C: Component,

§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromTemplate for T
where T: Clone + Default + Unpin,

§

type Template = T

The [Template] for this type.
§

impl<T> FromWorld for T
where T: Default,

§

fn from_world(_world: &mut World) -> T

Creates Self using default().

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> StaticAnim for T
where T: StaticAnimRequirement + 'static,

Source§

fn show(&self) -> Paramed<Static<T>>

Show this value.
Source§

fn hide(&self) -> Paramed<Static<T>>

Hide this value.
§

impl<T> Template for T
where T: Clone + Default + Unpin,

§

type Output = T

The type of value produced by this [Template].
§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a [Template::Output].
§

fn clone_template(&self) -> T

Clones this template. See Clone.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> With for T

Source§

fn with(self, f: impl Fn(&mut Self)) -> Self
where Self: Sized,

Mutating a value in place
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> AnyExtractCoreItem for T
where T: Extract<Target = CoreItem> + Any + DynClone,

Source§

impl<T> Component for T
where T: Debug + Default + Clone + PartialEq,

§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> StaticAnimRequirement for T