pub struct Flyer { /* private fields */ }Expand description
A camera the keyboard flies.
Holds a position and two angles rather than a Camera, because a camera is
an eye and a target: integrating a target directly makes turning depend on
how far away it happens to be.
Implementations§
Source§impl Flyer
impl Flyer
Sourcepub fn at(camera: &Camera) -> Self
pub fn at(camera: &Camera) -> Self
A flyer standing where camera stands and looking where it looks, at
SPEED.
Starting at the golden pose is what makes a sample’s free camera and its fixed camera the same first frame: a reviewer comparing a windowed run against a golden is comparing the same picture until they press a key.
Sourcepub const fn with_speed(self, speed: f32) -> Self
pub const fn with_speed(self, speed: f32) -> Self
The same flyer walking at speed metres a second instead of SPEED.
The default is sized for a room, and a scene that is not room-sized needs its own number: a camera that takes a minute and a half to cross the subject is as unusable as one that overshoots it. The turn rates are not configurable beside it, because an angle is an angle at every scale.
Sourcepub const fn key(&mut self, key: KeyCode, pressed: bool) -> bool
pub const fn key(&mut self, key: KeyCode, pressed: bool) -> bool
Takes a key edge, and says whether it was one of this camera’s.
Returning the answer rather than swallowing everything: the loop hands a game every key its own three did not claim, and a camera that reported “mine” for all of them would leave the sample unable to bind anything else later.
Sourcepub fn release_all(&mut self)
pub fn release_all(&mut self)
Lets go of every key.
Called when the window loses focus: a platform sends no release for a key that was down when focus went away, so without this the camera keeps walking into a wall for as long as the window is in the background.
Sourcepub fn look(&mut self, motion: Vec2)
pub fn look(&mut self, motion: Vec2)
Turns by one frame’s worth of mouse movement.
motion is PointerUpdate::motion: framebuffer pixels, Y down.
That is why the pitch subtracts where the yaw adds — pushing the mouse
away from the hand is a negative Y and has to raise the view — and it
is the one sign in this file that no compiler can check.
§Not on the fixed timestep, unlike advance
A held key is a rate and has to be integrated against the clock or the
camera flies at a speed proportional to how fast the machine is. A mouse
delta is already a distance the hand moved: scaling it by dt would make
the same sweep turn a different amount on a slow frame, and running it
once per tick would apply one frame’s movement two or three times over on
a frame that owed the clock several. So this lands where it arrives, in
the frame, exactly once.
Sourcepub fn camera(&self, projection: Projection) -> Camera
pub fn camera(&self, projection: Projection) -> Camera
The camera this flyer is, with projection taken from the fixed one.
The projection is the caller’s rather than a field here because it is the lens, and the whole point of the pair is that the free camera and the golden camera see through the same one.