-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.c
61 lines (56 loc) · 2.46 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <jaesjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 15:59:46 by jaemjeon #+# #+# */
/* Updated: 2022/11/13 13:13:39 by jaesjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "mlx.h"
void malloc_resources(t_game *game)
{
game->ray_data = (t_ray *)malloc(sizeof(t_ray) * game->info.screen_x);
game->wall_pixel = \
(t_vector2_d *)malloc(sizeof(t_vector2_d) * game->info.screen_x);
game->wall_line = \
(t_vector2 *)malloc(sizeof(t_vector2) * game->info.screen_x);
if (!game->ray_data || !game->wall_pixel || !game->wall_line)
exit_with_err("Malloc error", E_NOMEM);
}
void graphic_resource_init(t_game *game)
{
t_info *const info = &game->info;
ft_memset(game, 0, sizeof(t_game));
info->mlx_ptr = mlx_init();
if (info->mlx_ptr == NULL)
exit_with_err("mlx function error", E_PERM);
mlx_get_screen_size(info->mlx_ptr, &info->screen_x, &info->screen_y);
info->screen_x *= 0.6;
info->screen_y *= 0.6;
info->fov_h = 60.0;
info->fov_v = (double)info->screen_y / (double)info->screen_x \
* info->fov_h;
info->win_ptr = mlx_new_window(info->mlx_ptr, info->screen_x, \
info->screen_y, "cub3D");
game->view_data.img = mlx_new_image(game->info.mlx_ptr, \
game->info.screen_x, game->info.screen_y);
if (!info->win_ptr || !game->view_data.img)
exit_with_err("mlx function error", E_PERM);
game->view_data.addr = mlx_get_data_addr(game->view_data.img, \
&game->view_data.bits_per_pixel, &game->view_data.line_length, \
&game->view_data.endian);
malloc_resources(game);
}
void player_handle_setting(t_game *game)
{
game->player.move_speed = 0.1;
game->player.rotate_speed_h = 1.5;
game->player.rotate_speed_v = 30;
game->player.vertical_dist_pixel = 0;
game->player.view_trans = 0;
game->info.using_mouse = FALSE;
}