-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed70c78
commit e819518
Showing
4 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class Fov { | ||
static panels = { | ||
/** @type {SettingsSlider} @static */ | ||
fov: $('#FOV'), | ||
/** @type {TextEntry} @static */ | ||
horizontalFov: $('#FOV_Horizontal'), | ||
aspectRatio: $('#FOV_Horizontal_AspectRatioEnum') | ||
}; | ||
|
||
static loadSettings() { | ||
this.panels.aspectRatio.SetSelected('aspectratio1'); | ||
this.updateFOV(); | ||
} | ||
|
||
static aspectRatio() { | ||
const id = this.panels.aspectRatio.GetSelected().id; | ||
switch (id) { | ||
case 'aspectratio0': | ||
return 4 / 3; | ||
case 'aspectratio1': | ||
return 16 / 9; | ||
case 'aspectratio2': | ||
return 16 / 10; | ||
} | ||
return Number.NaN; | ||
} | ||
|
||
// 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)); | ||
} | ||
|
||
static horizontalToFov(horizontalFov) { | ||
const ratioRatio = this.aspectRatio() / (4 / 3); | ||
return 2 * rad2deg(Math.atan(Math.tan(deg2rad(horizontalFov) / 2) / ratioRatio)); | ||
} | ||
|
||
static updateFOV() { | ||
if (!this.panels.fov || !this.panels.horizontalFov) return; | ||
|
||
let fov = GameInterfaceAPI.GetSettingFloat('fov_desired'); | ||
fov = Math.round(this.fovToHorizontal(fov)); | ||
|
||
if (!Number.isNaN(fov)) { | ||
this.panels.horizontalFov.text = fov; | ||
} | ||
} | ||
|
||
static updateHorizontalFov() { | ||
if (!this.panels.fov || !this.panels.horizontalFov) return; | ||
|
||
let fov = Number.parseFloat(this.panels.horizontalFov.text); | ||
fov = Math.round(this.horizontalToFov(fov)); | ||
|
||
if (!Number.isNaN(fov)) { | ||
const fovText = this.panels.fov.FindChildTraverse('Value'); | ||
fovText.text = fov; | ||
fovText.Submit(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters