Skip to content

five-on-it / apps/client/src/renderer/camera / LookAhead

Class: LookAhead ​

Defined in: apps/client/src/renderer/camera.ts:175

The velocity the view looks ahead along: the car's, through an exponential filter (LOOK_AHEAD_RATE, frame-rate independent), so the view leads the car the way it goes without swinging with every flick of the steering, every kerb and every correction.

A blow is the exception to the filter (impact): a car that hits a wall at 80 km/h loses its speed in one tick, and a view that looked 7.5 m ahead of it would have filtered that away over a quarter of a second, panning on past the stopped car and then back onto it at up to 18 m/s for most of a second (measured by tests/netcode/impact.ts): the picture kept moving after a crash the simulation resolved in one tick. So at a blow the filter takes the new velocity at once, and the lead it loses with it is held in held, added to the view's target as it was, for IMPACT_HOLD and then let go at IMPACT_RECENTRE: the picture stops dead with the car and comes back onto it at a jog.

Constructors ​

Constructor ​

new LookAhead(): LookAhead

Returns ​

LookAhead

Properties ​

held ​

readonly held: Vec3

Defined in: apps/client/src/renderer/camera.ts:179

The lead a blow took from the car, held and then let go (m): what the view's target carries besides the look-ahead.


velocity ​

readonly velocity: Vec3

Defined in: apps/client/src/renderer/camera.ts:177

The filtered velocity (m/s).

Methods ​

impact() ​

impact(velocity): void

Defined in: apps/client/src/renderer/camera.ts:208

A blow changed the car's velocity to velocity in a tick: the filter takes it at once, and the lead it loses with it goes into held, so the view's target stands where it was and the picture stops with the car (see the class).

Parameters ​

velocity ​

Vec3

Returns ​

void


settle() ​

settle(followed, desired): void

Defined in: apps/client/src/renderer/camera.ts:235

On the first frame after a blow, the view stops where it is: the follower carried by the velocity trails a car at a steady speed by nothing, but a car pulling away grows its look-ahead faster than its velocity carries the view, and the view lags its desired target by that growth (half a metre at 80 km/h, CI's run of E2E-643), which it would close at 5 m/s after the car had stopped dead. So the lag the followed pose (the follower's) still has on desired joins the held lead, and desired is moved onto it (its target and its eye alike, as a lead moves them): the view stands where it was for the hold and comes back onto the car with the rest of the held lead. Nothing on any other frame.

Parameters ​

followed ​

CameraPose

desired ​

CameraPose

Returns ​

void


update() ​

update(velocity, dt): Vec3

Defined in: apps/client/src/renderer/camera.ts:184

Follows velocity for dt seconds, lets the held lead go in its time, and returns the filtered velocity (the same object each time).

Parameters ​

velocity ​

Vec3

dt ​

number

Returns ​

Vec3