<?php
/* simple FOV calculator for BF:BC2
 * author: rjdown@gmail.com
 * use/abuse as needed, no credits wanted
 */

if (isset($_POST['submit'])) {
    
$onload="";
    if (isset(
$_POST['height']) && is_numeric($_POST['height']) &&
        isset(
$_POST['width']) && is_numeric($_POST['width']) &&
        isset(
$_POST['hfov']) && is_numeric($_POST['hfov'])
    ) {
        
$height intval($_POST['height']);
        
$width  intval($_POST['width']);
        
$hfov   intval($_POST['hfov']);

        
// convert to radians
        
$hfovRad deg2rad($hfov);

        
// calculate vfov
        
$vfovRad 2*atan(tan($hfovRad/2)*($height/$width));

        
// convert back to degrees
        
$vfov    rad2deg($vfovRad);

        
// round up
        
$vfov ceil($vfov);
        
$message 'Calculated vertical FOV setting: <span id="vfov">' $vfov '</span>';
    }
    else {
        
$message '<span class="error">You must complete all fields!</span>';
    }
}
else {
    
$onload ' onload="init();"';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Battlefield: Bad Company 2 FOV Calculator</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link type="image/x-icon" rel="shortcut icon" href="favicon.ico">
        <link type="text/css" rel="stylesheet" href="style.css">
        <script type="text/javascript" src="script.js"></script>
    </head>
    <body<?php echo $onload?>>
        <div id="google_translate_element"></div>
        <script type="text/javascript">
            function googleTranslateElementInit() {
                new google.translate.TranslateElement({
                    pageLanguage: 'en'
                }, 'google_translate_element');
            }
        </script>
        <script type="text/javascript" src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
        <div id="fovform">
            <form action="" method="post" onsubmit="return validate();">
                <h2>Battlefield: BC2 FOV Calculator</h2>
                <p><label for="width">Screen width</label><input name="width" id="width" type="text"<?php if(isset($_POST['width'])) { echo ' value="' $_POST['width'] . '"'; } ?>> pixels or aspect ratio</p>
                <p><label for="height">Screen height</label><input name="height" id="height" type="text"<?php if(isset($_POST['height'])) { echo ' value="' $_POST['height'] . '"'; } ?>></p>
                <p><label for="hfov">Desired horizontal FOV</label><input name="hfov" id="hfov" type="text" value="<?php echo isset($_POST['hfov']) ? $_POST['hfov'] : "90"?>"> degrees</p>
                <p id="message"><?php if (isset($message)) { echo $message; } ?></p>
                <p><input name="submit" id="submit" type="submit" value="Calculate vertical FOV"></p>
            </form>
        </div>
        <div id="info">
            <h2>Explanation</h2>
            <p>FOV (Field of View) determines how much of your surrounding area you can see without turning.</p>
            <p>Usually in FPS games where this is configurable, you adjust the horizontal field of view so you can see more to the left and right. Battlefield: Bad Company 2 uses vertical FOV instead, so it's a little harder to work out what you need to set it to. Here's the formula, bearing in mind it works in <em>radians</em>, not degrees:</p>
            <p><img src="fov.png" alt="FOV formula"></p>
            <p>Not really something you can do in your head, huh? :D So, simply enter your in-game screen resolution (or aspect ratio) and preferred horizontal FOV above and click the calculate button.</p>
            <p>There's currently no way to change this setting in-game, so you'll need to update your settings.ini file manually. The default location is "My Documents\BFBC2". Open it with notepad and find the line that says something like "fov=55", change the number and save the file. If you can't find this line, you'll need to add it yourself. Just make sure it's somewhere under "[Graphics]".</p>
            <p>Note: You'll need to restart BC2 before it starts working.</p>
            <p>&nbsp;</p>
            <p>The source code for this PHP page is available <a href="fovcalculator.phps">here</a>.</p>
            <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                Did you find this page useful? Click here to buy me a pint:
                <input type="hidden" name="cmd" value="_s-xclick">
                <input type="hidden" name="hosted_button_id" value="TNNFWTZZFKD8E">
                <input type="image" src="http://rjdown.co.uk/projects/bfbc2/pint.png" name="submit" alt="Buy me a pint through PayPal :D">
                <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"> Cheers, Rich aka Rulesy :D
            </form>
        </div>
    </body>
</html>