miniRT
By Marcelo Magalhães and Ygor G. Sena, 2023.
camera.h File Reference
#include "tuples.h"
#include "matrices.h"
#include "rays.h"
Include dependency graph for camera.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_camera
 The structure of type t_camera contains the necessary information for camera configuration, rendering and transformation. More...
 

Typedefs

typedef struct s_camera t_camera
 The structure of type t_camera contains the necessary information for camera configuration, rendering and transformation. More...
 

Functions

t_matrix view_transform (t_point from, t_point to, t_vector up)
 Computes the view transformation matrix given the position of the camera and the point to look at. More...
 
t_camera new_camera (float hsize, float vsize, float field_of_view)
 Creates a new camera with the given attributes. More...
 
t_ray ray_for_pixel (t_camera *camera, float px, float py)
 Computes the ray that passes through the specified pixel on the camera plane. More...
 

Typedef Documentation

◆ t_camera

typedef struct s_camera t_camera

The structure of type t_camera contains the necessary information for camera configuration, rendering and transformation.

ABOUT THE HEADER CAMERA.H

This header contains all functions regarding camera implementation.

Parameters
hsizeStores the horizontal size (in pixels).
vsizeStores the vertical size (in pixels).
field_of_viewThis field stores angle that describes how much the camera can see. When the field of view is small, the view will be "zoomed in", magnifying a smaller area of the scene.
half_widthStores the camera's half hsize value.
half_heightStores the camera's half vsize value.
pixel_sizeStores the camera's pixel size calculated from half_width and hsize values.
transformStores the transformation matrix for the camera.
inverseStores the inverse matrix for the camera.
transposeStores the transpose matrix for the camera.

Function Documentation

◆ new_camera()

t_camera new_camera ( float  hsize,
float  vsize,
float  field_of_view 
)

Creates a new camera with the given attributes.

This function creates a virtual camera that can be used to "take pictures" of a three-dimensional scene. The camera is defined by its horizontal and vertical size in pixels, the field of view angle, and a transform matrix that orients the world relative to the camera.

Parameters
hsizeThe horizontal size (in pixels) of the canvas that the picture will be rendered to.
vsizeThe vertical size (in pixels) of the canvas that the picture will be rendered to.
field_of_viewThe angle that describes how much the camera can see. When the field of view is small, the view will be "zoomed in", magnifying a smaller area of the scene.
Returns
Returns the instance of a new camera.

◆ ray_for_pixel()

t_ray ray_for_pixel ( t_camera camera,
float  px,
float  py 
)

Computes the ray that passes through the specified pixel on the camera plane.

This function takes a camera and the pixel coordinates on the camera plane as input, and returns a ray with its origin at the camera position and its direction passing through the center of the pixel. To compute the ray, the function first calculates the displacement of the pixel center relative to the canvas edge, and then computes the non-transformed world coordinates of the pixel. Next, using the camera's transformation matrix, the function transforms the canvas point and the origin (0,0,0) to world coordinates. Based on these transformed coordinates, the function computes the direction of the ray from the origin to the pixel point, normalizing the resulting vector to ensure that it has unit length.

Parameters
cameraPointer to the camera object.
pxThe horizontal coordinate of the pixel on the camera plane.
pyThe vertical coordinate of the pixel on the camera plane.
Returns
Returns a ray that passes through the specified pixel on the camera plane.

◆ view_transform()

t_matrix view_transform ( t_point  from,
t_point  to,
t_vector  up 
)

Computes the view transformation matrix given the position of the camera and the point to look at.

This function returns a transformation matrix that orients the world relative to the camera's eye. You specify the position of the camera with the from parameter, the point to look at with the to parameter, and a vector indicating which direction is up with the up parameter.

Parameters
fromThe position of the camera in the world.
toThe point in the world to look at.
upA vector indicating which direction is up.
Returns
Returns the view transformation matrix.