-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
88 lines (68 loc) · 1.46 KB
/
utils.c
File metadata and controls
88 lines (68 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "fdf.h"
t_rgb ui_to_rgb(unsigned int i)
{
t_rgb rgb;
rgb.blue = i & 255;
rgb.green = (i >> 8) & 255;
rgb.red = (i >> 16) & 255;
return (rgb);
}
t_vector3f v3f_scale(t_vector3f v, double scaler)
{
t_vector3f result;
result.x = v.x * scaler;
result.y = v.y * scaler;
result.z = v.z * scaler;
return (result);
}
t_vector2 new_vec2(int x, int y)
{
t_vector2 v;
v.x = x;
v.y = y;
return (v);
}
t_vector3f new_vec3f(double x, double y, double z)
{
t_vector3f v;
v.x = x;
v.y = y;
v.z = z;
return (v);
}
t_vector2 new_vec3f_projection(t_vector3f a)
{
t_vector2 b;
b.x = (int)a.x;
b.y = (int)a.y;
return (b);
}
t_rgb new_rgb(int red, int green, int blue)
{
t_rgb col;
red = CLAMP(red, 25, 250);
blue = CLAMP(blue, 25, 250);
green = CLAMP(green, 25, 250);
col.red = red;
col.blue = blue;
col.green = green;
return (col);
}
t_rgb mix_rgb(t_rgb r1, t_rgb r2)
{
t_rgb rgb;
rgb.red = (r1.red + r2.red) / 2;
rgb.blue = (r1.blue + r2.blue) / 2;
rgb.green = (r1.green + r2.green) / 2;
return (rgb);
}
void put_pixel_to_img(t_collection *C, t_vector2 p, t_rgb rgb)
{
if (p.x < LIMIT_PIXEL_WIN_EDGE || p.x > WIDTH - LIMIT_PIXEL_WIN_EDGE - 1
|| p.y < LIMIT_PIXEL_WIN_EDGE || p.y > HEIGHT - LIMIT_PIXEL_WIN_EDGE - 1)
return ;
C->mlx.img_string[(p.x * 4) + (p.y * 4 * WIDTH)] = rgb.blue;
C->mlx.img_string[(p.x * 4) + (p.y * 4 * WIDTH) + 1] = rgb.green;
C->mlx.img_string[(p.x * 4) + (p.y * 4 * WIDTH) + 2] = rgb.red;
//NO NEED FOR ALPHA
}