pub struct Perspective { /* private fields */ }Expand description
Rotates the plane z = 0 about a pivot and projects it onto the viewport.
The camera sits distance units in front of the plane on the z axis, looking
toward the plane, and the pivot stays fixed on screen. Rotations apply in the order
z (in-plane), y, then x, in radians. Positive rotation_x swings the bottom edge
toward the viewer, and positive rotation_y swings the left edge toward the viewer.
A point at depth z scales by distance / (distance - z).
Clipping is explicit: a point closer than a thousandth of distance to the camera
plane, or behind it, is an error rather than being clipped or wrapped. A plane seen
from behind remains drawable (mirrored); Self::faces_camera reports the side so
callers can hide it. Only geometry is projected, so the result renders identically
on the CPU and GPU backends.
use motion_core::{Perspective, Point};
let tilt = Perspective::new(Point::new(100.0, 100.0), 0.0, 0.5, 0.0, 800.0)?;
let near = tilt.project(Point::new(0.0, 100.0))?;
let far = tilt.project(Point::new(200.0, 100.0))?;
assert!(100.0 - near.x > far.x - 100.0);
assert!(tilt.faces_camera());Implementations§
Source§impl Perspective
impl Perspective
Sourcepub fn new(
pivot: Point,
rotation_x: f64,
rotation_y: f64,
rotation_z: f64,
distance: f64,
) -> Result<Self, ValidationError>
pub fn new( pivot: Point, rotation_x: f64, rotation_y: f64, rotation_z: f64, distance: f64, ) -> Result<Self, ValidationError>
Creates a projection; angles are finite radians and distance is finite and positive.
Sourcepub fn distance(&self) -> f64
pub fn distance(&self) -> f64
Camera distance from the plane, in the same units as path coordinates.
Sourcepub fn faces_camera(&self) -> bool
pub fn faces_camera(&self) -> bool
Whether the rotated plane’s front side points toward the camera.
Sourcepub fn project(&self, point: Point) -> Result<Point, ValidationError>
pub fn project(&self, point: Point) -> Result<Point, ValidationError>
Projects one plane point, failing when it reaches the camera plane.
Sourcepub fn project_path(
&self,
path: &Path2D,
pieces: u32,
) -> Result<Path2D, ValidationError>
pub fn project_path( &self, path: &Path2D, pieces: u32, ) -> Result<Path2D, ValidationError>
Projects every verb of a path; each curve becomes pieces cubics whose controls
are projected, which approximates the exact rational curve.
Lines stay lines, because projection preserves straight edges. Fails when pieces
is outside 1..=MAX_PERSPECTIVE_CURVE_PIECES, a point reaches the camera
plane, or the result exceeds the path verb limit.