-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.c
55 lines (48 loc) · 1.76 KB
/
color.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajaehaer <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/30 13:14:12 by ajaehaer #+# #+# */
/* Updated: 2019/03/20 15:52:59 by ajaehaer ### ########.fr */
/* */
/* ************************************************************************** */
#include "engine_render.h"
int vec2color(t_vector vector)
{
int res;
vector.x = vector.x > 1. ? 1. : vector.x;
vector.y = vector.y > 1. ? 1. : vector.y;
vector.z = vector.z > 1. ? 1. : vector.z;
if (vector.x < 0.)
vector.x = 0.;
if (vector.y < 0.)
vector.y = 0.;
if (vector.z < 0.)
vector.z = 0.;
res = (((int)(vector.x * 255.)) << 16) |
(((int)(vector.y * 255.)) << 8) |
((int)(vector.z * 255.));
return (res);
}
t_vector color2vec(int color)
{
t_vector res;
res.x = (double)((color >> 16) & 0xff);
res.y = (double)((color >> 8) & 0xff);
res.z = (double)(color & 0xff);
res = vector_scalar_mul(res, 1. / 255.);
return (res);
}
t_vector primitive_color(t_primitive *primitive, t_uv uv, double lighting)
{
int color;
if (lighting > 0.)
{
color = get_color_uv(primitive->texture, uv);
return (vector_scalar_mul(color2vec(color), lighting));
}
return (color2vec(0x0));
}