/ fdf / fdf / includes / fdf.h
fdf.h
  1  /* ************************************************************************** */
  2  /*                                                                            */
  3  /*                                                        :::      ::::::::   */
  4  /*   fdf.h                                              :+:      :+:    :+:   */
  5  /*                                                    +:+ +:+         +:+     */
  6  /*   By: gychoi <gychoi@student.42seoul.kr>         +#+  +:+       +#+        */
  7  /*                                                +#+#+#+#+#+   +#+           */
  8  /*   Created: 2022/12/10 22:32:08 by gychoi            #+#    #+#             */
  9  /*   Updated: 2023/01/05 18:29:56 by gychoi           ###   ########.fr       */
 10  /*                                                                            */
 11  /* ************************************************************************** */
 12  
 13  #ifndef FDF_H
 14  # define FDF_H
 15  
 16  # include "mlx.h"
 17  # include "libft.h"
 18  
 19  # include <fcntl.h>
 20  # include <math.h>
 21  # include <stdlib.h>
 22  # include <stdio.h>
 23  # include <unistd.h>
 24  
 25  # define SCREEN_WIDTH	1280
 26  # define SCREEN_HEIGHT	960
 27  
 28  # define KEY_ESC		53
 29  # define KEY_ISO		34
 30  # define KEY_OTH		31
 31  # define KEY_RST		15
 32  # define KEY_W			13
 33  # define KEY_S			1
 34  # define KEY_A			0
 35  # define KEY_D			2
 36  # define KEY_Q			12
 37  # define KEY_E			14
 38  # define KEY_UP			126
 39  # define KEY_DOWN		125
 40  # define KEY_LEFT		123
 41  # define KEY_RIGHT		124
 42  # define KEY_ZOOM_IN	24
 43  # define KEY_ZOOM_OUT	27
 44  # define KEY_Z_UP		30
 45  # define KEY_Z_DOWN		33
 46  # define KEY_BEND_UP		47
 47  # define KEY_BEND_DOWN		43
 48  
 49  typedef struct s_delta
 50  {
 51  	int	dx;
 52  	int	dy;
 53  }	t_delta;
 54  
 55  typedef struct s_map
 56  {
 57  	int		width;
 58  	int		height;
 59  	int		x_origin;
 60  	int		y_origin;
 61  	int		z_max;
 62  	int		z_min;
 63  	double	x_margin;
 64  	double	y_margin;
 65  	double	z_margin;
 66  }	t_map;
 67  
 68  typedef struct s_coord
 69  {
 70  	double	x;
 71  	double	y;
 72  	double	z;
 73  }	t_coord;
 74  
 75  typedef struct s_point
 76  {
 77  	double	x;
 78  	double	y;
 79  	double	z;
 80  	int		color;
 81  }	t_point;
 82  
 83  typedef struct s_angle
 84  {
 85  	double	alpha;
 86  	double	beta;
 87  	double	gamma;
 88  }	t_angle;
 89  
 90  typedef struct s_offset
 91  {
 92  	int		x;
 93  	int		y;
 94  	double	z;
 95  	double	zoom;
 96  	double	bend;
 97  }	t_offset;
 98  
 99  typedef struct s_fdf
100  {
101  	void			*mlx;
102  	void			*win;
103  	void			*img;
104  	char			*addr;
105  	int				bpp;
106  	int				line_len;
107  	int				endian;
108  	struct s_map	map;
109  	struct s_coord	**coords;
110  	struct s_angle	angle;
111  	struct s_offset	offset;
112  }	t_fdf;
113  
114  t_fdf	*init_fdf(void);
115  void	init_draw(t_fdf *fdf);
116  t_coord	init_coord(int x, int y, int z);
117  
118  void	read_file(t_fdf *fdf, char *path);
119  void	set_coord_margin(t_fdf *fdf);
120  t_point	**set_points(t_fdf *fdf);
121  
122  void	rotate_x(t_point *point, double theta);
123  void	rotate_y(t_point *point, double theta);
124  void	rotate_z(t_point *point, double theta);
125  void	isometric(t_fdf *fdf);
126  void	orthographic(t_fdf *fdf);
127  void	reset_translation(t_fdf *fdf);
128  
129  void	draw_frame(t_fdf *fdf);
130  
131  int		key_hook(int keycode, t_fdf *fdf);
132  int		close_hook(t_fdf *fdf);
133  
134  void	fdf_error(char *str);
135  int		fdf_abs(int n);
136  int		fdf_open(char *path, int flag);
137  void	fdf_close(int fd);
138  void	*fdf_malloc(size_t size);
139  double	get_ratio(int s, int f, int cur);
140  
141  #endif