(Ray tracing) Trouble converting to screen coordinates, objects being stretched I followed along with Ray Tracing in One Weekend and managed to get the final output but I wanted to understand more about creating a camera and &quot;painting&quot; the screen since he didn't go over it much.
When I tried using a different way of creating a camera by spheres actually get elongated, making them look like more like ellipses. I've tried modifying the x and y assignments in screenCords but I've only managed to make more errors (such as objects wrapping around to the opposite side)
Camera.h:
#pragma once

#include &quot;../Matrix.h&quot;
#include &quot;../Defs.h&quot;
#include &quot;Defs.h&quot;

template&lt;typename O&gt;
using Point3 = Vec3&lt;O&gt;;

template&lt;typename O&gt;
using Color = Vec3&lt;O&gt;;

template &lt;typename O&gt;
class Camera{
  O Height;
  O Width;
  Vec3&lt;O&gt; Forward, Right, Up;
  Point3&lt;O&gt; Origin;

public:
  Camera(O fov, O aspect_ratio, Point3&lt;O&gt; origin, Point3&lt;O&gt; target, Vec3&lt;O&gt; upguide) {
    Height = atan(degrees_to_radians(fov));
    Width = Height * aspect_ratio;
    
    Origin = origin;

    Forward = target - origin;
    Forward.normalize();
    Right = Forward.cross(upguide);
    Right.normalize();
    Up = Right.cross(Forward);

    }

    Ray&lt;O&gt; get_raydir(O right, O up){
      Vec3&lt;O&gt; result(Forward + right * Width * Right + up * Height * Up); result.normalize();

      return Ray&lt;O&gt;(Origin, result);
    }

    void screenCords(O &amp;x, O &amp;y, O width, O height){
      x = ((2.0f * x) / width) -1.0f;
      y = ((2.0f * y) / height); 
    }
};

Main.cpp
#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &quot;../Matrix.h&quot;
#include &quot;Camera.h&quot;
#include &lt;vector&gt;
#include &quot;Image.h&quot;
#include &quot;Shapes.h&quot;
#include &quot;Tracer.h&quot;
#include &quot;../Defs.h&quot;

template&lt;typename O&gt;
using Point3 = Vec3&lt;O&gt;;

template&lt;typename O&gt;
using Color = Vec3&lt;O&gt;;

int main(){
  const int img_ratio = 2;
  const int img_width = 640;
  const int img_height = 480;
  const int depth = 50; float t_Max = infinity; float t_Min = 0.001;

  float inv_width = 1 / float(img_width);
  float inv_height = 1 / float(img_height);

  std::vector&lt;Sphere&lt;float&gt;&gt; shapes;

  Camera&lt;float&gt; cam1(20.0f, img_ratio, Point3&lt;float&gt;(0.0f, 0.0f, 0.0f), Point3&lt;float&gt;(0.0f, 0.0f, -1.0f), Vec3&lt;float&gt;(0.0f, 1.0f, 0.0f));

  Sphere&lt;float&gt; cir1(0.2f, Point3&lt;float&gt;(0.2f, 0.0f, -1.0f));
  Sphere&lt;float&gt; cir2(7.0f, Point3&lt;float&gt;(0.0f, -7.0f, -1.0f));
  Sphere&lt;float&gt; cir3(0.5f, Point3&lt;float&gt;(1.0f, 0.0f, -1.0f));
  shapes.push_back(cir1);
  //shapes.push_back(cir2);
  //shapes.push_back(cir3);

  Tracer&lt;float&gt; tracer(shapes);

  std::cout &lt;&lt; &quot;P3\n&quot; &lt;&lt; img_width &lt;&lt; ' ' &lt;&lt; img_height &lt;&lt; &quot;\n255&quot; &lt;&lt; std::endl;

  Ray&lt;float&gt; ray(Point3&lt;float&gt;(0.0f), Vec3&lt;float&gt;(0.0f));

  for (int j = 0; j &lt; img_height; j++)
  {
    std::cerr &lt;&lt; &quot;\rScanlines remaining: &quot; &lt;&lt; j &lt;&lt; ' ' &lt;&lt; std::flush;
    for (int i = 0; i &lt; img_width; i++){

        float x = i;
        float y = j;

        cam1.screenCords(x, y, img_width, img_height);

        ray = cam1.get_raydir(x, y);
        //ray = Ray&lt;float&gt;(Vec3&lt;float&gt;(x1, y1, 1), Point3&lt;float&gt;(0.0f, 0.0f, 0.0f));
        tracer.iterator(ray, depth, t_Max, t_Min);
    }
  }
  std::cerr &lt;&lt; &quot;\n done &quot; &lt;&lt; std::endl;
}

I suspect the error is in one of these files since the spheres are actually being drawn with the colors based on normals (with the top and bottom normal colors unsurprisingly being bugged)
Here are a few examples of the output:
It looks like the parameters to your camera class are not correct
 const int img_ratio = 2;
 ...
 Camera&lt;float&gt; cam1(20.0f, img_ratio, Point3&lt;float&gt;(0.0f, 0.0f, 0.0f), Point3&lt;float&gt;(0.0f, 0.0f, -1.0f), Vec3&lt;float&gt;(0.0f, 1.0f, 0.0f));

In your code you set img_ratio to 2, I would expect it should be something like img_width/img_height (or the reverse img_height/img_width). img_ratio should also be also be a floating point to match the  type the camera class is being instantiated with.