This repository has been archived by the owner on Aug 15, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added fov & fovconvert commands and fov helper functions (#133)
* feat: added fov command and fov helper functions * feat: added fovconvert command and associated helper functions * docs: added relevant documentation for fovconvert command
- Loading branch information
Showing
10 changed files
with
188 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,26 @@ | ||
import { Argument, PieceContext, ArgumentContext } from '@sapphire/framework' | ||
|
||
export default class GameArgument extends Argument<number> { | ||
public constructor(context: PieceContext) { | ||
super(context, { name: 'aspectRatio' }) | ||
} | ||
|
||
public run(parameter: string, context: ArgumentContext) { | ||
if (/\d{1,4}:\d{1,4}/.test(parameter)) { | ||
const split = parameter.split(':') | ||
return this.ok(Number(split[0]) / Number(split[1])) | ||
} | ||
return this.error({ | ||
parameter, | ||
message: 'Not valid aspect ratio', | ||
identifier: 'aspectRatioNoSupport', | ||
context, | ||
}) | ||
} | ||
} | ||
|
||
declare module '@sapphire/framework' { | ||
interface ArgType { | ||
aspectRatio: number | ||
} | ||
} |
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
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
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,107 @@ | ||
export function convertFOV( | ||
fov: number, | ||
inputAspect: number, | ||
outputAspect: number | ||
) { | ||
return ( | ||
(Math.atan( | ||
(outputAspect / inputAspect) * Math.tan((fov * Math.PI) / 360) | ||
) * | ||
360) / | ||
Math.PI | ||
) | ||
} | ||
|
||
export function filmToAspect(filmNotation: string) { | ||
const startString = filmNotation.split(/M/)[0] | ||
const endString = filmNotation.split(/M[FLI]/)[1] | ||
return Number(startString) / Number(endString) | ||
} | ||
|
||
export function filmToTrue( | ||
fov: number, | ||
film: string, | ||
aspectRatio: number | ||
): fovValues { | ||
const filmAspect = filmToAspect(film) | ||
if (/^\d{1,2}MS\d{1,2}$/.test(film)) { | ||
return { | ||
horizontalFOV: fov, | ||
verticalFOV: convertFOV(fov, filmAspect, 1), | ||
} | ||
} else if (film.startsWith('H')) { | ||
return lockHorizontal(fov, aspectRatio) | ||
} else if (film.startsWith('V')) { | ||
return lockVertical(fov, aspectRatio) | ||
} else if (/^\d{1,2}ML\d{1,2}$/.test(film)) { | ||
return lockVertical(fov, aspectRatio, filmAspect) | ||
} else if (/^\d{1,2}MF\d{1,2}$/.test(film)) { | ||
if (aspectRatio > filmAspect) { | ||
return lockHorizontal(fov, aspectRatio) | ||
} | ||
return lockVertical(fov, aspectRatio, filmAspect) | ||
} else if (/^\d{1,2}MI\d{1,2}$/.test(film)) { | ||
if (aspectRatio < filmAspect) { | ||
return lockHorizontal(fov, aspectRatio) | ||
} | ||
return lockVertical(fov, aspectRatio, filmAspect) | ||
} | ||
throw Error('parsing failed') | ||
} | ||
|
||
export function trueToFILM( | ||
{ horizontalFOV, verticalFOV }: fovValues, | ||
film: string, | ||
aspectRatio: number | ||
): number { | ||
const filmAspect = filmToAspect(film) | ||
if (/^\d{1,2}MS\d{1,2}$/.test(film) || film.startsWith('H')) { | ||
return horizontalFOV | ||
} else if (film.startsWith('V')) { | ||
return verticalFOV | ||
} else { | ||
return convertFOV(horizontalFOV, filmAspect, aspectRatio) | ||
} | ||
} | ||
|
||
export function lockVertical( | ||
fov: number, | ||
aspectRatio: number, | ||
filmAspect?: number | ||
): fovValues { | ||
if (filmAspect) { | ||
return { | ||
horizontalFOV: convertFOV(fov, filmAspect, aspectRatio), | ||
verticalFOV: convertFOV(fov, filmAspect, 1), | ||
} | ||
} | ||
return { | ||
horizontalFOV: convertFOV(fov, 1, aspectRatio), | ||
verticalFOV: fov, | ||
} | ||
} | ||
|
||
export function lockHorizontal(fov: number, aspectRatio: number): fovValues { | ||
return { | ||
horizontalFOV: fov, | ||
verticalFOV: convertFOV(fov, aspectRatio, 1), | ||
} | ||
} | ||
|
||
export interface fovValues { | ||
horizontalFOV: number | ||
verticalFOV: number | ||
} | ||
|
||
export function filmToFilm( | ||
fov: number, | ||
inFILM: string, | ||
outFILM: string, | ||
aspectRatio: number | ||
): number { | ||
return trueToFILM( | ||
filmToTrue(fov, inFILM, aspectRatio), | ||
outFILM, | ||
aspectRatio | ||
) | ||
} |