frameBounds static method
RenderView
frameBounds(})
A view of box, width by height, far enough back to see all of
it: from toward (a direction from its middle to the eye), or — when
that is null — turned yaw and tipped pitch (radians).
Implementation
static RenderView frameBounds(
Aabb3 box,
int width,
int height, {
Vector3? toward,
double yaw = -0.6,
double pitch = -0.45,
}) {
final centre = Vector3.zero();
box.centerInto(centre);
final radius = math.max(0.05, box.min.distanceTo(box.max) / 2);
const fov = math.pi / 4;
final distance = radius / math.sin(fov / 2) * 1.05;
final towardEye =
toward ??
Vector3(
-math.cos(pitch) * math.sin(yaw),
math.sin(pitch),
-math.cos(pitch) * math.cos(yaw),
);
towardEye.normalize();
final eye = centre + towardEye * distance;
final view = RenderView()
..width = width
..height = height;
view.lookAt(eye, centre);
view.projection.setPerspectiveYDown(
fov,
width / height,
math.max(0.01, distance - radius * 2),
distance + radius * 2,
);
return view;
}