#include "viewing_ray.h" void viewing_ray( const Camera & camera, const int i, const int j, const int width, const int height, Ray & ray) { /** * Based on * Fundamentals in Computer Graphics - Fourth Edition, Chapter 4.3.2 Perspective views. * Steve Marschner & Peter Shirley */ /* Determine the direction of the ray, using the camera and pixel location. */ double u = 0 - camera.width / 2 + camera.width * (j + 0.5) / width; double v = 0 - camera.height / 2 + camera.height * (i + 0.5) / height; ray.origin = camera.e; ray.direction = (0 - camera.d) * camera.w + u * camera.u + v * camera.v; }