Widescreen FOV (Field Of View) Calculator
Posted: Tue Apr 07, 2009 1:57 am
This is my Widescreen FOV (Field Of View) Calculator port
of my PHP original at: http://emsai.net/projects/widescreen/fovcalc/
PS! I know the results differ slightly... welcome to the world of floating point and it's various implementations.
There is also a simple FOV calculation commented out, a lot of the "calcs" out there probably uses that one, the one I use is based on the headache inducing math of Tan, ATan, PI, and degrees.
See Wikipedia for more: http://en.wikipedia.org/wiki/Field_of_v ... rocessing)
I also ported the oh so simple, but seemingly magic string parsers that supports the three most common ways to express aspect ratio plus resolution to aspect ratio conversion too.
of my PHP original at: http://emsai.net/projects/widescreen/fovcalc/
PS! I know the results differ slightly... welcome to the world of floating point and it's various implementations.
There is also a simple FOV calculation commented out, a lot of the "calcs" out there probably uses that one, the one I use is based on the headache inducing math of Tan, ATan, PI, and degrees.
See Wikipedia for more: http://en.wikipedia.org/wiki/Field_of_v ... rocessing)
I also ported the oh so simple, but seemingly magic string parsers that supports the three most common ways to express aspect ratio plus resolution to aspect ratio conversion too.
Code: Select all
;FOV (Field Of View) Calculator v1.0 (C) Roger Hågensen, EmSai 2009 http://EmSai.net/
;
;This software is provided 'as-is', without any express or implied
;warranty. In no event will the authors be held liable for any damages
;arising from the use of this software.
;
;Permission is granted to anyone to use this software for any purpose,
;including commercial applications, and to alter it and redistribute it
;freely, subject to the following restrictions:
;
;1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
;2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
;3. This notice may not be removed or altered from any source distribution.
EnableExplicit
Procedure.d AspectStringToDouble(aspect$)
Protected result.d,pos.i
aspect$=LCase(aspect$)
pos=FindString(aspect$,"x",1)
If pos=0
pos=FindString(aspect$,":",1)
EndIf
If pos
result=ValD(Trim(Mid(aspect$,1,pos)))/ValD(Trim(Mid(aspect$,pos+1)))
Else
result=ValD(aspect$)
EndIf
ProcedureReturn result
EndProcedure
Procedure.d CalculateFOV(oldaspect.d,oldfov.d,newaspect.d)
Protected result.d
result=(ATan(Tan((oldfov*#PI)/360.0)*(newaspect/oldaspect))*360.0)/#PI
; result=oldfov*(newaspect/oldaspect) ;simple and crude, rough, not as accurate, but very fast.
ProcedureReturn result
EndProcedure
Define oldaspect.d,oldfov.d,newaspect.d,newfov.d
Debug AspectStringToDouble("1680x1050")
Debug AspectStringToDouble("16:10")
Debug AspectStringToDouble("1.6")
Debug AspectStringToDouble("1.6:1")
Debug ""
Debug "1024x768 (aspect ratio), old FOV 90, new aspect is 1680x1050"
oldaspect=1024/768 ;AspectStringToDouble("1024x768")
oldfov=90.0
newaspect=1680/1050 ;AspectStringToDouble("1680x1050")
newfov=CalculateFOV(oldaspect,oldfov,newaspect)
Debug newfov