This repository has been archived on 2024-12-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2024CG-project-render/src/viewing_ray.cpp
Tibo De Peuter 08c5c9e8da
fix: Vertical flip
Fix the difference in (0,0) assumption of jpg and computer graphics.
2024-10-05 17:32:28 +02:00

23 lines
666 B
C++

#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;
}