fdf/inc/fdf.h

116 lines
3.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: o_ :::::: ::: */
/* fdf.h :+: / :+::+: :+: */
/* +:+ > +:++:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
/* +#+ +#+#+ +#++#+ +#+ \o/ */
/* Created: 2024/12/06 11:07:39 by whaffman #+#+# #+#+# #+# #+# | */
/* Updated: 2024/12/06 11:11:56 by whaffman ### ### ### ### / \ */
/* */
/* ************************************************************************** */
#ifndef FDF_H
# define FDF_H
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
# include <stdbool.h>
# include <math.h>
# include <stdio.h>
# include <errno.h>
# include "libft.h"
# include "MLX42.h"
# define SUCCESS 1
# define FAILURE 0
# define WRONG_LINE_LENGTH "Error: wrong line length. \
Expected %d, got %d in line nr %d\n"
# define MALLOC_ERROR "Error: malloc failed\n"
# define FILE_ERROR "Error: could not open file %s\n"
# define USAGE_ERROR "Usage: %s <filename>\n"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
# define SQRT2 1.41421356237309514547
# define SQRT6 2.44948974278317788134
# define WIDTH 2000
# define HEIGHT 1500
typedef struct s_point_3d
{
double x;
double y;
double z;
int color;
} t_point_3d;
typedef struct s_point_2d
{
int x;
int y;
int color;
} t_point_2d;
typedef struct s_map
{
t_point_3d *original;
t_point_3d *rotated;
t_point_2d *projected;
int width;
int height;
int z_max;
} t_map;
typedef struct s_fdf
{
t_map *map;
mlx_t *mlx;
mlx_image_t *img;
double angle_x;
double angle_y;
double angle_z;
double animate_z;
double zoom;
int offset_x;
int offset_y;
int last_width;
int last_height;
double z_scale;
} t_fdf;
int interpolate_color(t_point_2d start, t_point_2d end, t_point_2d current);
int get_color(char *str);
int get_map_sizes(char *filename, t_map *map);
void free_line_and_split(char **line, char ***split);
int read_map(char *filename, t_fdf *fdf);
int parse_map(char *filename, t_fdf *fdf);
void print_map(t_map *map);
void copy_map(t_fdf *fdf);
void fdf_apply_rotation(t_fdf *fdf);
void handle_error(t_fdf *fdf, char *error);
void rotate_x(t_point_3d **points, double angle, int size);
void rotate_y(t_point_3d **points, double angle, int size);
void rotate_z(t_point_3d **points, double angle, int size);
bool fdf_put_pixel(mlx_image_t *img, t_point_2d point);
void fdf_draw_line(mlx_image_t *img, t_point_2d start,
t_point_2d end);
int fdf_hooks(t_fdf *fdf);
void resize_hook(int width, int height, void *param);
void draw_hook(void *param);
void key_hook(mlx_key_data_t keydata, void *param);
void fdf_set_background(mlx_image_t *img, int color);
void fdf_project_isometric(t_fdf *fdf);
double deg2rad(double deg);
#endif