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

Go to the source code of this file.

Data Structures

struct  s_checker
 This structure encapsulates the function uv_checkers(). More...
 
struct  s_uv_image
 The struct of type t_uv_image represents an image used for texturing another image. More...
 
struct  s_text_map
 This structure creates a t_pattern subclass (the same as t_pttr_at, which calls stripe_at() or checkered_at()). t_text_map is a subclass that uses spherical_map(), planar_map() or cylindrical_map() to define how to apply a pattern on a given 2D or 3D shape's surface. More...
 
struct  s_pattern
 The type t_pattern contatins all the necessary information to apply a texture on a given shape's surface. More...
 

Typedefs

typedef struct s_pattern t_pattern
 The type t_pattern contatins all the necessary information to apply a texture on a given shape's surface. More...
 
typedef struct s_checker t_checker
 This structure encapsulates the function uv_checkers(). More...
 
typedef t_color(* t_pttr_at) (t_pattern pattern, t_point world_point)
 t_pttr_at is a function-type that receives the function's name of a pattern to be applied. For example, to apply a checkered pattern, the t_pttr_at is "checkered_at", which is the function that computes a checkered pattern on a given shape. To apply a striped pattern, use stripe_at instead.
 
typedef t_checker(* t_uv_map) (t_point point)
 
typedef struct s_uv_image t_uv_image
 The struct of type t_uv_image represents an image used for texturing another image. More...
 
typedef struct s_text_map t_text_map
 This structure creates a t_pattern subclass (the same as t_pttr_at, which calls stripe_at() or checkered_at()). t_text_map is a subclass that uses spherical_map(), planar_map() or cylindrical_map() to define how to apply a pattern on a given 2D or 3D shape's surface. More...
 

Functions

t_pattern new_pattern (t_color a, t_color b)
 This function creates a new default pattern with the following properties: it has a stripe pattern and it receives the color passed as parameter to the function. More...
 
t_color stripe_at (t_pattern pattern, t_point world_point)
 This function applies a stripe pattern on shape's surface located at a given world point. It checks which pattern color should or not be applied at a specific point of the world. More...
 
t_color checkered_at (t_pattern pattern, t_point world_point)
 This function applies a checkered pattern on shape's surface located at a given world point. It checks which pattern color should or not be applied at a specific point of the world. More...
 
t_color bumped_at (t_pattern pattern, t_point point)
 Calculates the color of a bumped pattern applied to a shape's surface at a given point. More...
 
void set_pattern_transform (t_pattern *pattern, t_matrix transform)
 This function assigns a transformation matrix to a pattern, which is used to manipulate the way the pattern is rendered. More...
 
t_checker uv_checkers (double width, double height, t_color a, t_color b)
 This function creates a checker structure to be used by pattern functions. More...
 
t_color uv_pattern_at (t_checker checkers, double u, double v)
 This function gets the pattern's color and at the given width (v) and height (v) coordinates stored at the structure t_checker. More...
 
void texture_map (t_pattern *pattern, t_checker checkers, t_uv_map uv_map)
 This function saves t_checker struct to t_pattern struct. It sends information to t_pattern about how to apply a given pattern (uv_map) and what is the pattern to be applied (checkers). More...
 
t_checker spherical_map (t_point point)
 This function renders a 3D point of a sphere on its surface to a 2D point (u, v) on the flattered surface. More...
 
t_checker cylindrical_map (t_point point)
 This function renders a 3D point of a cylinder on its surface to a 2D point (u, v) on the flattered surface. More...
 
t_checker planar_map (t_point point)
 This function renders a 3D point of a plane on its surface to a 2D point (u, v) on the flattered surface. More...
 

Typedef Documentation

◆ t_checker

typedef struct s_checker t_checker

This structure encapsulates the function uv_checkers().

Parameters
widthDescribes how many squares the pattern creates in u, that is, in the vertical axis.
heightDescribes how many squares the pattern creates in v, that is, in the horizontal axis.
color_aDescribes the first color of the square to be applied.
color_aDescribes the second color of the square to be applied.

◆ t_pattern

typedef struct s_pattern t_pattern

The type t_pattern contatins all the necessary information to apply a texture on a given shape's surface.

Parameters
has_patternStores TRUE if shape has a pattern or FALSE, if not.
pattern_atReceives a pattern function to apply the corresponding pattern. For more information, see t_pttr_at description.
texture_mapThis structure creates a t_pattern subclass (the same as t_pttr_at, which calls stripe_at() or checkered_at()). t_text_map is a subclass that uses spherical_map(), planar_map() or cylindrical_map() to define how to apply a pattern on a given 2D or 3D shape's surface.
widthReceives u, the horizontal value of checkers squares.
heightReceives v, the vertical value of checkers squares.
aReceives the first color of a given pattern to be applied.
bReceives the second color of a given pattern to be applied.
transformStores matrix transformation so that pattern be manipulated.

◆ t_text_map

typedef struct s_text_map t_text_map

This structure creates a t_pattern subclass (the same as t_pttr_at, which calls stripe_at() or checkered_at()). t_text_map is a subclass that uses spherical_map(), planar_map() or cylindrical_map() to define how to apply a pattern on a given 2D or 3D shape's surface.

Parameters
uv_patternContains information about the pattern to applied on a given shape's surface.
uv_mapContains the corresponding shape's function that will correctly apply the texture on its surface. For example, if the shape is a plane, this field must be planar_map. If it's a cylinder, it must be cylindrical_map and if it's a sphere, it must be spherical_map.

◆ t_uv_image

typedef struct s_uv_image t_uv_image

The struct of type t_uv_image represents an image used for texturing another image.

The t_uv_image structure contains the necessary fields for storing image data and relevant information used for texturing operations. It is used to define an image that can be applied as a texture on another image or rendered onto a canvas.

Parameters
mlx_ptrA pointer to a connection with the Xserver.
win_ptrA pointer to a window created with MLX (MinilibX).
img_ptrA pointer to an image created with MLX (MinilibX).
addrA pointer to the image data, indicating how to write data on pixels of the image.
bppThe bits per pixel value of the image.
line_lenThe line length value of the image.
endianThe endianness order of the image.
widthThe width of the image in pixels.
heightThe height of the image in pixels.

Function Documentation

◆ bumped_at()

t_color bumped_at ( t_pattern  pattern,
t_point  point 
)

Calculates the color of a bumped pattern applied to a shape's surface at a given point.

A bumped pattern is a pattern that adds a sense of depth or texture to a surface. This function applies a bumped pattern on the surface of a shape at the specified point. It determines the color of the pattern at that point based on the pattern and the position of the point.

Parameters
patternA structure of type t_pattern that stores the bumped pattern to be applied.
pointA structure of type t_point representing the point on the shape's surface.
Returns
The color of the pattern at the given point.

◆ checkered_at()

t_color checkered_at ( t_pattern  pattern,
t_point  world_point 
)

This function applies a checkered pattern on shape's surface located at a given world point. It checks which pattern color should or not be applied at a specific point of the world.

Parameters
patternStores the pattern to be applied.
world_pointContains the world's point to be evaluated.
Returns
The function returns the first pattern color a if condition is met. Otherwise, it returns the second pattern b.

◆ cylindrical_map()

t_checker cylindrical_map ( t_point  point)

This function renders a 3D point of a cylinder on its surface to a 2D point (u, v) on the flattered surface.

Parameters
pointSpecifies the point to be converted.
Returns
Returns the (u, v) pair corresponding to the given 3D point p.

◆ new_pattern()

t_pattern new_pattern ( t_color  a,
t_color  b 
)

This function creates a new default pattern with the following properties: it has a stripe pattern and it receives the color passed as parameter to the function.

Parameters
aReceives the first color of a given pattern to be applied.
bReceives the second color of a given pattern to be applied.
Returns
This function successfully returns a new pattern structure.

◆ planar_map()

t_checker planar_map ( t_point  point)

This function renders a 3D point of a plane on its surface to a 2D point (u, v) on the flattered surface.

Parameters
pointSpecifies the point to be converted.
Returns
Returns the (u, v) pair corresponding to the given 3D point p.

◆ set_pattern_transform()

void set_pattern_transform ( t_pattern pattern,
t_matrix  transform 
)

This function assigns a transformation matrix to a pattern, which is used to manipulate the way the pattern is rendered.

Parameters
patternReceives the pattern structure to alter transform's field.
transformReceives the matrix transformation to be assigned.

◆ spherical_map()

t_checker spherical_map ( t_point  point)

This function renders a 3D point of a sphere on its surface to a 2D point (u, v) on the flattered surface.

Parameters
pointSpecifies the point to be converted.
Returns
Returns the (u, v) pair corresponding to the given 3D point p.

◆ stripe_at()

t_color stripe_at ( t_pattern  pattern,
t_point  world_point 
)

This function applies a stripe pattern on shape's surface located at a given world point. It checks which pattern color should or not be applied at a specific point of the world.

Parameters
patternStores the pattern to be applied.
world_pointContains the world's point to be evaluated.
Returns
The function returns the first pattern color a if condition is met. Otherwise, it returns the second pattern b.

◆ texture_map()

void texture_map ( t_pattern pattern,
t_checker  checkers,
t_uv_map  uv_map 
)

This function saves t_checker struct to t_pattern struct. It sends information to t_pattern about how to apply a given pattern (uv_map) and what is the pattern to be applied (checkers).

Parameters
patternStores the pattern to be applied.
checkersContains the how many squares in x and y axes there are and which colors are to be applied on a surface.
uv_mapContains the corresponding shape's function that will correctly apply the texture on its surface. For example, if the shape is a plane, this field must be planar_map. If it's a cylinder, it must be cylindrical_map and if it's a sphere, it must be spherical_map.

◆ uv_checkers()

t_checker uv_checkers ( double  width,
double  height,
t_color  a,
t_color  b 
)

This function creates a checker structure to be used by pattern functions.

Parameters
widthDescribes how many squares the pattern creates in u, that is, in the vertical axis.
heightDescribes how many squares the pattern creates in v, that is, in the horizontal axis.
aDescribes the first color of the square to be applied.
bDescribes the second color of the square to be applied.
Returns
Returns a data structure of type t_cheker that encapsulates the function's parameters.

◆ uv_pattern_at()

t_color uv_pattern_at ( t_checker  checkers,
double  u,
double  v 
)

This function gets the pattern's color and at the given width (v) and height (v) coordinates stored at the structure t_checker.

Parameters
checkersContains the how many squares in x and y axes there are and which colors are to be applied on a surface.
uThis parameter specifies the x location.
vThis parameter specifies the y location.
Returns
Returns the pattern's color at the given u and v coordinates, where both u and v are floating point numbers between 0 and 1, inclusive.