Browse Source

fix: playerDir was normed to 0.66. add: biger test map

master
narnaud 3 years ago
parent
commit
5d26366529
  1. 4
      includes/cub3d.h
  2. 51
      maps/scene_big.cub
  3. 10
      sources/hooks.c
  4. 8
      sources/utils.c

4
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/06/01 14:59:38 by narnaud ### ########.fr */
/* Updated: 2022/06/01 17:45:22 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -102,7 +102,7 @@ int update_hook(t_env *env);
int rgb_to_int(char **rgb);
void set_vec(t_vec_d *vec, double x, double y);
double vec_len(t_vec_d vec);
void rot_vec(t_vec_d *vec, double rad);
void rot_vec(t_vec_d *vec, double rad, double init_len);
t_env *parse_envFile(char *filename);
char *get_next_line(int fd);

51
maps/scene_big.cub

@ -0,0 +1,51 @@
NO ./textures/wood.xpm
EA ./textures/colorstone.xpm
SO ./textures/wood.xpm
WE ./textures/wood.xpm
F 18, 176, 12
C 27, 210, 227
111100001111111111111111111111111111111111111111
1001000001 1
1001111101 1
1001000001 1
11111 11111 1001000001 1
10001 1000111110011111111111 1
10001 1000000000000000000001 1
10001 1000000000000000000001 1
10001 10001111011111111000011111110000000000000000000001111111
10001 10001 1010000001000000000000000000000000000000000000001
10001 10001 1011111111000010000010000000000000000000001000001
10001111110001 1000000000000010010010011111111111111111001001001
10000000000001 1111101111000010010010000000000000000000001001001
10000000000001 101111000010010011111111111111111111111001001
10000E00000001 100000000010010000000000000000000000000001001
10000000000001 100000000010011111111111111111111111111111001
10111111111111 111111111110000000000000000000000000000000001
100000001 100000000011111111111111111111111111111111101
1111110011111111111110000000001 101
10000000100010000000000000000111 101
10000000000000000000000000000101 101
11111111110000000001111111111101111111111111111111111111111111101111111
11111111110000000001111111111100000000000000000000000000000000000000001
11111111110000000001111111111101111111111111111100000000000000000000001
11111111110000000001111111111101111111111110000000000000000011110000001
1111111111000000000111111111110111111111111000000000000000001 10000001
1111111111000000000111111111110100000000000001100000000000001 10000001
1100000000011110000000001111110100000000000001100000111111111 10000001
1100000000011110000000001111110100000000000001111111111111111 11111111
11000000000111100000000011111101001111111111111111111111111111111111111
11000000000111100000000011111101000000000000000000000000000000000000001
11101111111101111111100000000001010001000100010001000100010001000100101
11101111111111111111111111111111000100010001000100010001000100010001001
10101000000000000100000000000010010001000100010001000100010001000100011
10101111110111110101111111101111000100010001000100010001000100010001001
10101000000101000001000000000010010001000100010001000100010001000100011
10101011111101011101011111111111000100010001000100010001000100010001001
10101000000000010101000000000000010001000100010001000100010001000100011
10000011111111110101011111111111000100010001000100010001000100010001001
10101000001000010101000000000010010001000100010001000100010001000100011
10111111111111010101111111111111000100010001000100010001000100010001001
10000001000000000000000000000010010001000100010001000100010001000100011
11111111111111111111111111111111111111111111111111111111111111111111111

10
sources/hooks.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/01 13:47:30 by narnaud #+# #+# */
/* Updated: 2022/06/01 17:10:10 by narnaud ### ########.fr */
/* Updated: 2022/06/01 17:49:24 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,18 +33,18 @@ int update_hook(t_env *env)
double dY;
dX = (env->controls[KEY_W] - env->controls[KEY_S]) * env->playerDir.x
/ (10 - env->controls[KEY_SHFT] * 5);
/ (20 - env->controls[KEY_SHFT] * 10);
dY = (env->controls[KEY_W] - env->controls[KEY_S]) * env->playerDir.y
/ (10 - env->controls[KEY_SHFT] * 5);
/ (20 - env->controls[KEY_SHFT] * 10);
if (env->map[(int)env->playerPos.y][(int)(env->playerPos.x + dX)] == '0')
set_vec(&env->playerPos, env->playerPos.x + dX, env->playerPos.y);
if (env->map[(int)(env->playerPos.y + dY)][(int)env->playerPos.x] == '0')
set_vec(&env->playerPos, env->playerPos.x, env->playerPos.y + dY);
rot_vec(&env->playerDir,
(double)(env->controls[KEY_D] - env->controls[KEY_A]) * M_PI / 36);
(double)(env->controls[KEY_D] - env->controls[KEY_A]) * M_PI / 72, 1);
rot_vec(&env->camPlan,
(double)(env->controls[KEY_D] - env->controls[KEY_A]) * M_PI / 36);
(double)(env->controls[KEY_D] - env->controls[KEY_A]) * M_PI / 72, 0.66);
if (DEBUG)
{
printf("playerPos: %f, %f. playerDir: %f, %f\n", env->playerPos.x, env->playerPos.y, env->playerDir.x, env->playerDir.y);

8
sources/utils.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/31 08:59:01 by narnaud #+# #+# */
/* Updated: 2022/06/01 17:16:10 by narnaud ### ########.fr */
/* Updated: 2022/06/01 17:44:56 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,13 +23,13 @@ void set_vec(t_vec_d *vec, double x, double y)
vec->y = y;
}
void rot_vec(t_vec_d *vec, double rad)
void rot_vec(t_vec_d *vec, double rad, double init_len)
{
double len;
len = vec_len(*vec);
vec->x = (cos(rad) * vec->x - sin(rad) * vec->y) * 0.66 / len;
vec->y = (sin(rad) * vec->x + cos(rad) * vec->y) * 0.66 / len;
vec->x = (cos(rad) * vec->x - sin(rad) * vec->y) * init_len / len;
vec->y = (sin(rad) * vec->x + cos(rad) * vec->y) * init_len / len;
}

Loading…
Cancel
Save