I was doing a code for raytracing based on this tutorial: https://youtu.be/AARMPhL9d6g, but at the minute 3:30 there is this code below to adjust the image aspect ratio, but I can't understand the logic behind this adjust in ratio:
if (width > height)
{
xamnt = (x + 0.5) / (double)height - ((width - height) / (double)height) / 2;
yamnt = ((height - y) + 0.5) / height;
}
else if (height > width)
{
xamnt = (x + 0.5) / width;
yamnt = (height - y + 0.5) / (double)width - ((height - width) / (double)width) / 2;
}
else
{
xamnt = ((x + 0.5) / width);
yamnt = (((height - y) + 0.5) / height);
}
I tried to found some aswer in https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-generating-camera-rays/generating-camera-rays.html but things are done very different here.