// C/C++ File
// AUTHOR:   fotonmootn
// FILE:     inc/fdf.h
// ROLE:     to rule them all
// CREATED:  2017-02-13 20:07:04
// MODIFIED: 2017-02-18 01:11:28


#ifndef FDF_H
# define FDF_H

#include "libft.h"
#include "mlx.h"
#include <math.h>
#include <fcntl.h>
#include <stdio.h>

# define HEIGHT	700
# define WIDTH	700
# define BPP	32
# define ENDIAN	1
# define COLOR1 2604805
# define COLOR2 12518661

typedef struct 	s_color
{
	int 		red;
	int 		green;
	int 		blue;
}				t_color;

typedef struct	s_vec
{
	float		x;
	float		y;
	float		z;
}				t_vec;

typedef struct	s_pnt
{
	int 		x;
	int 		y;
	float 		z;
	t_color		color;
}				t_pnt;

typedef struct 	s_line
{
	t_pnt		p1;
	t_pnt		p2;
}				t_line;

typedef struct	s_mw
{
	void		*mlx;
	void		*win;
}				t_mw;

typedef struct	s_map
{
	t_list		*lst_map;
	t_pnt		**arr_pnt;
	int 		x_max;
	int 		y_max;
	int 		z_max;
}				t_map;

typedef struct	s_mat4
{
	double 		mx[4][4];
}				t_mat4;

typedef struct	s_trnsf
{
	t_mat4		*tr;
	t_mat4		*xr;
	t_mat4		*yr;
	t_mat4		*zr;
	t_mat4		*fin;
}				t_trnsf;

typedef struct 	s_FDF
{
	t_map		*map;
	t_mw		*mw;
	int 		w_height;
	int 		w_width;
	int 		bpp;
	int 		line_size;
	void 		*image;
	char 		*image_data;
	int 		endian;
}				t_FDF;

typedef struct	s_swap
{
	int 		swap_x;
	int 		swap_z;
	int 		swap_coord;
}				t_swap;


void			line(t_pnt p1, t_pnt p2, t_FDF *FDF);

t_map			*map_init(char *path);
void			pnt_init(t_map *map);

t_mat4			*mat4_init(void);
t_mat4			*mat4_mult(t_mat4 *m1, t_mat4 *m2);
void			mat4_translate(t_mat4 *m, double x, double y, double z);
void			mat4_scale(t_mat4 *m, double x, double y, double z);
void			mat4_z_rot(t_mat4 *m, double angle);
void			mat4_x_rot(t_mat4 *m, double angle);
void			mat4_y_rot(t_mat4 *m, double angle);
void			vec_mat_mult(t_mat4 *m, t_vec *v, t_pnt *result);

void			map_transform(t_map *map);
void			transform(t_mat4 *mat, t_map *map);

void			render(t_FDF *FDF);

void			free_tab(char **tab);
void			quit(t_FDF *FDF);
void			swap_init(t_swap *s);

t_color			color_init(int red, int green, int blue);
t_color			color_lerp(t_color c1, t_color c2, float step);
t_color			int_to_color(int c);
int				color_to_int(t_color c);
t_color			choose_color(t_line *line, t_swap *s, t_FDF *FDF);

t_mw			*mlx_and_win_ptr_init(int x, int y);
t_FDF			*FDF_init(char *path);

int     		key_hook(int keycode, void *m);

void			put_pixel_to_image(t_line *line, t_swap *s, t_FDF *FDF);

#endif
