Last active
July 20, 2022 21:44
-
-
Save Lokno/f4c2f6e1aa887440445d7682634763ad to your computer and use it in GitHub Desktop.
Lines 7-24 was generated by OpenAI's davinci-codex using Lines 1-6. Lines 27-33 were generated with only Lines 25-26
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
// I have a plane of size A,B in 3D space. I have a camera, which is pointed dead-on at the plane. The camera is mapping the plane into a window of size X,Y. | |
// How far Z should the camera be away from the plane for the *entire* plane to be visible? | |
// | |
// Find the minimum distance where the entire plane is in view | |
float get_distance( float plane_width, float plane_height, float fov ) | |
{ | |
float half_width = plane_width / 2.0f; | |
float half_height = plane_height / 2.0f; | |
float half_fov = fov / 2.0f; | |
float distance = half_width / tan( half_fov ); | |
return distance; | |
} | |
// Find the distance where the plane is centered in the view | |
float get_distance_center( float plane_width, float plane_height, float fov ) | |
{ | |
float half_width = plane_width / 2.0f; | |
float half_height = plane_height / 2.0f; | |
float half_fov = fov / 2.0f; | |
float distance = half_width / tan( half_fov ) + half_height; | |
return distance; | |
} | |
// Find the minimum distance where the entire plane is in view | |
float get_distance( float plane_width, float plane_height, float fov ) | |
{ | |
float distance = 0.0f; | |
float plane_diagonal = sqrt( plane_width * plane_width + plane_height * plane_height ); | |
float diagonal_fov = 2.0f * atanf( plane_diagonal / ( 2.0f * fov ) ); | |
distance = plane_diagonal / tanf( diagonal_fov / 2.0f ); | |
return distance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment