Skip to content

Commit

Permalink
Fixed the weird sprites through the wall issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesim Zaim committed Feb 8, 2024
1 parent ae3c212 commit 7fea4ea
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
14 changes: 7 additions & 7 deletions include/meta.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* meta.h :+: :+: */
/* +:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* :::::::: */
/* meta.h :+: :+: */
/* +:+ */
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/02/05 14:01:44 by joppe #+# #+# */
/* Updated: 2024/02/05 14:01:52 by joppe ######## odam.nl */
/* Updated: 2024/02/08 13:54:31 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -218,7 +218,7 @@ typedef struct s_attr {
t_rgba ceiling_c;
uint32_t sprite_count;
uint32_t sprite_arr_index;
t_sprite *sprites; // we need to make the sprite count modular
t_sprite *sprites;
} t_attr;

typedef struct s_minimap {
Expand Down
17 changes: 9 additions & 8 deletions src/game/sprite.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* sprite.c :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* :::::::: */
/* sprite.c :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */
/* Updated: 2024/02/07 12:48:55 by yzaim ######## odam.nl */
/* Updated: 2024/02/08 14:09:34 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -68,8 +68,9 @@ void sprite_calculate(t_player *p)
const t_vec2d s_pos = (t_vec2d){sp[p->sprite_order[i]].pos.x - p->position.x, sp[p->sprite_order[i]].pos.y - p->position.y};


const double inv_det = 1.0 / (p->cam_plane.x * p->direction.y) - (p->cam_plane.y * p->direction.x);

const double inv_det = 1.0 / (p->cam_plane.x * p->direction.y - p->direction.x * p->cam_plane.y);

printf("invdet [%lf]\n", inv_det);

const t_vec2d transform = {inv_det * (p->direction.y * s_pos.x - p->direction.x * s_pos.y),
inv_det * (-(p->cam_plane.y) * s_pos.x + p->cam_plane.x * s_pos.y)};
Expand Down
32 changes: 26 additions & 6 deletions src/game/sprite_utils.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* sprite_utils.c :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* :::::::: */
/* sprite_utils.c :+: :+: */
/* +:+ */
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/25 16:01:20 by jboeve #+# #+# */
/* Updated: 2024/01/29 12:50:12 by yesimzaim ######## odam.nl */
/* Updated: 2024/02/08 14:06:22 by yzaim ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -66,7 +66,27 @@ void quick_sort(double *sprite_dist, int32_t *sprite_order, int32_t low, int32_t
}
}

void reverse(double *arr1, int32_t *arr2, uint32_t size)
{
uint32_t i;
double tmp1;
int32_t tmp2;

i = 0;
while (i < size / 2)
{
tmp1 = arr1[i];
arr1[i] = arr1[size - i - 1];
arr1[size - i - 1] = tmp1;
tmp2 = arr2[i];
arr2[i] = arr2[size - i - 1];
arr2[size - i - 1] = tmp2;
i++;
}
}

void sprite_sort(double *sprite_dist, int32_t *sprite_order, uint32_t sprite_count)
{
quick_sort(sprite_dist, sprite_order, 0, sprite_count - 1);
// reverse(sprite_dist, sprite_order, sprite_count);
}
15 changes: 7 additions & 8 deletions test_maps/valid_tex.cub
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ SO texture_examples/purplestone2.png
F texture_examples/floor.png
C texture_examples/ceiling_square.png

SP texture_examples/barrel.png 3.5 2.5
SP texture_examples/barrel.png 4.5 2.5
SP texture_examples/pillar.png 4.5 2.5
SP texture_examples/barrel.png 5.5 2.5
SP texture_examples/hoofd.png 6.5 2.5
SP texture_examples/sexy.png 7.5 2.5

11111111111111
1000000001
1000000001
1000000001
1000000001
1111101111
11111111111111
1000000001
1000000001
1000000001
1000000001
1111101111
111000N00111
100000000001
10000000011
Expand Down

0 comments on commit 7fea4ea

Please sign in to comment.