miniRT
By Marcelo Magalhães and Ygor G. Sena, 2023.
All Data Structures Files Functions Typedefs Pages
rays.h File Reference
#include "matrices.h"
Include dependency graph for rays.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_ray
 The struct of type t_ray represents a ray, which is the foundation for ray casting. Ray casting is the process of creating a ray, or line, and finding the intersections of that ray with the objects in a scene. More...
 

Typedefs

typedef struct s_ray t_ray
 The struct of type t_ray represents a ray, which is the foundation for ray casting. Ray casting is the process of creating a ray, or line, and finding the intersections of that ray with the objects in a scene. More...
 

Functions

t_ray new_ray (t_point origin, t_vector direction)
 The function new_ray() creates and queries a ray with the given origin and direction passed as parameter. More...
 
t_point position (t_ray ray, float distance)
 The function position() finds the position of a given ray and a given time or distance. To find a ray's position, it's necessary to multiply the ray direction by time or distance to find the total distance traveled and add the result to the ray's origin. More...
 
t_ray transform (t_ray ray, t_matrix matrix)
 The function transform() multiplies a given ray by a given matrix, which results in an unnormalized ray. In other words, whatever wanted transformation to be applied to a world's object is applied instead in the ray by the inverse of the operation intended on a world's object. For more information, refer to the book TRTC on page 66. More...
 

Typedef Documentation

◆ t_ray

typedef struct s_ray t_ray

The struct of type t_ray represents a ray, which is the foundation for ray casting. Ray casting is the process of creating a ray, or line, and finding the intersections of that ray with the objects in a scene.

Parameters
originStores the starting point of a ray.
directionStores the vector which says where a ray points to.

Function Documentation

◆ new_ray()

t_ray new_ray ( t_point  origin,
t_vector  direction 
)

The function new_ray() creates and queries a ray with the given origin and direction passed as parameter.

Parameters
originReceives a point tuple, which is starting point of the ray.
directionReceives a vector tuple, which is the direction where the ray points to.
Returns
Sucessfully returns a new ray with the given origin and direction passed as parameter to the function.

◆ position()

t_point position ( t_ray  ray,
float  distance 
)

The function position() finds the position of a given ray and a given time or distance. To find a ray's position, it's necessary to multiply the ray direction by time or distance to find the total distance traveled and add the result to the ray's origin.

Parameters
rayReceives a ray as reference.
distanceReceives a float value which is the time or distance that the ray must travel.
Returns
Returns the ray's coordinates after it traveled for a given time or after it gone through a given distance.

◆ transform()

t_ray transform ( t_ray  ray,
t_matrix  matrix 
)

The function transform() multiplies a given ray by a given matrix, which results in an unnormalized ray. In other words, whatever wanted transformation to be applied to a world's object is applied instead in the ray by the inverse of the operation intended on a world's object. For more information, refer to the book TRTC on page 66.

Parameters
rayReceives a ray to the transformed.
matrixReveives the matrix transformation to be applied in the ray.
Returns
Successfully returns a new unnormalized and transformed ray.