Skip to main content

Projection

Struct Projection 

Source
pub struct Projection { /* private fields */ }
Expand description

Screen extent of the world, and its foreshortening by depth.

The view is always the drawing area’s shape; games never need an aspect ratio.

Implementations§

Source§

impl Projection

Source

pub const fn perspective(fov_degrees: f32) -> Self

Foreshortened by depth, over a vertical field of view, in degrees.

Examples found in repository?
examples/material-playground.rs (line 790)
787    fn camera(&self) -> Camera {
788        Camera::new(
789            View::look_at(self.eye, self.eye + self.forward()),
790            Projection::perspective(CAMERA_FOV),
791        )
792    }
More examples
Hide additional examples
examples/stress-preview.rs (line 290)
287    fn camera(&self) -> Camera {
288        Camera::new(
289            View::look_at(self.eye, self.eye + self.forward()),
290            Projection::perspective(CAMERA_FOV),
291        )
292    }
293}
294
295struct StressPreview {
296    settings: Settings,
297    applied_instance_count: u32,
298    applied_seed_count: u32,
299    field: Vec<FieldEntry>,
300    frame_times: FrameTimer,
301    /// Set at the instant a pan, a wheel step or a drag first moves the
302    /// camera; from then on the orbit never runs again.
303    player: Option<Player>,
304}
305
306impl StressPreview {
307    fn init(_ctx: &mut InitContext<'_, Self>) -> Result<Self, Error> {
308        let settings = Settings::default();
309        let field = build_field(settings.instance_count, settings.seed_count);
310        Ok(Self {
311            applied_instance_count: settings.instance_count,
312            applied_seed_count: settings.seed_count,
313            settings,
314            field,
315            frame_times: FrameTimer::new(),
316            player: None,
317        })
318    }
319
320    /// Rebuilds the field where the instance count or the seed count
321    /// changed since the last frame.
322    fn apply_settings(&mut self) {
323        if self.settings.instance_count == self.applied_instance_count
324            && self.settings.seed_count == self.applied_seed_count
325        {
326            return;
327        }
328        self.field = build_field(self.settings.instance_count, self.settings.seed_count);
329        self.applied_instance_count = self.settings.instance_count;
330        self.applied_seed_count = self.settings.seed_count;
331    }
332
333    /// The camera's place along the orbit at `elapsed`, before the player
334    /// takes it over.
335    fn orbit_eye(elapsed: f32) -> Vec3 {
336        let angle = elapsed * CAMERA_ANGULAR_SPEED;
337        Vec3::new(
338            angle.cos() * CAMERA_ORBIT_RADIUS,
339            CAMERA_HEIGHT,
340            angle.sin() * CAMERA_ORBIT_RADIUS,
341        )
342    }
343
344    /// The frame's camera: the orbit at `elapsed`, or the player's own
345    /// place once they have taken over.
346    fn camera(&self, elapsed: f32) -> Camera {
347        match &self.player {
348            Some(player) => player.camera(),
349            None => Camera::new(
350                View::look_at(Self::orbit_eye(elapsed), Vec3::ZERO),
351                Projection::perspective(CAMERA_FOV),
352            ),
353        }
354    }
examples/breakout-game.rs (line 585)
582    fn camera() -> Camera {
583        Camera::new(
584            View::look_at(Vec3::new(0.0, 13.5, 12.5), Vec3::new(0.0, 0.0, 0.5)),
585            Projection::perspective(50.0),
586        )
587    }
examples/sprite-adventure.rs (line 1039)
1036    fn camera(position: Vec3, offset: Vec3) -> Camera {
1037        Camera::new(
1038            View::look_at(position + offset, position),
1039            Projection::perspective(CAMERA_FOV),
1040        )
1041    }
examples/sound-lab.rs (line 457)
450    fn camera(player: Vec2) -> Camera {
451        let ground = Vec3::new(player.x, 0.0, player.y);
452        Camera::new(
453            View::look_at(
454                ground + Vec3::new(0.0, CHASE_UP, CHASE_BACK),
455                ground + Vec3::Y * 0.5,
456            ),
457            Projection::perspective(55.0),
458        )
459    }
examples/post-effects.rs (line 159)
156    fn frame(&mut self, ctx: &mut FrameContext<'_, Self>) {
157        ctx.set_camera(Camera::new(
158            View::look_at(Vec3::new(0.0, 3.4, 4.6), Vec3::new(0.0, 0.2, 0.0)),
159            Projection::perspective(45.0),
160        ));
161        ctx.set_bloom(SCENE_BLOOM);
162
163        self.draw_scene(ctx);
164        self.panel(ctx);
165    }
Source

pub const fn orthographic(world_height: f32) -> Self

No foreshortening; world_height meters of world are visible over the drawing area’s height.

Examples found in repository?
examples/isometric-board.rs (line 386)
382    fn camera() -> Camera {
383        let eye = Vec3::new(9.0, 9.0, 9.0);
384        Camera::new(
385            View::look_at(eye, Vec3::ZERO),
386            Projection::orthographic(11.0),
387        )
388    }
Source

pub const fn clip(self, clip: Range<f32>) -> Self

Sets the distances, in meters, between which the world is visible; 0.1..1000.0 by default.

Source

pub const fn lens(&self) -> Lens

This projection’s lens, and the number shaping it.

Source

pub const fn near(&self) -> f32

This projection’s near clip distance, in meters.

Source

pub const fn far(&self) -> f32

This projection’s far clip distance, in meters.

Trait Implementations§

Source§

impl Clone for Projection

Source§

fn clone(&self) -> Projection

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Projection

Source§

impl Debug for Projection

Source§

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

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

impl PartialEq for Projection

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Projection

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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