Skip to content
Snippets Groups Projects
Commit f92755c9 authored by Alexander Rose's avatar Alexander Rose
Browse files

factored out Camera.targetDistance

parent d141c277
Branches
No related tags found
No related merge requests found
......@@ -101,12 +101,7 @@ class Camera implements ICamera {
}
getTargetDistance(radius: number) {
const r = Math.max(radius, 0.01);
const { fov } = this.state;
const { width, height } = this.viewport;
const aspect = width / height;
const aspectFactor = (height < width ? 1 : aspect);
return Math.abs((r / aspectFactor) / Math.sin(fov / 2));
return Camera.targetDistance(radius, this.state.fov, this.viewport.width, this.viewport.height);
}
getFocus(target: Vec3, radius: number, up?: Vec3, dir?: Vec3): Partial<Camera.Snapshot> {
......@@ -194,6 +189,13 @@ namespace Camera {
out.height = view.height;
}
export function targetDistance(radius: number, fov: number, width: number, height: number) {
const r = Math.max(radius, 0.01);
const aspect = width / height;
const aspectFactor = (height < width ? 1 : aspect);
return Math.abs((r / aspectFactor) / Math.sin(fov / 2));
}
export function createDefaultSnapshot(): Snapshot {
return {
mode: 'perspective',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment