miniRT
By Marcelo Magalhães and Ygor G. Sena, 2023.
All Data Structures Files Functions Typedefs Pages
patterns.h
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* patterns.h :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2023/05/17 15:21:56 by yde-goes #+# #+# */
9 /* Updated: 2023/06/16 13:40:14 by yde-goes ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
14 #ifndef PATTERNS_H
15 # define PATTERNS_H
16 
17 # include "matrices.h"
18 
19 typedef struct s_pattern t_pattern;
20 typedef struct s_checker t_checker;
21 
29 typedef t_color (*t_pttr_at)(t_pattern pattern,
30  t_point world_point);
31 typedef t_checker (*t_uv_map)(t_point point);
32 
43 typedef struct s_checker
44 {
45  double width;
46  double height;
47  t_color color_a;
48  t_color color_b;
49 } t_checker;
50 
71 typedef struct s_uv_image
72 {
73  void *mlx_ptr;
74  void *win_ptr;
75  void *img_ptr;
76  char *addr;
77  int bpp;
78  int line_len;
79  int endian;
80  int width;
81  int height;
83 
98 typedef struct s_text_map
99 {
100  t_checker uv_pattern;
101  t_uv_map uv_map;
102  t_uv_image *canvas;
104 
122 typedef struct s_pattern
123 {
124  t_bool has_pattern;
125  t_pttr_at pattern_at;
126  t_text_map texture_map;
127  t_color a;
128  t_color b;
129  t_matrix transform;
130  t_matrix inverse;
131  t_matrix transpose;
132 } t_pattern;
133 
134 /* ************************************************************************** */
135 /* PATTERNS.C */
136 /* ************************************************************************** */
137 
148 
159 t_color stripe_at(t_pattern pattern, t_point world_point);
160 
171 t_color checkered_at(t_pattern pattern, t_point world_point);
172 
190 
199 
200 /* ************************************************************************** */
201 /* CHECKERS.C */
202 /* ************************************************************************** */
203 
217 t_checker uv_checkers(double width, double height, t_color a, t_color b);
218 
230 t_color uv_pattern_at(t_checker checkers, double u, double v);
231 
232 /* ************************************************************************** */
233 /* MAPPINGS.C */
234 /* ************************************************************************** */
235 
250 void texture_map(t_pattern *pattern,
251  t_checker checkers, t_uv_map uv_map);
252 
261 
270 
279 
280 #endif
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 an...
Definition: patterns.c:16
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.
Definition: checkers.c:15
struct s_pattern t_pattern
The type t_pattern contatins all the necessary information to apply a texture on a given shape's surf...
Definition: patterns.h:19
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....
Definition: patterns.c:39
struct s_uv_image t_uv_image
The struct of type t_uv_image represents an image used for texturing another image.
struct s_checker t_checker
This structure encapsulates the function uv_checkers().
Definition: patterns.h:20
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 checke...
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 sur...
Definition: mappings.c:21
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....
Definition: patterns.c:32
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....
Definition: patterns.h:29
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 surf...
Definition: mappings.c:42
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 s...
Definition: mappings.c:57
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...
Definition: mappings.c:15
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 p...
Definition: patterns.c:62
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 a...
Definition: checkers.c:25
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.
Definition: bumpmap.c:19
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 r...
Definition: rays.c:27
This structure encapsulates the function uv_checkers().
Definition: patterns.h:44
The struct s_color stores the color values of ray tracing. It contains a field for red,...
Definition: tuples.h:63
The struct t_matrix stores a matrix up to 4x4 and size of 16. A matrix is a grid of numbers that can ...
Definition: matrices.h:34
The type t_pattern contatins all the necessary information to apply a texture on a given shape's surf...
Definition: patterns.h:123
This structure creates a t_pattern subclass (the same as t_pttr_at, which calls stripe_at() or checke...
Definition: patterns.h:99
Tuple means a list of ordered things. The struct t_tuple stores coordinates for a left-handed coordin...
Definition: tuples.h:33
The struct of type t_uv_image represents an image used for texturing another image.
Definition: patterns.h:72
struct s_color t_color
The struct s_color stores the color values of ray tracing. It contains a field for red,...
t_tuple point(double x, double y, double z)
This function is a simplification of the function tuple(). It will create a point with the given coor...
Definition: models.c:20