Module camera

Source
Expand description

Allocation-free presentation cameras. World Y is up. Shooter yaw zero faces -Z; orbit eye offsets and vehicle-local chase forward use +Z. No simulation or input state is changed by damping, obstruction recovery or shake.

Follow2 and Rig3 initialize on their first successful update. Use snap when the new spawn/teleport target is available, reset when restarting before that target exists, or cut to defer a snap until the next update while retaining the last pose. Honor the returned cut flag when interpolating rendered frames. Reset simulation interpolation at the teleport too: provide the new target directly so the camera does not follow a stale blended target.

Smoothing half-lives are in seconds: after one half-life a stationary goal’s error is halved. Existing tuning is retained by resets and snaps. Update time must be finite and in 0..=0.25; larger gaps are rejected without mutation. A host can deliberately snap on resume or bound only its presentation time.

This chase-camera integration uses Dune Skimmer’s position/target damping. Call it after sampling the vehicle pose, then copy the returned pose into the renderer’s camera. A recovery flag must be raised even for a short teleport below the automatic distance threshold.

use ferravex_math::Vec3;
use ferravex_play::camera::{
    CameraError, CollisionQuery, Frame3, Input3, Mode3, NoObstructions,
    Rig3, Settings3, Target3,
};

fn vehicle_view(
    camera: &mut Rig3,
    vehicle: Target3,
    elapsed: f32,
    recovered: bool,
    blockers: &(impl CollisionQuery + ?Sized),
) -> Result<Frame3, CameraError> {
    if !elapsed.is_finite() || elapsed < 0. {
        return Err(CameraError::InvalidInput);
    }
    let input = Input3 {
        target: vehicle,
        mode: Mode3::Chase {
            distance: 8., height: 3., look_ahead: 4., look_height: 1.,
            speed_distance: 0.05, speed_height: 0., prediction: 0.1,
            level: true,
        },
        fov_y: 1.,
    };
    if recovered || elapsed > 0.25 {
        camera.snap(input, blockers)
    } else {
        camera.update(elapsed, input, blockers)
    }
}

let mut camera = Rig3::new(Settings3 {
    position_half_life: std::f32::consts::LN_2 / 5.5,
    target_half_life: std::f32::consts::LN_2 / 8.,
    ..Default::default()
})?;
let spawn = Target3::at(Vec3::new(100., 1., 20.));
let frame = vehicle_view(&mut camera, spawn, 1. / 60., true, &NoObstructions)?;
assert!(frame.cut);
assert_eq!(camera.pose(), Some(frame.pose));

Structs§

CameraComposer
CameraShake
Allocation-free seeded shake, driven only by explicitly supplied delta time.
CameraZone
Follow2
A planar follow camera. The first valid update initializes directly at its goal; subsequent updates apply the configured dead zone and half-life.
Follow2Settings
Frame2
Frame3
FramingBounds
An axis-aligned world-space subject box. Equal endpoints on any axis are allowed, including a point subject. Each coordinate must be within ±1e6. Bounds are checked by FramingSettings::frame, including public-field edits.
FramingResult
A perspective framing solution, before damping, obstruction and shake. The host must use the same aspect and vertical FOV, a near clip plane no larger than the requested near, and a sufficiently distant far clip plane. Floating-point projection retains ordinary f32 rounding error.
FramingSettings
Checked perspective framing constraints. All fields are revalidated on use.
Input3
Limits2
NoObstructions
ObstructionSettings
Pose3
Rig3
Copyable complete presentation state; update errors preserve it unchanged.
Settings3
ShakeEnvelope
An owned snapshot of an active impulse; changing it does not change the shake.
ShakeImpulse
Bounded local-space motion with a quadratic decay envelope.
ShakeSample
Sweep
A sphere-center segment. Equal endpoints perform a stationary overlap check. Use Sweep::new to check inputs, or Sweep::probe to also check adapter results and obtain distances and a padded placement.
SweepOutcome
Diagnostics from Sweep::probe, describing only the queried segment. Distances are sphere-center travel in world units, not surface separation. No penetration depth, surface normal or blocker identity is inferred from the fraction-only CollisionQuery abstraction.
Target3

Enums§

Blocker
A small built-in adapter for authored environments. Box sweeps inflate the local box by radius and are conservative at corners; physics adapters may provide exact rounded-box/primitive sphere sweeps through CollisionQuery.
CameraError
FramingError
A rejected framing request. No camera or composer state is changed.
FramingLimit
How authored distance limits affected a framing result.
Mode3

Constants§

MAX_BLOCKERS
MAX_FRAMING_SUBJECTS
Maximum number of subject boxes examined by one framing calculation.

Traits§

CollisionQuery
Return the first sphere-center impact fraction in [0,1], or None if clear. A blocked starting point must return Some(0), including zero-length sweeps. Stationary sweeps must return only None or Some(0). Use Sweep::probe for checked results and padded clearance without changing this adapter contract.