Struct FramingSettings

Source
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: f32

Finite positive viewport width / height.

§fov_y: f32

Vertical field of view in radians, in 0.05..=3.1, matching Input3.

§margin: Vec2

Symmetric 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: f32

Minimum view-space depth of every corner, in 0.001..=1e5 world units.

§min_distance: f32

Positive boom floor, in 0.01..=1e5; prevents point subjects collapsing the eye onto the target. Must not exceed max_distance.

§max_distance: f32

Boom ceiling in min_distance..=1e5. A constrained fit is returned with FramingLimit::MaximumDistance, rather than silently claiming success.

Implementations§

Source§

impl FramingSettings

Source

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

Source§

fn clone(&self) -> FramingSettings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FramingSettings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for FramingSettings

Source§

fn default() -> FramingSettings

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FramingSettings

Source§

fn eq(&self, other: &FramingSettings) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for FramingSettings

Source§

impl StructuralPartialEq for FramingSettings

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.