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... | |
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.
hsize | Stores the horizontal size (in pixels). |
vsize | Stores the vertical size (in pixels). |
field_of_view | This 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_width | Stores the camera's half hsize value. |
half_height | Stores the camera's half vsize value. |
pixel_size | Stores the camera's pixel size calculated from half_width and hsize values. |
transform | Stores the transformation matrix for the camera. |
inverse | Stores the inverse matrix for the camera. |
transpose | Stores the transpose matrix for the 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.
hsize | The horizontal size (in pixels) of the canvas that the picture will be rendered to. |
vsize | The vertical size (in pixels) of the canvas that the picture will be rendered to. |
field_of_view | The 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. |
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.
camera | Pointer to the camera object. |
px | The horizontal coordinate of the pixel on the camera plane. |
py | The vertical coordinate of the pixel on the camera plane. |
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.
from | The position of the camera in the world. |
to | The point in the world to look at. |
up | A vector indicating which direction is up. |