julia fractal and some hooks
This commit is contained in:
parent
231e813653
commit
50b9a36fae
25 changed files with 248 additions and 1250 deletions
|
@ -1,33 +1,24 @@
|
|||
cmake_minimum_required(VERSION 3.6)
|
||||
project(fractol)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra -O3")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra")
|
||||
|
||||
include_directories(inc libft/includes minilibx) # headers
|
||||
link_directories(libft minilibx) # libraries
|
||||
|
||||
set(SOURCE_FILES
|
||||
src/main.c
|
||||
src/line.c
|
||||
src/map_init.c
|
||||
src/pnt_init.c
|
||||
src/help_func.c
|
||||
src/render.c
|
||||
src/mat4.c
|
||||
src/color.c
|
||||
src/fractol_init.c
|
||||
src/hooks.c
|
||||
src/image_routine.c
|
||||
src/map_routine.c
|
||||
src/mat4_init_funcs.c
|
||||
src/mat4_operations.c
|
||||
src/matrix_routine.c
|
||||
src/map_movement.c
|
||||
src/parse_input.c
|
||||
src/map_check.c
|
||||
src/map_movement_1.c
|
||||
src/map_movement_2.c) # sources
|
||||
src/complex.c src/julia.c src/mandelbrot.c) # sources
|
||||
|
||||
add_executable(fractol ${SOURCE_FILES}) # compilation
|
||||
|
||||
target_link_libraries(fractol -lft -lmlx -lXext -lX11 m) # linkage
|
||||
target_link_libraries(fractol
|
||||
-lft
|
||||
-lmlx
|
||||
"-framework OpenGL"
|
||||
"-framework AppKit") # linkage
|
||||
|
|
140
inc/fractol.h
140
inc/fractol.h
|
@ -17,6 +17,7 @@
|
|||
# include "mlx.h"
|
||||
# include <math.h>
|
||||
# include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
# define HEIGHT 1200
|
||||
# define WIDTH 2500
|
||||
|
@ -29,12 +30,22 @@
|
|||
# define INIT_Y_SCALE 0.9
|
||||
# define INIT_Z_SCALE 0.1
|
||||
|
||||
typedef struct s_swap
|
||||
# define RED 16711680
|
||||
# define ORANGE 16744448
|
||||
# define YELLOW 16776960
|
||||
# define GREEN 65280
|
||||
# define BLUE 255
|
||||
# define INDIGO 4915330
|
||||
# define VIOLET 8323327
|
||||
# define BLACK 0
|
||||
|
||||
# define JUL_MAX_ITER 100
|
||||
|
||||
typedef struct s_complex
|
||||
{
|
||||
int swap_x;
|
||||
int swap_z;
|
||||
int swap_coord;
|
||||
} t_swap;
|
||||
double rl;
|
||||
double im;
|
||||
} t_complex;
|
||||
|
||||
typedef struct s_color
|
||||
{
|
||||
|
@ -43,71 +54,36 @@ typedef struct s_color
|
|||
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_mat4
|
||||
typedef struct s_move
|
||||
{
|
||||
double mx[4][4];
|
||||
} t_mat4;
|
||||
int x;
|
||||
int y;
|
||||
double z;
|
||||
} t_move;
|
||||
|
||||
typedef struct s_trnsf
|
||||
typedef struct s_julia
|
||||
{
|
||||
t_mat4 *tr;
|
||||
t_mat4 *sc;
|
||||
t_mat4 *vp;
|
||||
t_mat4 *pr;
|
||||
t_mat4 *xr;
|
||||
t_mat4 *yr;
|
||||
t_mat4 *zr;
|
||||
t_mat4 *vp_pr_tr;
|
||||
t_mat4 *fin;
|
||||
} t_trnsf;
|
||||
t_complex jul_const;
|
||||
t_color color;
|
||||
int max_iterations;
|
||||
t_move mov;
|
||||
} t_julia;
|
||||
|
||||
typedef struct s_map
|
||||
typedef struct s_fractals
|
||||
{
|
||||
t_trnsf *trnsf;
|
||||
t_vec **arr_vec;
|
||||
t_pnt **arr_pnt;
|
||||
t_color *low;
|
||||
t_color *high;
|
||||
int x_max;
|
||||
int y_max;
|
||||
int z_max;
|
||||
int z_min;
|
||||
int z_rot;
|
||||
int x_rot;
|
||||
int y_rot;
|
||||
float scale[3];
|
||||
} t_map;
|
||||
t_julia *jul;
|
||||
} t_fractals;
|
||||
|
||||
typedef struct s_fractol
|
||||
{
|
||||
t_mw *mw;
|
||||
t_fractals *fractals;
|
||||
int w_height;
|
||||
int w_width;
|
||||
int bpp;
|
||||
|
@ -117,68 +93,28 @@ typedef struct s_fractol
|
|||
int endian;
|
||||
} t_fractol;
|
||||
|
||||
void parse_input(int ac, char **av, t_fractol **fractol);
|
||||
|
||||
int wrong_symbols(char **line);
|
||||
void wrong_map(void);
|
||||
|
||||
t_map *map_init(char *path);
|
||||
|
||||
void pnt_init(t_map *map);
|
||||
t_mat4 *mat4_init(void);
|
||||
|
||||
t_trnsf *trnsf_mat_init();
|
||||
t_mat4 *viewport_mat_init(int x, int y);
|
||||
|
||||
t_mat4 *orth_mat_init(float r, float t, float f);
|
||||
void initial_trnsf_mats(t_fractol *fractol);
|
||||
void mat4_mult_chain(t_trnsf *tf);
|
||||
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);
|
||||
|
||||
t_mat4 *mat4_mult(t_mat4 *m1, t_mat4 *m2);
|
||||
|
||||
void transform(t_mat4 *mat, t_map *map);
|
||||
void recalculate_trnsf_matrs(t_map *map);
|
||||
void center(t_map *map);
|
||||
|
||||
int tab_length(char **tab);
|
||||
|
||||
void free_tab(char **tab);
|
||||
void quit(t_fractol *fractol);
|
||||
void swap_init(t_swap *s);
|
||||
void print_help(void);
|
||||
t_color color_init(int red, int green, int blue);
|
||||
t_color color_lerp(t_color c1, t_color c2, double step);
|
||||
int rainbow(int step, int max_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);
|
||||
void first_color(t_pnt *pnt, float z, t_map *map);
|
||||
t_fractol *fractol_init(void);
|
||||
|
||||
int key_hook(int keycode, void *m);
|
||||
int mouse_move_hook( int x, int y, void *fr);
|
||||
int mouse_button_hook(int btn, int x, int y, void *fr);
|
||||
|
||||
void line(t_pnt p1, t_pnt p2, t_fractol *fractol);
|
||||
void render(t_fractol *fractol);
|
||||
void put_pixel_to_image(int x, int y, t_color *col, t_fractol *fr);
|
||||
void new_and_clear_image(t_fractol *fr);
|
||||
|
||||
void left_rot(t_fractol *fractol);
|
||||
void right_rot(t_fractol *fractol);
|
||||
void forw_rot(t_fractol *fractol);
|
||||
void back_rot(t_fractol *fractol);
|
||||
void clock_rot(t_fractol *fractol);
|
||||
void aclock_rot(t_fractol *fractol);
|
||||
void scale_up_z(t_fractol *fractol);
|
||||
void scale_down_z(t_fractol *fractol);
|
||||
void zoom_in(t_fractol *fractol);
|
||||
void zoom_out(t_fractol *fractol);
|
||||
void reset(t_fractol *fractol);
|
||||
void move(t_fractol *fractol);
|
||||
void complex_equal(double real, double imag, t_complex *c);
|
||||
|
||||
void draw_julia(t_fractol *fr);
|
||||
|
||||
#endif
|
||||
|
|
80
src/color.c
80
src/color.c
|
@ -53,44 +53,48 @@ t_color int_to_color(int c)
|
|||
return (new);
|
||||
}
|
||||
|
||||
t_color choose_color(t_line *line, t_swap *s)
|
||||
int rainbow(int step, int max_step)
|
||||
{
|
||||
t_color c;
|
||||
float z1;
|
||||
float z2;
|
||||
|
||||
z1 = line->p1.z;
|
||||
z2 = line->p2.z;
|
||||
if (s->swap_z)
|
||||
{
|
||||
if (z2 == 0)
|
||||
c = int_to_color(color_to_int(line->p2.color));
|
||||
else
|
||||
c = color_lerp(line->p2.color, line->p1.color, z1 / z2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (z2 == 0)
|
||||
c = int_to_color(color_to_int(line->p1.color));
|
||||
else
|
||||
c = color_lerp(line->p1.color, line->p2.color, z1 / z2);
|
||||
}
|
||||
return (c);
|
||||
if (step >= 0 && step < max_step / 8)
|
||||
return (RED);
|
||||
if (step >= max_step / 8 && step <= max_step / 4)
|
||||
return (ORANGE);
|
||||
if (step >= max_step / 4 && step <= max_step / 8 * 3)
|
||||
return (YELLOW);
|
||||
if (step >= max_step / 8 * 3 && step <= max_step / 2)
|
||||
return (BLUE);
|
||||
if (step >= max_step / 2 && step <= max_step / 8 * 5)
|
||||
return (VIOLET);
|
||||
if (step >= max_step / 8 * 5 && step <= max_step / 8 * 6)
|
||||
return (BLACK);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void first_color(t_pnt *pnt, float z, t_map *map)
|
||||
{
|
||||
int low_color;
|
||||
int high_color;
|
||||
|
||||
low_color = (map->low == NULL) ? COLOR1 : color_to_int(*map->low);
|
||||
high_color = (map->high == NULL) ? COLOR2 : color_to_int(*map->high);
|
||||
if (z == 0)
|
||||
pnt->color = int_to_color(low_color);
|
||||
if (z == map->z_max - map->z_min)
|
||||
pnt->color = int_to_color(high_color);
|
||||
else
|
||||
pnt->color = color_lerp(
|
||||
int_to_color(low_color),
|
||||
int_to_color(high_color), fabs(z / (map->z_max - map->z_min)));
|
||||
}
|
||||
//int rainbow(int step, int max_step)
|
||||
//{
|
||||
// if (step >= 0 && step < max_step / 8)
|
||||
// return (color_to_int(
|
||||
// color_lerp(int_to_color(RED), int_to_color(ORANGE),
|
||||
// step / max_step / 8)));
|
||||
// if (step >= max_step / 8 && step <= max_step / 8 * 2)
|
||||
// return (color_to_int(
|
||||
// color_lerp(int_to_color(ORANGE), int_to_color(YELLOW),
|
||||
// step / max_step / 8 * 2)));
|
||||
// if (step >= max_step / 8 * 2 && step <= max_step / 8 * 3)
|
||||
// return (color_to_int(
|
||||
// color_lerp(int_to_color(YELLOW), int_to_color(GREEN),
|
||||
// step / max_step / 8 * 3)));
|
||||
// if (step >= max_step / 8 * 3 && step <= max_step / 8 * 4)
|
||||
// return (color_to_int(
|
||||
// color_lerp(int_to_color(GREEN), int_to_color(BLUE),
|
||||
// step / max_step / 8 * 4)));
|
||||
// if (step >= max_step / 8 * 4 && step <= max_step / 8 * 5)
|
||||
// return (color_to_int(
|
||||
// color_lerp(int_to_color(BLUE), int_to_color(VIOLET),
|
||||
// step / max_step / 8 * 5)));
|
||||
// if (step >= max_step / 8 * 5 && step <= max_step / 8 * 6)
|
||||
// return (color_to_int(
|
||||
// color_lerp(int_to_color(VIOLET), int_to_color(BLACK),
|
||||
// step / max_step / 8 * 6)));
|
||||
// return (0);
|
||||
//}
|
||||
|
|
7
src/complex.c
Normal file
7
src/complex.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "fractol.h"
|
||||
|
||||
void complex_equal(double real, double imag, t_complex *c)
|
||||
{
|
||||
c->im = imag;
|
||||
c->rl = real;
|
||||
}
|
|
@ -24,6 +24,28 @@ static t_mw *mlx_and_win_ptr_init(int x, int y)
|
|||
return (mw);
|
||||
}
|
||||
|
||||
t_julia *jul_init(void)
|
||||
{
|
||||
t_julia *j;
|
||||
|
||||
j = malloc(sizeof(t_julia));
|
||||
complex_equal(-0.7, 0.27015, &j->jul_const);
|
||||
j->max_iterations = JUL_MAX_ITER;
|
||||
j->mov.x = 0;
|
||||
j->mov.y = 0;
|
||||
j->mov.z = 1;
|
||||
return (j);
|
||||
}
|
||||
|
||||
t_fractals *frac_init(void)
|
||||
{
|
||||
t_fractals *f;
|
||||
|
||||
f = malloc(sizeof(t_fractals));
|
||||
f->jul = jul_init();
|
||||
return (f);
|
||||
}
|
||||
|
||||
t_fractol *fractol_init(void)
|
||||
{
|
||||
t_fractol *fractol;
|
||||
|
@ -32,13 +54,9 @@ t_fractol *fractol_init(void)
|
|||
{
|
||||
fractol->w_height = HEIGHT;
|
||||
fractol->w_width = WIDTH;
|
||||
fractol->fractals = frac_init();
|
||||
fractol->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT);
|
||||
fractol->image = mlx_new_image(fractol->mw->mlx, WIDTH, HEIGHT);
|
||||
fractol->image_data = mlx_get_data_addr(
|
||||
fractol->image,
|
||||
&fractol->bpp,
|
||||
&fractol->line_size,
|
||||
&fractol->endian);
|
||||
fractol->image = NULL;
|
||||
}
|
||||
return (fractol);
|
||||
}
|
||||
|
|
|
@ -26,13 +26,6 @@ void quit(t_fractol *fr)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void swap_init(t_swap *s)
|
||||
{
|
||||
s->swap_coord = 0;
|
||||
s->swap_x = 1;
|
||||
s->swap_z = 0;
|
||||
}
|
||||
|
||||
void print_help(void)
|
||||
{
|
||||
ft_putstr(
|
||||
|
|
24
src/hooks.c
24
src/hooks.c
|
@ -12,11 +12,11 @@
|
|||
|
||||
#include "fractol.h"
|
||||
|
||||
int key_hook(int keycode, void *fdf)
|
||||
int key_hook(int keycode, void *fr)
|
||||
{
|
||||
ft_putnbr(keycode);
|
||||
printf("%d\n", keycode);
|
||||
if (keycode == 53)
|
||||
quit(fdf);
|
||||
quit(fr);
|
||||
// if (keycode == 89)
|
||||
// aclock_rot(fdf);
|
||||
// if (keycode == 86)
|
||||
|
@ -41,3 +41,21 @@ int key_hook(int keycode, void *fdf)
|
|||
// reset(fdf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mouse_move_hook( int x, int y, void *fr)
|
||||
{
|
||||
fr = 0;
|
||||
printf("x = %d, y = %d\n", x, y);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mouse_button_hook(int btn, int x, int y, void *fr)
|
||||
{
|
||||
printf("x = %d, y = %d, btn = %d\n", x, y, btn);
|
||||
if (btn == 4)
|
||||
{
|
||||
((t_fractol *)fr)->fractals->jul->mov.z += 0.3;
|
||||
draw_julia((t_fractol *)fr);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,21 @@
|
|||
|
||||
#include "fractol.h"
|
||||
|
||||
void new_and_clear_image(t_fractol *fr)
|
||||
{
|
||||
if (fr)
|
||||
{
|
||||
if (fr->image)
|
||||
mlx_destroy_image(fr->mw->mlx, fr->image);
|
||||
fr->image = mlx_new_image(fr->mw->mlx, WIDTH, HEIGHT);
|
||||
fr->image_data = mlx_get_data_addr(
|
||||
fr->image,
|
||||
&fr->bpp,
|
||||
&fr->line_size,
|
||||
&fr->endian);
|
||||
}
|
||||
}
|
||||
|
||||
void put_pixel_to_image(int x, int y, t_color *col, t_fractol *fr)
|
||||
{
|
||||
if (x < 0 || y < 0 || x >= fr->w_width || y >= fr->w_height)
|
||||
|
|
44
src/julia.c
Normal file
44
src/julia.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "fractol.h"
|
||||
|
||||
static void julia_computation(int x, int y, t_julia *ju)
|
||||
{
|
||||
t_complex new;
|
||||
t_complex old;
|
||||
int i;
|
||||
|
||||
new.rl = 1.5 * (x - WIDTH / 2) / (0.5 * ju->mov.z * WIDTH) + ju->mov.x;
|
||||
new.im = (y - HEIGHT / 2) / (0.5 * ju->mov.z * HEIGHT) + ju->mov.y;
|
||||
i = 0;
|
||||
while (i < ju->max_iterations)
|
||||
{
|
||||
old = new;
|
||||
new.rl = old.rl * old.rl - old.im * old.im + ju->jul_const.rl;
|
||||
new.im = 2 * old.rl * old.im + ju->jul_const.im;
|
||||
if((new.rl * new.rl + new.im * new.im) > 4)
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
ju->color = int_to_color(rainbow(i, ju->max_iterations));
|
||||
}
|
||||
|
||||
|
||||
void draw_julia(t_fractol *fr)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
new_and_clear_image(fr);
|
||||
x = 0;
|
||||
while (x < fr->w_width)
|
||||
{
|
||||
y = 0;
|
||||
while(y < fr->w_height)
|
||||
{
|
||||
julia_computation(x, y, fr->fractals->jul);
|
||||
put_pixel_to_image(x, y, &fr->fractals->jul->color, fr);
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
|
||||
}
|
103
src/line.c
103
src/line.c
|
@ -1,103 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* line.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:59:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:59:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static void swap_z(t_pnt *p1, t_pnt *p2)
|
||||
{
|
||||
float tmp;
|
||||
t_color c;
|
||||
|
||||
tmp = p1->z;
|
||||
p1->z = p2->z;
|
||||
p2->z = tmp;
|
||||
c = p1->color;
|
||||
p1->color = p2->color;
|
||||
p2->color = c;
|
||||
}
|
||||
|
||||
static void swap_x_y(t_pnt *p1, t_pnt *p2)
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = p1->x;
|
||||
p1->x = p1->y;
|
||||
p1->y = temp;
|
||||
temp = p2->x;
|
||||
p2->x = p2->y;
|
||||
p2->y = temp;
|
||||
}
|
||||
|
||||
static void swap_points(t_pnt *p1, t_pnt *p2)
|
||||
{
|
||||
t_pnt temp;
|
||||
|
||||
temp = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = temp;
|
||||
}
|
||||
|
||||
static void draw_line(t_line *line, t_swap *s, t_fractol *fr)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
int derr;
|
||||
double dz;
|
||||
t_color col;
|
||||
|
||||
col = int_to_color(COLOR2);
|
||||
dx = abs(line->p2.x - line->p1.x);
|
||||
dy = abs(line->p2.y - line->p1.y);
|
||||
dz = fabs(line->p2.z - line->p1.z);
|
||||
derr = 2 * dy - dx;
|
||||
while (line->p1.x < line->p2.x)
|
||||
{
|
||||
put_pixel_to_image(line->p1.x, line->p1.y, &col, fr);
|
||||
if (derr > 0)
|
||||
{
|
||||
line->p1.y += s->swap_x;
|
||||
derr -= dx;
|
||||
}
|
||||
(line->p1.x)++;
|
||||
(line->p1.z) += dz / dx;
|
||||
derr += dy;
|
||||
}
|
||||
}
|
||||
|
||||
void line(t_pnt p1, t_pnt p2, t_fractol *fdf)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
t_swap swap;
|
||||
t_line line;
|
||||
|
||||
dx = abs(p2.x - p1.x);
|
||||
dy = abs(p2.y - p1.y);
|
||||
swap_init(&swap);
|
||||
if (dy > dx)
|
||||
{
|
||||
swap_x_y(&p1, &p2);
|
||||
swap.swap_coord = 1;
|
||||
}
|
||||
if (p1.x > p2.x)
|
||||
swap_points(&p1, &p2);
|
||||
if (p1.y > p2.y)
|
||||
swap.swap_x = -1;
|
||||
if (p1.z > p2.z)
|
||||
{
|
||||
swap_z(&p1, &p2);
|
||||
swap.swap_z = -1;
|
||||
}
|
||||
line.p1 = p1;
|
||||
line.p2 = p2;
|
||||
draw_line(&line, &swap, fdf);
|
||||
}
|
91
src/main.c
91
src/main.c
|
@ -13,98 +13,17 @@
|
|||
#include "fractol.h"
|
||||
#include <time.h>
|
||||
|
||||
void drawcircle(t_pnt pnt, float radius, t_fractol *fr)
|
||||
{
|
||||
int x = (int)radius;
|
||||
int y = 0;
|
||||
int err = 0;
|
||||
|
||||
while (x >= y)
|
||||
{
|
||||
put_pixel_to_image(pnt.x + x, pnt.y + y, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x + y, pnt.y + x, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x - y, pnt.y + x, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x - x, pnt.y + y, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x - x, pnt.y - y, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x - y, pnt.y - x, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x + y, pnt.y - x, &pnt.color, fr);
|
||||
put_pixel_to_image(pnt.x + x, pnt.y - y, &pnt.color, fr);
|
||||
if (err <= 0)
|
||||
{
|
||||
y += 1;
|
||||
err += 2*y + 1;
|
||||
}
|
||||
if (err > 0)
|
||||
{
|
||||
x -= 1;
|
||||
err -= 2*x + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void recursive_circles(t_pnt pnt, float radius, t_fractol *fr)
|
||||
{
|
||||
int tmp;
|
||||
drawcircle(pnt, radius, fr);
|
||||
pnt.color = color_lerp(pnt.color, color_lerp(pnt.color, color_init(0, 97, 255), 0.4), 0.3);
|
||||
if (radius > 3)
|
||||
{
|
||||
tmp = pnt.x;
|
||||
pnt.x = tmp + (int)radius / 2;
|
||||
recursive_circles(pnt, radius / 2, fr);
|
||||
pnt.x = tmp - (int)radius / 2;
|
||||
recursive_circles(pnt, radius / 2, fr);
|
||||
tmp = pnt.y;
|
||||
pnt.y = tmp + (int)radius / 2;
|
||||
recursive_circles(pnt, radius / 2, fr);
|
||||
pnt.y = tmp - (int)radius / 2;
|
||||
recursive_circles(pnt, radius / 2, fr);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(void)
|
||||
{
|
||||
t_fractol *fr;
|
||||
t_pnt pnt;
|
||||
// int i;
|
||||
|
||||
srand(time(NULL));
|
||||
fr = NULL;
|
||||
argc = 0;
|
||||
argv = 0;
|
||||
|
||||
fr = fractol_init();
|
||||
// while (pnt.y < fr->w_height)
|
||||
// {
|
||||
// pnt.x = 0;
|
||||
// pnt.color = color_lerp(int_to_color(COLOR2), int_to_color(COLOR1), (float)pnt.y / (float)fr->w_height);
|
||||
// while (pnt.x < fr->w_width)
|
||||
// {
|
||||
// drawcircle(pnt, 100, fr);
|
||||
// pnt.x += 30;
|
||||
// }
|
||||
// pnt.y += 30;
|
||||
// }
|
||||
pnt.y = fr->w_height / 2;
|
||||
pnt.x = fr->w_width / 2;
|
||||
// i = 0;
|
||||
pnt.color = color_init(255, 0, 0);
|
||||
recursive_circles(pnt, 1000, fr);
|
||||
// while (i < 10000)
|
||||
// {
|
||||
// usleep(150000);
|
||||
// recursive_circles(pnt, i, fr);
|
||||
// mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
|
||||
// mlx_destroy_image(fr->mw->mlx, fr->image);
|
||||
// fr->image = mlx_new_image(fr->mw->mlx, WIDTH, HEIGHT);
|
||||
// fr->image_data = mlx_get_data_addr(
|
||||
// fr->image,
|
||||
// &fr->bpp,
|
||||
// &fr->line_size,
|
||||
// &fr->endian);
|
||||
// i +=10;
|
||||
// }
|
||||
mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
|
||||
draw_julia(fr);
|
||||
mlx_hook(fr->mw->win, 2, 5, key_hook, fr);
|
||||
mlx_hook(fr->mw->win, 4, 0, mouse_button_hook, fr);
|
||||
mlx_hook(fr->mw->win, 6, 0, mouse_move_hook, fr);
|
||||
mlx_loop(fr->mw->mlx);
|
||||
return (0);
|
||||
}
|
||||
|
|
43
src/mandelbrot.c
Normal file
43
src/mandelbrot.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "fractol.h"
|
||||
|
||||
//static void julia_computation(int x, int y, t_julia *ju)
|
||||
//{
|
||||
// t_complex new;
|
||||
// t_complex old;
|
||||
// int i;
|
||||
//
|
||||
// new.rl = 1.5 * (x - WIDTH / 2) / (0.5 * ju->mov.z * WIDTH) + ju->mov.x;
|
||||
// new.im = (y - HEIGHT / 2) / (0.5 * ju->mov.z * HEIGHT) + ju->mov.y;
|
||||
// i = 0;
|
||||
// while (i < ju->max_iterations)
|
||||
// {
|
||||
// old = new;
|
||||
// new.rl = old.rl * old.rl - old.im * old.im + ju->jul_const.rl;
|
||||
// new.im = 2 * old.rl * old.im + ju->jul_const.im;
|
||||
// if((new.rl * new.rl + new.im * new.im) > 4)
|
||||
// break ;
|
||||
// i++;
|
||||
// }
|
||||
// ju->color = int_to_color(rainbow(i, ju->max_iterations));
|
||||
//}
|
||||
//
|
||||
//
|
||||
//void draw_julia(t_fractol *fr)
|
||||
//{
|
||||
// int x;
|
||||
// int y;
|
||||
//
|
||||
// x = 0;
|
||||
// while (x < fr->w_width)
|
||||
// {
|
||||
// y = 0;
|
||||
// while(y < fr->w_height)
|
||||
// {
|
||||
// julia_computation(x, y, fr->fractals->jul);
|
||||
// put_pixel_to_image(x, y, &fr->fractals->jul->color, fr);
|
||||
// y++;
|
||||
// }
|
||||
// x++;
|
||||
// }
|
||||
// mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
|
||||
//}
|
|
@ -1,57 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_check.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:59:27 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:59:29 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static int wrong_symbols_help(char *tmp)
|
||||
{
|
||||
if ((ft_strstr(tmp, ",0x") == tmp) && (tmp += 3))
|
||||
{
|
||||
if (!*tmp)
|
||||
return (1);
|
||||
while (ft_isdigit(*tmp) || (*tmp >= 'A' && *tmp <= 'F'))
|
||||
tmp++;
|
||||
}
|
||||
if (*tmp)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int wrong_symbols(char **line)
|
||||
{
|
||||
char *tmp;
|
||||
int num;
|
||||
int neg;
|
||||
|
||||
num = 0;
|
||||
neg = 0;
|
||||
tmp = *line;
|
||||
while ((*tmp == '-' || ft_isdigit(*tmp)) && *tmp)
|
||||
{
|
||||
if (*tmp == '-')
|
||||
neg = 1;
|
||||
else if (*tmp)
|
||||
num++;
|
||||
tmp++;
|
||||
}
|
||||
if (neg == 1 && num == 0)
|
||||
return (1);
|
||||
if (wrong_symbols_help(tmp))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void wrong_map(void)
|
||||
{
|
||||
ft_putstr("Wrong map!\n");
|
||||
quit(0);
|
||||
}
|
113
src/map_init.c
113
src/map_init.c
|
@ -1,113 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_init.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:59:36 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:59:38 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static char *to_str_map(char *path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd != -1)
|
||||
return (ft_read_file(fd));
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int map_width(char **tab)
|
||||
{
|
||||
int width;
|
||||
int width_tmp;
|
||||
char **line_tab;
|
||||
|
||||
line_tab = ft_strsplit(*tab, ' ');
|
||||
width = tab_length(line_tab);
|
||||
free(line_tab);
|
||||
width_tmp = width;
|
||||
while (*tab)
|
||||
{
|
||||
if ((line_tab = ft_strsplit(*tab, ' ')))
|
||||
{
|
||||
if (wrong_symbols(line_tab))
|
||||
wrong_map();
|
||||
if ((width = tab_length(line_tab)) != width_tmp)
|
||||
wrong_map();
|
||||
}
|
||||
free_tab(line_tab);
|
||||
tab++;
|
||||
}
|
||||
return (width);
|
||||
}
|
||||
|
||||
static void min_max_z(t_map *map, int i, int j)
|
||||
{
|
||||
if (map->arr_vec[i][j].z > map->z_max)
|
||||
map->z_max = (int)map->arr_vec[i][j].z;
|
||||
if (map->arr_vec[i][j].z < map->z_min)
|
||||
map->z_min = (int)map->arr_vec[i][j].z;
|
||||
}
|
||||
|
||||
static void to_vec_arr(char **tab, t_map *map)
|
||||
{
|
||||
char **line;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
map->y_max = tab_length(tab);
|
||||
map->x_max = map_width(tab);
|
||||
map->arr_vec = malloc(sizeof(t_vec *) * (map->y_max));
|
||||
i = 0;
|
||||
while (i < map->y_max)
|
||||
{
|
||||
j = 0;
|
||||
line = ft_strsplit(tab[i], ' ');
|
||||
map->arr_vec[i] = malloc(sizeof(t_vec) * (map->x_max));
|
||||
while (j < map->x_max)
|
||||
{
|
||||
map->arr_vec[i][j].z = ft_atoi(line[j]);
|
||||
map->arr_vec[i][j].x = j;
|
||||
map->arr_vec[i][j].y = i;
|
||||
min_max_z(map, i, j);
|
||||
j++;
|
||||
}
|
||||
free_tab(line);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
t_map *map_init(char *path)
|
||||
{
|
||||
char *str_map;
|
||||
char **tab_map;
|
||||
t_map *map;
|
||||
|
||||
map = malloc(sizeof(t_map));
|
||||
map->z_min = 0;
|
||||
map->x_max = 0;
|
||||
map->x_rot = 0;
|
||||
map->y_rot = 0;
|
||||
map->z_rot = 0;
|
||||
map->scale[0] = 1;
|
||||
map->scale[1] = 1;
|
||||
map->scale[2] = 1;
|
||||
map->low = NULL;
|
||||
map->high = NULL;
|
||||
if (!(str_map = to_str_map(path)))
|
||||
{
|
||||
ft_putstr("Wrong path to a map! For help help put \"fdf --help\"\n");
|
||||
quit(0);
|
||||
}
|
||||
tab_map = ft_strsplit(str_map, '\n');
|
||||
to_vec_arr(tab_map, map);
|
||||
free(str_map);
|
||||
free_tab(tab_map);
|
||||
return (map);
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_movement.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:58:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:58:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
//
|
||||
//void move(t_fdf *fdf)
|
||||
//{
|
||||
// recalculate_trnsf_matrs(fdf->map);
|
||||
// mat4_mult_chain(fdf->map->trnsf);
|
||||
// transform(fdf->map->trnsf->fin, fdf->map);
|
||||
// mlx_destroy_image(fdf->mw->mlx, fdf->image);
|
||||
// fdf->image = mlx_new_image(fdf->mw->mlx, WIDTH, HEIGHT);
|
||||
// fdf->image_data = mlx_get_data_addr(
|
||||
// fdf->image,
|
||||
// &fdf->bpp,
|
||||
// &fdf->line_size,
|
||||
// &fdf->endian);
|
||||
// render(fdf);
|
||||
//}
|
||||
//
|
||||
//void left_rot(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->y_rot -= 1;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void right_rot(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->y_rot += 1;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void forw_rot(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->x_rot += 1;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void back_rot(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->x_rot -= 1;
|
||||
// move(fdf);
|
||||
//}
|
|
@ -1,50 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_movement_1.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:58:19 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:58:21 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
//void scale_up_z(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->scale[2] += 1.0f / 100 * 20;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void scale_down_z(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->scale[2] -= 1.0f / 100 * 20;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void zoom_in(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->scale[0] += 1.0f / 100 * 20;
|
||||
// fdf->map->scale[1] += 1.0f / 100 * 20;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void zoom_out(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->scale[0] -= 1.0f / 100 * 20;
|
||||
// fdf->map->scale[1] -= 1.0f / 100 * 20;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void reset(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->z_rot = 0;
|
||||
// fdf->map->y_rot = 0;
|
||||
// fdf->map->x_rot = 0;
|
||||
// fdf->map->scale[0] = 1;
|
||||
// fdf->map->scale[1] = 1;
|
||||
// fdf->map->scale[2] = 1;
|
||||
// move(fdf);
|
||||
//}
|
|
@ -1,25 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_movement_2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:58:24 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:58:26 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
//
|
||||
//void clock_rot(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->z_rot -= 1;
|
||||
// move(fdf);
|
||||
//}
|
||||
//
|
||||
//void aclock_rot(t_fdf *fdf)
|
||||
//{
|
||||
// fdf->map->z_rot += 1;
|
||||
// move(fdf);
|
||||
//}
|
|
@ -1,57 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_routine.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:59:45 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:59:47 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
void transform(t_mat4 *mat, t_map *map)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (i < map->y_max)
|
||||
{
|
||||
j = 0;
|
||||
while (j < map->x_max)
|
||||
{
|
||||
vec_mat_mult(mat, &map->arr_vec[i][j], &map->arr_pnt[i][j]);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void center(t_map *map)
|
||||
{
|
||||
double d_x;
|
||||
double d_y;
|
||||
double d_z;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
d_x = map->x_max / 2.0f;
|
||||
d_y = map->y_max / 2.0f;
|
||||
d_z = map->z_max / 2.0f;
|
||||
i = 0;
|
||||
while (i < map->y_max)
|
||||
{
|
||||
j = 0;
|
||||
while (j < map->x_max)
|
||||
{
|
||||
map->arr_vec[i][j].z -= d_z;
|
||||
map->arr_vec[i][j].x -= d_x;
|
||||
map->arr_vec[i][j].y -= d_y;
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
116
src/mat4.c
116
src/mat4.c
|
@ -1,116 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mat4.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:59:57 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:59:59 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
void mat4_translate(t_mat4 *m, double x, double y, double z)
|
||||
{
|
||||
m->mx[0][0] = 1;
|
||||
m->mx[0][1] = 0;
|
||||
m->mx[0][2] = 0;
|
||||
m->mx[0][3] = 0;
|
||||
m->mx[1][0] = 0;
|
||||
m->mx[1][1] = 1;
|
||||
m->mx[1][2] = 0;
|
||||
m->mx[1][3] = 0;
|
||||
m->mx[2][0] = 0;
|
||||
m->mx[2][1] = 0;
|
||||
m->mx[2][2] = 1;
|
||||
m->mx[2][3] = 0;
|
||||
m->mx[3][0] = x;
|
||||
m->mx[3][1] = y;
|
||||
m->mx[3][2] = z;
|
||||
m->mx[3][3] = 1;
|
||||
}
|
||||
|
||||
void mat4_scale(t_mat4 *m, double x, double y, double z)
|
||||
{
|
||||
m->mx[0][0] = x;
|
||||
m->mx[0][1] = 0;
|
||||
m->mx[0][2] = 0;
|
||||
m->mx[0][3] = 0;
|
||||
m->mx[1][0] = 0;
|
||||
m->mx[1][1] = y;
|
||||
m->mx[1][2] = 0;
|
||||
m->mx[1][3] = 0;
|
||||
m->mx[2][0] = 0;
|
||||
m->mx[2][1] = 0;
|
||||
m->mx[2][2] = z;
|
||||
m->mx[2][3] = 0;
|
||||
m->mx[3][0] = 0;
|
||||
m->mx[3][1] = 0;
|
||||
m->mx[3][2] = 0;
|
||||
m->mx[3][3] = 1;
|
||||
}
|
||||
|
||||
void mat4_z_rot(t_mat4 *m, double angle)
|
||||
{
|
||||
angle = angle * M_PI / 180;
|
||||
m->mx[0][0] = cos(angle);
|
||||
m->mx[0][1] = -(sin(angle));
|
||||
m->mx[0][2] = 0;
|
||||
m->mx[0][3] = 0;
|
||||
m->mx[1][0] = sin(angle);
|
||||
m->mx[1][1] = cos(angle);
|
||||
m->mx[1][2] = 0;
|
||||
m->mx[1][3] = 0;
|
||||
m->mx[2][0] = 0;
|
||||
m->mx[2][1] = 0;
|
||||
m->mx[2][2] = 1;
|
||||
m->mx[2][3] = 0;
|
||||
m->mx[3][0] = 0;
|
||||
m->mx[3][1] = 0;
|
||||
m->mx[3][2] = 0;
|
||||
m->mx[3][3] = 1;
|
||||
}
|
||||
|
||||
void mat4_x_rot(t_mat4 *m, double angle)
|
||||
{
|
||||
angle = angle * M_PI / 180;
|
||||
m->mx[0][0] = 1;
|
||||
m->mx[0][1] = 0;
|
||||
m->mx[0][2] = 0;
|
||||
m->mx[0][3] = 0;
|
||||
m->mx[1][0] = 0;
|
||||
m->mx[1][1] = cos(angle);
|
||||
m->mx[1][2] = (sin(angle));
|
||||
m->mx[1][3] = 0;
|
||||
m->mx[2][0] = 0;
|
||||
m->mx[2][1] = -sin(angle);
|
||||
m->mx[2][2] = cos(angle);
|
||||
m->mx[2][3] = 0;
|
||||
m->mx[3][0] = 0;
|
||||
m->mx[3][1] = 0;
|
||||
m->mx[3][2] = 0;
|
||||
m->mx[3][3] = 1;
|
||||
}
|
||||
|
||||
void mat4_y_rot(t_mat4 *m, double angle)
|
||||
{
|
||||
angle = angle * M_PI / 180;
|
||||
m->mx[0][0] = cos(angle);
|
||||
m->mx[0][1] = 0;
|
||||
m->mx[0][2] = -(sin(angle));
|
||||
m->mx[0][3] = 0;
|
||||
m->mx[1][0] = 0;
|
||||
m->mx[1][1] = 1;
|
||||
m->mx[1][2] = 0;
|
||||
m->mx[1][3] = 0;
|
||||
m->mx[2][0] = sin(angle);
|
||||
m->mx[2][1] = 0;
|
||||
m->mx[2][2] = cos(angle);
|
||||
m->mx[2][3] = 0;
|
||||
m->mx[3][0] = 0;
|
||||
m->mx[3][1] = 0;
|
||||
m->mx[3][2] = 0;
|
||||
m->mx[3][3] = 1;
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mat4_init_funcs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 19:00:07 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 19:00:08 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
t_mat4 *mat4_init(void)
|
||||
{
|
||||
t_mat4 *mat;
|
||||
|
||||
if ((mat = (t_mat4 *)malloc(sizeof(t_mat4))))
|
||||
{
|
||||
mat->mx[0][0] = 1;
|
||||
mat->mx[0][1] = 0;
|
||||
mat->mx[0][2] = 0;
|
||||
mat->mx[0][3] = 0;
|
||||
mat->mx[1][0] = 0;
|
||||
mat->mx[1][1] = 1;
|
||||
mat->mx[1][2] = 0;
|
||||
mat->mx[1][3] = 0;
|
||||
mat->mx[2][0] = 0;
|
||||
mat->mx[2][1] = 0;
|
||||
mat->mx[2][2] = 1;
|
||||
mat->mx[2][3] = 0;
|
||||
mat->mx[3][0] = 0;
|
||||
mat->mx[3][1] = 0;
|
||||
mat->mx[3][2] = 0;
|
||||
mat->mx[3][3] = 1;
|
||||
}
|
||||
return (mat);
|
||||
}
|
||||
|
||||
t_trnsf *trnsf_mat_init(void)
|
||||
{
|
||||
t_trnsf *trnsf;
|
||||
|
||||
if ((trnsf = malloc(sizeof(t_trnsf))))
|
||||
{
|
||||
trnsf->tr = mat4_init();
|
||||
trnsf->sc = mat4_init();
|
||||
trnsf->vp = mat4_init();
|
||||
trnsf->pr = mat4_init();
|
||||
trnsf->xr = mat4_init();
|
||||
trnsf->yr = mat4_init();
|
||||
trnsf->zr = mat4_init();
|
||||
trnsf->vp_pr_tr = mat4_init();
|
||||
trnsf->fin = mat4_init();
|
||||
}
|
||||
return (trnsf);
|
||||
}
|
||||
|
||||
t_mat4 *viewport_mat_init(int x, int y)
|
||||
{
|
||||
t_mat4 *m;
|
||||
|
||||
if ((m = malloc(sizeof(t_mat4))))
|
||||
{
|
||||
m->mx[0][0] = (double)x / 2.0f;
|
||||
m->mx[0][1] = 0;
|
||||
m->mx[0][2] = 0;
|
||||
m->mx[0][3] = 0;
|
||||
m->mx[1][0] = 0;
|
||||
m->mx[1][1] = (double)y / 2.0f;
|
||||
m->mx[1][2] = 0;
|
||||
m->mx[1][3] = 0;
|
||||
m->mx[2][0] = 0;
|
||||
m->mx[2][1] = 0;
|
||||
m->mx[2][2] = 1;
|
||||
m->mx[2][3] = 0;
|
||||
m->mx[3][0] = ((double)x - 1) / 2.0f;
|
||||
m->mx[3][1] = ((double)y - 1) / 2.0f;
|
||||
m->mx[3][2] = 0;
|
||||
m->mx[3][3] = 1;
|
||||
}
|
||||
return (m);
|
||||
}
|
||||
|
||||
t_mat4 *orth_mat_init(float r, float t, float f)
|
||||
{
|
||||
t_mat4 *orth;
|
||||
|
||||
if ((orth = malloc(sizeof(t_mat4))))
|
||||
{
|
||||
orth->mx[0][0] = 2.0f / r;
|
||||
orth->mx[0][1] = 0;
|
||||
orth->mx[0][2] = 0;
|
||||
orth->mx[0][3] = 0;
|
||||
orth->mx[1][0] = 0;
|
||||
orth->mx[1][1] = 2.0f / t;
|
||||
orth->mx[1][2] = 0;
|
||||
orth->mx[1][3] = 0;
|
||||
orth->mx[2][0] = 0;
|
||||
orth->mx[2][1] = 0;
|
||||
orth->mx[2][2] = 2.0f / f;
|
||||
orth->mx[2][3] = 0;
|
||||
orth->mx[3][0] = -1;
|
||||
orth->mx[3][1] = -1;
|
||||
orth->mx[3][2] = 1;
|
||||
orth->mx[3][3] = 1;
|
||||
}
|
||||
return (orth);
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mat4_operations.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 19:00:12 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 19:00:13 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
void vec_mat_mult(t_mat4 *m, t_vec *v, t_pnt *result)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
x = v->x * m->mx[0][0] + v->y * m->mx[1][0] + v->z * m->mx[2][0] +
|
||||
m->mx[3][0];
|
||||
y = v->x * m->mx[0][1] + v->y * m->mx[1][1] + v->z * m->mx[2][1] +
|
||||
m->mx[3][1];
|
||||
result->x = (int)x;
|
||||
result->y = (int)y;
|
||||
}
|
||||
|
||||
t_mat4 *mat4_mult(t_mat4 *m1, t_mat4 *m2)
|
||||
{
|
||||
t_mat4 *m3;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
if ((m3 = (t_mat4 *)malloc(sizeof(t_mat4))))
|
||||
{
|
||||
while (i < 4)
|
||||
{
|
||||
j = 0;
|
||||
while (j < 4)
|
||||
{
|
||||
m3->mx[i][j] =
|
||||
m1->mx[i][0] * m2->mx[0][j] +
|
||||
m1->mx[i][1] * m2->mx[1][j] +
|
||||
m1->mx[i][2] * m2->mx[2][j] +
|
||||
m1->mx[i][3] * m2->mx[3][j];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (m3);
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* matrix_routine.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:20:31 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 19:00:22 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
void recalculate_trnsf_matrs(t_map *map)
|
||||
{
|
||||
mat4_x_rot(map->trnsf->xr, INIT_X + map->x_rot);
|
||||
mat4_z_rot(map->trnsf->zr, INIT_Z + map->z_rot);
|
||||
mat4_y_rot(map->trnsf->yr, INIT_Y + map->y_rot);
|
||||
mat4_scale(map->trnsf->sc,
|
||||
INIT_X_SCALE * map->scale[0],
|
||||
INIT_Y_SCALE * map->scale[1],
|
||||
INIT_Z_SCALE * map->scale[2]);
|
||||
}
|
||||
//
|
||||
//static void viewport_projection_translate(t_trnsf *tf)
|
||||
//{
|
||||
// t_mat4 *tmp;
|
||||
//
|
||||
// tmp = tf->vp_pr_tr;
|
||||
// tf->vp_pr_tr = mat4_mult(tf->vp, tf->pr);
|
||||
// free(tmp);
|
||||
// tmp = tf->vp_pr_tr;
|
||||
// tf->vp_pr_tr = mat4_mult(tf->tr, tf->vp_pr_tr);
|
||||
// free(tmp);
|
||||
//}
|
||||
|
||||
//void initial_trnsf_mats(t_fdf *fdf)
|
||||
//{
|
||||
// t_trnsf *tf;
|
||||
//
|
||||
// tf = trnsf_mat_init();
|
||||
// tf->vp = viewport_mat_init(fdf->w_width, fdf->w_height);
|
||||
// tf->pr = orth_mat_init(
|
||||
// (fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
|
||||
// fdf->map->x_max + 2,
|
||||
// (fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
|
||||
// fdf->map->x_max + 2,
|
||||
// fdf->map->z_max + 2);
|
||||
// mat4_translate(
|
||||
// tf->tr,
|
||||
// (float)((fdf->map->y_max > fdf->map->x_max) ?
|
||||
// fdf->map->y_max : fdf->map->x_max) / 2.0f,
|
||||
// (float)((fdf->map->y_max > fdf->map->x_max) ?
|
||||
// fdf->map->y_max : fdf->map->x_max) / 2.0f,
|
||||
// (float)fdf->map->z_max / 2.0f);
|
||||
// mat4_x_rot(tf->xr, INIT_X);
|
||||
// mat4_z_rot(tf->zr, INIT_Z);
|
||||
// mat4_y_rot(tf->yr, INIT_Y);
|
||||
// mat4_scale(tf->sc, INIT_X_SCALE, INIT_Y_SCALE, INIT_Z_SCALE);
|
||||
// viewport_projection_translate(tf);
|
||||
// fdf->map->trnsf = tf;
|
||||
//}
|
||||
|
||||
void mat4_mult_chain(t_trnsf *tf)
|
||||
{
|
||||
t_mat4 *tmp;
|
||||
|
||||
tmp = tf->fin;
|
||||
tf->fin = mat4_mult(tf->zr, tf->vp_pr_tr);
|
||||
free(tmp);
|
||||
tmp = tf->fin;
|
||||
tf->fin = mat4_mult(tf->xr, tf->fin);
|
||||
free(tmp);
|
||||
tmp = tf->fin;
|
||||
tf->fin = mat4_mult(tf->yr, tf->fin);
|
||||
free(tmp);
|
||||
tmp = tf->fin;
|
||||
tf->fin = mat4_mult(tf->sc, tf->fin);
|
||||
free(tmp);
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_input.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 19:00:28 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 19:00:30 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
//static int tab_to_color(t_color **color, char **tab)
|
||||
//{
|
||||
// int red;
|
||||
// int green;
|
||||
// int blue;
|
||||
//
|
||||
// red = ft_atoi(tab[0]);
|
||||
// green = ft_atoi(tab[1]);
|
||||
// blue = ft_atoi(tab[2]);
|
||||
// if (red > 255 || red < 0 ||
|
||||
// green > 255 || green < 0 ||
|
||||
// blue > 255 || blue < 0)
|
||||
// return (0);
|
||||
// (*color)->red = red;
|
||||
// (*color)->green = green;
|
||||
// (*color)->blue = blue;
|
||||
// return (1);
|
||||
//}
|
||||
|
||||
//static void wrong_heatmap(t_color **low, t_color **high)
|
||||
//{
|
||||
// ft_putstr("wrong heatmap! Type \"fdf --help\" for heatmap example\n");
|
||||
// free(*low);
|
||||
// free(*high);
|
||||
// *low = NULL;
|
||||
// *high = NULL;
|
||||
//}
|
||||
//
|
||||
//static void parse_heatmap(char *hm, t_color **low, t_color **high)
|
||||
//{
|
||||
// char **hm_tab;
|
||||
// char **low_tab;
|
||||
// char **high_tab;
|
||||
//
|
||||
// *low = malloc(sizeof(t_color));
|
||||
// *high = malloc(sizeof(t_color));
|
||||
// hm_tab = ft_strsplit(hm, '-');
|
||||
// if ((tab_length(hm_tab) != 2))
|
||||
// {
|
||||
// wrong_heatmap(low, high);
|
||||
// return ;
|
||||
// }
|
||||
// low_tab = ft_strsplit(hm_tab[0], ',');
|
||||
// high_tab = ft_strsplit(hm_tab[1], ',');
|
||||
// if (tab_length(low_tab) != 3 || tab_length(high_tab) != 3)
|
||||
// {
|
||||
// wrong_heatmap(low, high);
|
||||
// return ;
|
||||
// }
|
||||
// if (!tab_to_color(low, low_tab) || !tab_to_color(high, high_tab))
|
||||
// {
|
||||
// wrong_heatmap(low, high);
|
||||
// return ;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void parse_input(int ac, char **av, t_fdf **fdf)
|
||||
//{
|
||||
// t_color *low;
|
||||
// t_color *high;
|
||||
//
|
||||
// low = NULL;
|
||||
// high = NULL;
|
||||
// if ((ac < 2 || ac > 4) || (ac == 2 && ft_strstr(av[1], "--help")))
|
||||
// {
|
||||
// print_help();
|
||||
// quit(*fdf);
|
||||
// }
|
||||
// else if (ac == 2)
|
||||
// *fdf = fdf_init(av[1], low, high);
|
||||
// else if (ac == 4 && ft_strstr(av[1], "--heatmap"))
|
||||
// {
|
||||
// parse_heatmap(av[2], &low, &high);
|
||||
// *fdf = fdf_init(av[3], low, high);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// print_help();
|
||||
// quit(*fdf);
|
||||
// }
|
||||
//}
|
|
@ -1,36 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pnt_init.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 19:00:44 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 19:00:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
void pnt_init(t_map *map)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
float z;
|
||||
|
||||
map->arr_pnt = malloc(sizeof(t_pnt *) * (map->y_max));
|
||||
i = 0;
|
||||
while (i < map->y_max)
|
||||
{
|
||||
map->arr_pnt[i] = malloc(sizeof(t_pnt) * (map->x_max));
|
||||
j = 0;
|
||||
while (j < map->x_max)
|
||||
{
|
||||
z = map->arr_vec[i][j].z - map->z_min;
|
||||
map->arr_pnt[i][j].z = z;
|
||||
first_color(&map->arr_pnt[i][j], z, map);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
42
src/render.c
42
src/render.c
|
@ -1,42 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* render.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 19:00:37 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 19:01:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
//void render(t_fractol *fr)
|
||||
//{
|
||||
// int i;
|
||||
// int j;
|
||||
// t_map *map;
|
||||
//
|
||||
// map = fr->map;
|
||||
// i = 0;
|
||||
// while (i < map->y_max)
|
||||
// {
|
||||
// j = 0;
|
||||
// while (j < map->x_max)
|
||||
// {
|
||||
// if (i == map->y_max - 1 && j < map->x_max - 1)
|
||||
// line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fr);
|
||||
// else if (i < map->y_max - 1 && j == map->x_max - 1)
|
||||
// line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], fr);
|
||||
// else if (i < map->y_max - 1 && j < map->x_max - 1)
|
||||
// {
|
||||
// line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], fr);
|
||||
// line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fr);
|
||||
// }
|
||||
// j++;
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
// mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
|
||||
//}
|
Loading…
Add table
Reference in a new issue