OrthographicCamera.framing constructor
OrthographicCamera.framing(
- Aabb3 bounds, {
- Vector3? direction,
- Vector3? up,
- double margin = 1.1,
Places a camera to frame bounds (a model's world-space AABB, from
Node.combinedWorldBounds) so it fills the view on any aspect ratio.
The camera looks at the bounds' center from direction (defaults to
(0, 0, -1), as PerspectiveCamera.framing). The volume contains the
bounds' bounding sphere, scaled by margin, and its clip planes enclose
it.
Implementation
factory OrthographicCamera.framing(
Aabb3 bounds, {
Vector3? direction,
Vector3? up,
double margin = 1.1,
}) {
final center = bounds.center;
final radius = max((bounds.max - bounds.min).length * 0.5, 1e-4);
final reach = radius * margin;
final dir = (direction ?? Vector3(0, 0, -1)).normalized();
return OrthographicCamera(
projection: OrthographicProjection(
size: OrthographicSize.contain(reach * 2.0, reach * 2.0),
far: reach * 2.0,
),
position: center + dir * reach,
target: center,
up: up,
);
}