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/lab1/viewing_ray.cpp
Tibo De Peuter d9cf26902e
Some checks failed
CMake / build (zip, zip, [self-hosted Linux], raytracing, ux) (push) Has been cancelled
CMake / build (zip, zip, [self-hosted Windows], Release/raytracing.exe, win) (push) Has been cancelled
chore: Cleanup
2024-10-25 17:50:44 +02:00

23 lines
856 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;
/* NOTE I flipped the vertical axis of the pixels, because in computer graphics we assume the bottom left pixel
* is (0,0), while traditional jpg assumes (0,0) to be the upper left pixel. */
ray.direction = (0 - camera.d) * camera.w + u * camera.u - v * camera.v;
}