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
impl Projection
Sourcepub const fn perspective(fov_degrees: f32) -> Self
pub const fn perspective(fov_degrees: f32) -> Self
Foreshortened by depth, over a vertical field of view, in degrees.
Examples found in repository?
More 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 }Additional examples can be found in:
Sourcepub const fn orthographic(world_height: f32) -> Self
pub const fn orthographic(world_height: f32) -> Self
No foreshortening; world_height meters of world are visible over the
drawing area’s height.
Trait Implementations§
Source§impl Clone for Projection
impl Clone for Projection
Source§fn clone(&self) -> Projection
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for Projection
Source§impl Debug for Projection
impl Debug for Projection
Source§impl PartialEq for Projection
impl PartialEq for Projection
impl StructuralPartialEq for Projection
Auto Trait Implementations§
impl Freeze for Projection
impl RefUnwindSafe for Projection
impl Send for Projection
impl Sync for Projection
impl Unpin for Projection
impl UnsafeUnpin for Projection
impl UnwindSafe for Projection
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
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 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> ⓘ
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