-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
104 lines (96 loc) · 2.54 KB
/
main.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mle-roy <mle-roy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/03 19:09:44 by mle-roy #+# #+# */
/* Updated: 2014/03/04 19:45:26 by mle-roy ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <mlx.h>
#include "rt.h"
#include "libft.h"
void get_pixel_color(t_env *e, int x, int y)
{
t_obj *obj;
obj = e->obj;
while (obj)
{
e->calc->dir->x = e->focal - e->cam->x;
e->calc->dir->y = (-(e->width / 2) + x);
e->calc->dir->z = ((e->height / 2) - y);
/* if (check_inter_plan(e) == 1)
calculate_color_plan(e, obj);
if (check_inter_sphere(e, obj) == 1)
calculate_color_sphere(e, obj);
if (check_inter_cylindre(e, obj) == 1)
calculate_color_cylindre(e, obj);
if (e->calc->delta == e->focal)
e->obj->color = e->color;*/
/*
** This uses to trace axes
*/
if (x == e->width / 2 || y == e->height / 2)
e->color = 0x00FF00;
obj = obj->next;
}
}
int expose_hook(t_env *e)
{
int x;
int y;
x = 0;
y = 0;
while (y < e->height)
{
while (x < e->width)
{
e->calc->delta = e->focal;
get_pixel_color(e, x, y);
mlx_pixel_put(e->mlx, e->win, x, y, e->color);
x += 1;
}
x = 0;
y +=1;
}
return (0);
}
int key_hook(int keycode, t_env *e)
{
if (keycode == 65307)
exit(0);
if (e)
return (0);
return (0);
}
int main(int argc, char **argv)
{
t_env *e;
t_lx *lex;
if (argc != 2)
{
write(1, "./rt scene.sc\n", 14);
return (0);
}
lex = get_lex(argv[1]);
print_lex(lex); //nonon
e = init_env(lex);
printf("\n\n"); //nononon
print_env(e); //nononon
printf("coucou1\n");
e->mlx = mlx_init();
printf("coucou2\n");
e->win = mlx_new_window(e->mlx, e->width, e->height, "RT");
printf("coucou3\n");
mlx_key_hook(e->win, key_hook, e);
printf("coucou4\n");
// mlx_expose_hook(e->win, expose_hook, e);
printf("coucou5\n");
mlx_loop(e->mlx);
return (0);
}