Thanks guys.
I am using C++ with no libraries.
My camera class:
Camera::Camera(const Vec3 & p, const Vec3 & l, double fov, double aspect)
{
position = p;
lookAt = l;
this->fov = fov;
aspectRatio = aspect;
Vec3 tempUp(0, 1, 0);
forward = (lookAt - position).normalized();
right = cross(forward, tempUp).normalized();
up = cross(right, forward);
HEIGHT = tan(fov);
WIDTH = HEIGHT * aspectRatio;
}
Ray Camera::GetRay(unsigned x, unsigned y, unsigned H, unsigned W, double antiOffsetX, double antiOffsetY)
{
double X, Y;
X = (2.0*(double)x) / (double)W - 1.0 + antiOffsetX;
Y = (-2.0*(double)y) / (double)H + 1.0 - antiOffsetY;
Vec3 direction =
forward + X * WIDTH * right + Y * HEIGHT * up;
return Ray(position, direction.normalized());
}
I was about to post this but checked the code in main where I make the camera:
Camera camera(Vec3(0.0, 1.0, 10.0), Vec3(0.0, 1.0, 0.0), PI / 4.0,WIDTH / HEIGHT);
And sure enough, WIDTH and HEIGHT were unsigned ints lol so aspectRatio was always one.
God damn :P I must have been tired last night lol.
THANKS!
16:9