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 291)
288 fn camera(&self) -> Camera {
289 Camera::new(
290 View::look_at(self.eye, self.eye + self.forward()),
291 Projection::perspective(CAMERA_FOV),
292 )
293 }
294}
295
296struct StressPreview {
297 settings: Settings,
298 applied_instance_count: u32,
299 applied_seed_count: u32,
300 field: Vec<FieldEntry>,
301 frame_times: FrameTimer,
302 /// Set at the instant a pan, a wheel step or a drag first moves the
303 /// camera; from then on the orbit never runs again.
304 player: Option<Player>,
305}
306
307impl StressPreview {
308 fn init(_ctx: &mut InitContext<'_, Self>) -> Result<Self, Error> {
309 let settings = Settings::default();
310 let field = build_field(settings.instance_count, settings.seed_count);
311 Ok(Self {
312 applied_instance_count: settings.instance_count,
313 applied_seed_count: settings.seed_count,
314 settings,
315 field,
316 frame_times: FrameTimer::new(),
317 player: None,
318 })
319 }
320
321 /// Rebuilds the field where the instance count or the seed count
322 /// changed since the last frame.
323 fn apply_settings(&mut self) {
324 if self.settings.instance_count == self.applied_instance_count
325 && self.settings.seed_count == self.applied_seed_count
326 {
327 return;
328 }
329 self.field = build_field(self.settings.instance_count, self.settings.seed_count);
330 self.applied_instance_count = self.settings.instance_count;
331 self.applied_seed_count = self.settings.seed_count;
332 }
333
334 /// The camera's place along the orbit at `elapsed`, before the player
335 /// takes it over.
336 fn orbit_eye(elapsed: f32) -> Vec3 {
337 let angle = elapsed * CAMERA_ANGULAR_SPEED;
338 Vec3::new(
339 angle.cos() * CAMERA_ORBIT_RADIUS,
340 CAMERA_HEIGHT,
341 angle.sin() * CAMERA_ORBIT_RADIUS,
342 )
343 }
344
345 /// The frame's camera: the orbit at `elapsed`, or the player's own
346 /// place once they have taken over.
347 fn camera(&self, elapsed: f32) -> Camera {
348 match &self.player {
349 Some(player) => player.camera(),
350 None => Camera::new(
351 View::look_at(Self::orbit_eye(elapsed), Vec3::ZERO),
352 Projection::perspective(CAMERA_FOV),
353 ),
354 }
355 }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
impl 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