I've been reading some code which setups a ray tracer and I've realized I've a doubt regarding what's a screen and what's a window in this context. Here's the relevant code using Qt:
...
void CCanvas::paint()
{
// check if we have something to draw on
if (!image) return;
// camera position
Point3d camera (0.0, 0.0, 0.0);
// screen resolution
int w = image->width();
int h = image->height();
// horizontal opening angle
double alpha = PI/2.0;
// horizontal window dimension [-X,X]
double X = tan(alpha/2.0);
// pixel size
double s = 2.0 * X / (double)w;
// vertical window dimension [-Y,Y]
double Y = s * h / 2.0;
...
I think I know what's the screen resolution: if we think of the screen as a matrix, w
and h
would be respectively the number of columns and rows in this "matrix".
After obtaining the resolution of the image, we define an opening angle $\alpha$. I interpreted this opening angle as the opening angle of the camera, i.e., it defines basically what's visible from the camera.
Then we compute X
, which is half of the horizontal window (according to the comments in the code). (Note this X
is not the same X representing the x axis in the picture below. Yes, whoever wrote this code had no common sense!)
Now, mathematically I understood these calculations, what I don't understand is the difference between $2X$ and $w$.
Is the "window" here the same thing as "screen"?
I've this picture here
I've added the $X=\tan \left( \frac{\alpha}{2}\right)$ to the picture according to what I think $X$ is from the code above.
If the window is the same thing as the screen, I wonder why do we need $w$. I mean, couldn't we just decide how many rows and columns we have in the visible area?
Again, it's not clear if the visible area of the camera is the same thing as the screen or window...