Raytracer
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Raytracer::Core::Camera Class Reference

Public Member Functions

void setup ()
 Set up the camera with the given parameters.
 
void render (const Interfaces::IHittable &world)
 Render the scene with the given camera.
 
Core::Ray getRay (double u, double v) const
 Get the ray for the given pixel.
 
Utils::Vec3 sampleSquare () const
 Sample a square.
 
Utils::Vec3 sampleDisk (double radius) const
 Sample a disk.
 
Utils::Vec3 sampleDefocusDisk () const
 Sample the defocus disk.
 
Utils::Color rayColor (const Ray ray, int depth, const Interfaces::IHittable &world) const
 Get the color of the ray.
 
void progress (const std::chrono::steady_clock::time_point &start, int j) const
 Print the progress of the rendering.
 

Member Function Documentation

◆ getRay()

Raytracer::Core::Ray Raytracer::Core::Camera::getRay ( double i,
double j ) const

Get the ray for the given pixel.

This function calculates the sample location based on the pixel location and the pixel delta u and v vectors. The origin is set to the center of the camera if the defocus angle is less than or equal to 0. Otherwise, the origin is set to a point on the defocus disk. The direction is set to the sample location minus the origin. The time is set to a random double.

Parameters
iThe x coordinate of the pixel.
jThe y coordinate of the pixel.
Returns
The ray for the given pixel.

◆ progress()

void Raytracer::Core::Camera::progress ( const std::chrono::steady_clock::time_point & start,
int j ) const

Print the progress of the rendering.

This function prints the progress of the rendering to the standard error stream. The progress is printed as a percentage and the time elapsed is printed in seconds.

Parameters
startThe start time of the rendering.
jThe y coordinate of the pixel.
Returns
void

◆ rayColor()

Raytracer::Utils::Color Raytracer::Core::Camera::rayColor ( const Ray ray,
int depth,
const Interfaces::IHittable & world ) const

Get the color of the ray.

This function returns the color of the ray based on the depth and the world. If the depth is less than or equal to 0, the function returns black. If the ray does not hit anything in the world, the function returns the background color. If the ray scatters, the function returns the emission color plus the scatter color.

Parameters
rayThe ray to get the color of.
depthThe depth of the ray.
worldThe world to get the color from.
Returns
The color of the ray.

◆ render()

void Raytracer::Core::Camera::render ( const Interfaces::IHittable & world)

Render the scene with the given camera.

This function sets up the camera and prints the PPM header. It then loops through each pixel in the image and calculates the pixel color based on the number of samples per pixel. The pixel color is then written to the output stream.

Parameters
worldThe world to render.
Returns
void

◆ sampleDefocusDisk()

Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDefocusDisk ( ) const

Sample the defocus disk.

This function returns a random point in the defocus disk.

Returns
A random point in the defocus disk.

◆ sampleDisk()

Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleDisk ( double radius) const

Sample a disk.

This function returns a random point in a disk centered at the origin with a radius of 1.

Parameters
radiusThe radius of the disk.
Returns
A random point in a disk.

◆ sampleSquare()

Raytracer::Utils::Vec3 Raytracer::Core::Camera::sampleSquare ( ) const

Sample a square.

This function returns a random point in a square centered at the origin with a side length of 1.

Returns
A random point in a square.

◆ setup()

void Raytracer::Core::Camera::setup ( )

Set up the camera with the given parameters.

This function calculates the image height based on the aspect ratio and the image width. It also calculates the viewport height and width based on the vertical field of view and the focus distance. The pixel sample scale is calculated based on the number of samples per pixel. The camera's center is set to the look from point. The camera's u, v, and w vectors are calculated based on the look from, look at, and v up points. The viewport u and v vectors are calculated based on the viewport width and height and the u and v vectors. The pixel delta u and v vectors are calculated based on the viewport u and v vectors and the image width and height. The pixel zero location is calculated based on the viewport upper left corner and the pixel delta u and v vectors. The defocus disk u and v vectors are calculated based on the defocus angle and the u and v vectors.

Returns
void

The documentation for this class was generated from the following files: