@@ -15,7 +15,7 @@
#include <fcntl.h>
#include "libft.h"

static t_map *get_map_fromlst(t_map *map, t_list *list)
static void get_map_fromlst(t_map *map, t_list *list)
{
int x;
int y;
@@ -25,40 +25,31 @@ static t_map *get_map_fromlst(t_map *map, t_list *list)
y = 0;
while (list && map)
{
//ft_putendl(((char **)list->content)[0]);
if (!(map->points[y] = (t_points *)malloc(sizeof(t_points) * map->width)))
fdf_error(2);
x = 0;
while (x < map->width)
{
map->points[y][x].x = x * 10;
map->points[y][x].y = y * 10;
if (!ft_strdigit(((char **)list->content)[x]))
if (!ft_strdigit(((char **)list->content)[0]))
fdf_error(4);
map->points[y][x].z = ft_atoi(((char **)list->content)[x]) / 2;
// ft_putstr(&((char*)list->content)[0]);
x++;
}
y++;
list = list->next;
}
free(list);
return (map);
// free(list);
}

t_map *get_map(char *path)
static void build_map(char *path, int fd, t_map *map)
{
char **split;
int fd;
t_list *list;
t_map *map;

if (!(map = (t_map *)malloc(sizeof(t_map))))
fdf_error(2);
map->width = 0;
map->height = 0;
if (!(fd = open(path, O_RDONLY)))
fdf_error(1);
while (get_next_line(fd, &path) > 0)
{
split = ft_strsplit(path, ' ');
@@ -76,86 +67,19 @@ t_map *get_map(char *path)
list->content = (void *)split;
}
}
close(fd);
return (get_map_fromlst(map, list));
get_map_fromlst(map, list);
}

/*
static int fdf_get_width(char **split)
t_map *get_map(char *path)
{
int i;
i = 0;
while (*split++)
i++;
return (i);
}
static void fdf_fill_map(t_map *map, t_list *list)
{
int x;
int y;
if (!(map->points = (t_points **)malloc(sizeof(t_points *) * map->height)))
fdf_error(2);
y = 0;
while (list)
{
if (!(map->points[y] = (t_points *)malloc(sizeof(t_points) * map->width)))
fdf_error(2);
x = 0;
while (x < map->width)
{
map->points[y][x].x = x;
map->points[y][x].y = y;
map->points[y][x].z = ft_atoi(((char **)list->content)[x]);
x++;
}
y++;
list = list->next;
}
}
static void fdf_build_map(int fd, t_map *map)
{
char *line;
char **split_line;
t_list *list;
map->width = 0;
map->height = 0;
while (get_next_line(fd, &line) > 0)
{
split_line = ft_strsplit(line, ' ');
free(line);
if (!map->height)
{
map->width = fdf_get_width(split_line);
list = ft_lstnew(&split_line, sizeof(char **));
list->content = (void *)split_line;
}
else
{
// TODO: check errors in file
ft_lstadd(&list, ft_lstnew(&split_line, sizeof(char **)));
list->content = (void *)split_line;
}
map->height++;
}
fdf_fill_map(map, list);
// TODO: free list
}
t_map *fdf_get_map(char *path)
{
int fd;
t_map *map;
int fd;

if ((fd = open(path, O_RDONLY)) < 0)
fdf_error(3);
if (!(fd = open(path, O_RDONLY)))
fdf_error(1);
if (!(map = (t_map *)malloc(sizeof(t_map))))
fdf_error(2);
fdf_build_map(fd, map);
build_map(path, fd, map);
close(fd);
return (map);
}
*/
}
@@ -15,10 +15,9 @@
#include "get_next_line.h"
#include <math.h>


static void fdf_update_minmax(t_map *map, t_points *points)
static void get_minmax(t_map *map, t_points *points)
{
t_2dpos *proj;
t_2dpos *proj;

proj = &points->project;
if (!points->x && !points->y)
@@ -37,43 +36,6 @@ static void fdf_update_minmax(t_map *map, t_points *points)
}
}

/*
static void get_new_max(t_map *map, t_points *points)
{
t_2dpos *proj;
proj = &points->project;
if (points && map)
{
map->max.x = proj->x > map->max.x ? proj->x : map->max.x;
map->max.y = proj->y > map->min.y ? proj->y : map->max.y;
}
else
{
map->max.x = proj->x;
map->max.y = proj->y;
}
}
static void get_new_min(t_map *map, t_points *points)
{
t_2dpos *proj;
proj = &points->project;
if (points && map)
{
map->min.x = proj->x < map->min.x ? proj->x : map->min.x;
map->min.y = proj->y < map->min.y ? proj->y : map->min.y;
}
else
{
map->min.x = proj->x;
map->min.y = proj->y;
}
get_new_max(map, points);
}
*/

void projection_iso(t_map *map)
{
int x;
@@ -87,12 +49,11 @@ void projection_iso(t_map *map)
y = 0;
while (y < map->height)
{
pts = &map->points[y][x];

pts = &map->points[y][x];
proj_pts = &pts->project;
proj_pts->x = (sqrt(2) / 2.0) * (pts->x - pts->y);
proj_pts->y = (sqrt(2 / 3.0) * -1 * pts->z) - ((1.0 / sqrt(6)) * (pts->x + pts->y));
fdf_update_minmax(map, pts);
get_minmax(map, pts);
y++;
}
x++;
@@ -0,0 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zoom.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ada-cunh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/27 00:10:11 by ada-cunh #+# #+# */
/* Updated: 2017/02/27 00:10:13 by ada-cunh ### ########.fr */
/* */
/* ************************************************************************** */

#include "fdf.h"
#include "mlx.h"
#include <math.h>
/*
void get_center(t_map *map)
{
int x;
int y;
x = 0;
while (x < map->width)
{
y = 0;
while (y < map->height)
{
map->points[y][x].cx += map->width / 2;
map->points[y][x].cy += map->height / 2;
y++;
}
x++;
}
}
static void zoom_in(t_map *map)
{
int x;
int y;
x = 0;
while (x < map->width)
{
y = 0;
while (y < map->height)
{
map->points[y][x].x -= map->points[y][x].cx;
map->points[y][x].y -= map->points[y][x].cy;
map->points[y][x].x *= Z_IN;
map->points[y][x].y *= Z_IN;
map->points[y][x].x += map->points[y][x].cx;
map->points[y][x].y += map->points[y][x].cy;
y++;
}
x++;
}
}
static void zoom_out(t_map *map)
{
int x;
int y;
x = 0;
while (x < map->width)
{
y = 0;
while (y < map->height)
{
map->points[y][x].x -= map->points[y][x].cx;
map->points[y][x].y -= map->points[y][x].cy;
map->points[y][x].x /= Z_OUT;
map->points[y][x].y /= Z_OUT;
map->points[y][x].x += map->points[y][x].cx;
map->points[y][x].y += map->points[y][x].cy;
y++;
}
x++;
}
}
void zoom_map(t_env *env, int zoom)
{
if (zoom == ZOOM_IN)
zoom_in(env->map);
else if (zoom == ZOOM_OUT)
zoom_out(env->map);
}
*/
0 test
Empty file.