Skip to content

Commit

Permalink
fixup! feat: add horizontal FOV converter
Browse files Browse the repository at this point in the history
  • Loading branch information
wertiop121 committed Jul 25, 2024
1 parent 7309650 commit 0e71941
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 0 additions & 8 deletions scripts/pages/settings/fov.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
function deg2rad(x) {
return (x / 180) * Math.PI;
}
function rad2deg(x) {
return (x * 180) / Math.PI;
}

class Fov {
static panels = {
/** @type {SettingsSlider} @static */
Expand All @@ -29,7 +22,6 @@ class Fov {
return panel.actuallayoutwidth / panel.actuallayoutheight;
}

// based on https://casualhacks.net/Source-FOV-calculator.html
static fovToHorizontal(fov) {
const ratioRatio = this.aspectRatio() / (4 / 3);
return 2 * rad2deg(Math.atan(Math.tan(deg2rad(fov) / 2) * ratioRatio));
Expand Down
8 changes: 8 additions & 0 deletions scripts/util/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,11 @@ function mapAngleToScreenDist(angle: number, fov: number, length: number, scale:
return Math.round((1 + Math.tan(angle * 0.5) / Math.tan(fov * 0.5)) * screenDist * 0.5);
}
}

function deg2rad(x: number): number {
return (x / 180) * Math.PI;
}

function rad2deg(x: number): number {
return (x * 180) / Math.PI;
}

0 comments on commit 0e71941

Please sign in to comment.