Last active
February 15, 2016 07:47
-
-
Save kahrl/379e39767da95ff16bc7 to your computer and use it in GitHub Desktop.
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
%% Octave code | |
format long | |
% First, some utility functions | |
% Convert degrees to radians | |
deg2rad = @(x) x * pi / 180; | |
% Convert radians to degrees | |
rad2deg = @(x) x * 180 / pi; | |
% Compute the angle between two vectors | |
vector_angle = @(v,w) acos(dot(v,w) / (norm(v) * norm(w))); | |
% The inputs for our calculation | |
% Aspect ratio of a default minetest window (e.g. 800/600) | |
aspect_ratio = 4/3; | |
% Default (vertical) field of view in radians | |
fov_y = deg2rad(72); | |
% The horizontal field of view | |
fov_x = aspect_ratio * fov_y; | |
% Now, the calculation | |
% Assume we are looking in +Z direction (the direction has no effect on the end result) | |
center_of_screen = [0, 0, 1]; | |
corner_of_screen = [tan(fov_x/2), tan(fov_y/2), 1]; | |
angle_to_corner = vector_angle(center_of_screen, corner_of_screen); | |
camera_fov = max(fov_x, fov_y); | |
required_factor = angle_to_corner / (camera_fov / 2) | |
% | |
% Output: required_factor = 1.10421165985322 | |
% | |
% Changing the inputs (e.g. aspect_ratio = 1, fov_y = deg2rad(0.1)) | |
% results in required_factor approaching sqrt(2) as fov_y gets close to zero. | |
% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment