149 lines
4.0 KiB
C
149 lines
4.0 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 <errno.h>
|
|
# include "libft.h"
|
|
# include "MLX42.h"
|
|
# include <stdio.h>
|
|
|
|
# define SUCCESS 1
|
|
# define FAILURE 0
|
|
|
|
# define WRONG_LINE_LENGTH "Error: wrong line length.\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 500
|
|
# define HEIGHT 500
|
|
|
|
typedef enum e_colormode
|
|
{
|
|
COLOR_MODE_DEFAULT,
|
|
COLOR_MODE_Z,
|
|
COLOR_MODE_GRADIENT
|
|
} t_colormode;
|
|
|
|
typedef enum e_projection
|
|
{
|
|
PROJECTION_ISOMETRIC,
|
|
PROJECTION_PARALLEL,
|
|
PROJECTION_TRIMETRIC
|
|
} t_projection;
|
|
|
|
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 orig_z;
|
|
int color;
|
|
} t_point_2d;
|
|
|
|
|
|
typedef struct s_map
|
|
{
|
|
t_point_3d *orig;
|
|
t_point_3d *rot;
|
|
t_point_2d *proj;
|
|
int width;
|
|
int height;
|
|
int z_max;
|
|
} t_map;
|
|
|
|
typedef struct s_fdf
|
|
{
|
|
t_map *map;
|
|
mlx_t *mlx;
|
|
mlx_image_t *img;
|
|
mlx_image_t *menu;
|
|
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_colormode colormode;
|
|
t_projection projection;
|
|
} t_fdf;
|
|
|
|
void free_line_and_split(char **line, char ***split);
|
|
int get_map_sizes(char *filename, t_map *map);
|
|
int load_map_from_file(char *filename, t_fdf *fdf);
|
|
int parse_map(char *filename, t_fdf *fdf);
|
|
void set_map_point(t_fdf *fdf, int x, int y, char **str);
|
|
int parse_color_string(char *str);
|
|
void get_z_max(t_fdf *fdf);
|
|
void handle_error(t_fdf *fdf, char *error);
|
|
|
|
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);
|
|
|
|
mlx_image_t *draw_menu(t_fdf *fdf);
|
|
void apply_rotation(t_fdf *fdf);
|
|
int get_z_color(double z, int z_max);
|
|
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);
|
|
void project_isometric(t_fdf *fdf);
|
|
int interpolate_color(t_point_2d start,
|
|
t_point_2d end, t_point_2d current);
|
|
void draw_line(t_fdf *fdf, t_point_2d start,
|
|
t_point_2d end);
|
|
bool put_pixel(t_fdf *fdf, t_point_2d point);
|
|
void fdf_set_background(mlx_image_t *img, int color);
|
|
double deg2rad(double deg);
|
|
t_fdf *initialise_fdf(void);
|
|
bool clean_fdf(t_fdf *fdf);
|
|
int init_mlx(t_fdf *fdf);
|
|
void close_hook(void *param);
|
|
int get_gradient_color(double z, int z_max);
|
|
void project_parallel(t_fdf *fdf);
|
|
void project_trimetric(t_fdf *fdf);
|
|
|
|
void project(t_fdf *fdf);
|
|
int check_filename(char *filename);
|
|
void get_pixel_color(t_fdf *fdf, t_point_2d *point);
|
|
void reset_fdf(t_fdf *fdf);
|
|
void prepare_draw(t_fdf *fdf);
|
|
void key_hook_options(mlx_key_data_t keydata, t_fdf *fdf);
|
|
void key_hook_transform(mlx_key_data_t keydata, t_fdf *fdf);
|
|
|
|
#endif
|