pub struct FramingSettings {
pub aspect_ratio: f32,
pub fov_y: f32,
pub margin: Vec2,
pub near: f32,
pub min_distance: f32,
pub max_distance: f32,
}Expand description
Checked perspective framing constraints. All fields are revalidated on use.
A box’s eight corners are projected independently, including their depth; framing does not approximate a subject by a point or use vertical FOV for both axes. The fit holds the orientation and group center fixed. It is not an optimization over alternative orientations or target positions.
use ferravex_math::{Quat, Vec2, Vec3};
use ferravex_play::camera::{FramingBounds, FramingLimit, FramingSettings};
let subjects = [FramingBounds { min: -Vec3::ONE, max: Vec3::ONE }];
let settings = FramingSettings {
aspect_ratio: 9. / 16., // width / height of a portrait viewport
margin: Vec2::splat(0.1), // reserve 10% along each screen edge
..Default::default()
};
let frame = settings.frame(&subjects, Quat::IDENTITY)?;
assert_ne!(frame.limit, FramingLimit::MaximumDistance);
assert_eq!(frame.pose.target, Vec3::ZERO);
// Copy frame.pose into the presentation camera using the same aspect ratio.Fields§
§aspect_ratio: f32Finite positive viewport width / height.
fov_y: f32Vertical field of view in radians, in 0.05..=3.1, matching Input3.
margin: Vec2Symmetric per-edge fractions of the full viewport width and height.
Each component must be finite and in 0..0.5. For example, x = 0.1
leaves 80% of the width for subjects, independent of the aspect ratio.
near: f32Minimum view-space depth of every corner, in 0.001..=1e5 world units.
min_distance: f32Positive boom floor, in 0.01..=1e5; prevents point subjects collapsing
the eye onto the target. Must not exceed max_distance.
max_distance: f32Boom ceiling in min_distance..=1e5. A constrained fit is returned with
FramingLimit::MaximumDistance, rather than silently claiming success.
Implementations§
Source§impl FramingSettings
impl FramingSettings
Sourcepub fn frame(
self,
subjects: &[FramingBounds],
view_rotation: Quat,
) -> Result<FramingResult, FramingError>
pub fn frame( self, subjects: &[FramingBounds], view_rotation: Quat, ) -> Result<FramingResult, FramingError>
Frame one subject or a group without allocations or camera mutation.
view_rotation maps camera-local -Z to the viewing direction and +Y to
up; identity places the eye on the group’s +Z side. Accepted quaternions
are normalized before use. Each call examines at most 256 boxes, with
two passes over their 2048 corners and constant storage. Duplicate boxes
do not change the fit.
Errors are checked in this order: settings, rotation, group length,
individual bounds, then the representability of the result. Empty groups
return an error so the caller can retain its last presentation pose.
A maximum-distance result may violate both margins and near clearance;
callers must inspect limit before relying on the fit.
use ferravex_math::{Quat, Vec3};
use ferravex_play::camera::{FramingBounds, FramingError, FramingLimit, FramingSettings};
let point = FramingBounds { min: Vec3::ZERO, max: Vec3::ZERO };
let settings = FramingSettings::default();
let frame = settings.frame(&[point], Quat::IDENTITY)?;
assert_eq!(frame.limit, FramingLimit::MinimumDistance);
assert_eq!(frame.distance, settings.min_distance);
assert_eq!(settings.frame(&[], Quat::IDENTITY), Err(FramingError::EmptyGroup));Trait Implementations§
Source§impl Clone for FramingSettings
impl Clone for FramingSettings
Source§fn clone(&self) -> FramingSettings
fn clone(&self) -> FramingSettings
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more