Expand description
Opt-in, checked camera presentation blends. No clock, simulation, collision queries, input, or authoritative pose history is owned here.
Blend eye position, positive eye-to-target distance and vertical FOV linearly;
blend the orthonormal view orientation along the shortest quaternion arc.
The look target is reconstructed from the blended eye, direction and distance,
not interpolated independently through a possible coincident eye/target.
Up scale and its component parallel to forward do not affect the view: interior
samples use unit perpendicular up. Exact endpoints retain the supplied Pose3
verbatim, including its up vector. No Euler-angle or swing/twist stack is added.
Only symmetric, finite-far perspective lenses are described by Perspective3.
Positive-duration blends require exactly matching lens descriptors, including
aspect, clipping planes, handedness and depth convention; only FOV blends.
Orthographic, infinite-far, asymmetric and custom projections need a host-owned
cut/adapter. Descriptors declare intent; the host must use the same conventions
in its renderer. Internally orientation uses local -Z forward/+Y up as in
Mat4::try_look_to_rh; the resulting world-space forward/up also work with the
host’s LH view builder. Handedness never changes within a blend.
Retargeting starts at the last displayed pose and resets segment time. It
preserves a hold; resume continues the new segment without consuming paused
time. A cut (including a zero-duration retarget or a Frame3::cut) immediately
replaces all endpoints and releases hold. reset forgets the pose entirely.
The next valid target initializes directly. Host-owned teleport/restart and
renderer history must also be reset; a camera transition cannot repair stale
simulation interpolation. Input frames are borrowed: their obstruction,
recovery and query diagnostics remain observations of the host’s original
query, never observations of the blended path. Output is a Pose3, not a
fabricated Frame3. A blended path can cross obstacles even with safe endpoints.
§Pause, continuous retarget, accepted teleport and restart
Runnable headless recipe using actual Pose3, Frame3 and Rig3. The host
decides when simulation/network/replay updates execute, even during a local
menu. These injected presentation deltas never schedule simulation ticks.
use ferravex_math::{Vec3, projection::NdcDepth};
use ferravex_play::camera::{Input3, Mode3, NoObstructions, Pose3, Rig3, Target3};
use ferravex_play::camera::transition::{Perspective3, Transition3, ViewHandedness};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let lens = Perspective3 { aspect: 16. / 9., near: 0.1, far: 1000.,
handedness: ViewHandedness::Right, depth: NdcDepth::NegativeOneToOne };
let mut view = Transition3::new();
assert_eq!(view.pose(), None);
view.cut(Pose3::default(), lens)?;
view.retarget(Pose3 { position: Vec3::X * 8.,
target: Vec3::X * 8. - Vec3::Z, ..Pose3::default() }, lens, 1.)?;
let visible = view.advance(0.25)?.unwrap();
assert_eq!(visible.position.x, 2.);
assert!(view.is_blending());
assert_eq!(view.projection(), Some(lens));
assert!(view.hold());
assert!(view.is_held());
assert_eq!(view.advance(0.25)?, Some(visible));
// A local menu does not block authoritative updates. A newly selected
// presentation target may replace the pending segment while held.
view.retarget(Pose3::default(), lens, 0.5)?;
assert_eq!(view.pose(), Some(visible));
assert!(view.resume());
assert_eq!(view.advance(0.)?, Some(visible));
assert_eq!(view.advance(0.25)?.unwrap().position.x, 1.);
let mut rig = Rig3::default();
// Simulation has accepted this teleport; do not pass a pending request
// or an old interpolated subject. The host already reset subject history.
let accepted = Target3::at(Vec3::X * 100.);
let frame = rig.snap(Input3 { target: accepted, mode: Mode3::Follow {
eye_offset: Vec3::Z * 5., look_offset: Vec3::ZERO }, fov_y: 1. },
&NoObstructions)?;
assert!(frame.cut);
let generation = view.generation();
view.retarget_frame(&frame, lens, 1.)?; // Cut overrides blend and hold.
assert_eq!(view.generation(), generation + 1);
assert_eq!(view.advance(0.)?, Some(frame.pose));
assert!(!view.is_blending());
view.reset(); // Also reset host simulation/rig/history for a real restart.
assert_eq!(view.advance(0.25)?, None);
view.retarget(Pose3::default(), lens, 1.)?;
assert_eq!(view.pose(), Some(Pose3::default()));
Ok(())
}§Numerical and storage limits
Eye coordinates have absolute components <= 1e6; view distance is in
0.001..=1e6; FOV is in 0.05..=3.1 radians (the rig’s existing FOV range).
Up must be finite/nonzero, with sine of its angle to forward >= 1e-4. Near
parallel up is rejected, not replaced with an arbitrary roll. Subtraction,
distance and scalar interpolation use f64 intermediates. Rotations use existing
checked quaternion normalization, angular distance and rotate-towards helpers.
Extracted endpoint quaternions are canonicalized to positive w, or, at w == 0,
first nonzero x/y/z positive. A negative endpoint dot flips the destination;
exact zero-dot half-turn ties retain these signs, as in the math helpers.
Small perturbations near half turns may choose the opposite equally short arc.
Durations are finite seconds in 0..=3600; per-call presentation deltas are
finite in 0..=0.25, including during hold/idle. Long suspension time must be
discarded/rebased by the host or handled with a cut. Elapsed segment time uses
f64, capped at duration. Interior outputs round to f32; at large coordinates a
short reconstructed target may round onto the eye. Such samples return
TransitionError::NumericalLimit atomically. Valid endpoints do not guarantee
every intermediate target is representable. Endpoint completion bypasses
reconstruction and is exact; no cross-platform bitwise determinism is promised.
All methods use fixed-size inline state and bounded work, without heap storage.
Structs§
- Perspective3
- Explicit symmetric finite-far perspective intent; FOV comes from
Pose3. - Transition3
- Bounded presentation segment, initially empty. See the module’s runnable recipe.
Enums§
- Transition
Error - Rejected input leaves the complete transition unchanged, even during hold.
See
Transition3::retargetfor an executable error example. - View
Handedness - Host view-matrix convention. See the module recipe for lens construction.