resolve floating point exception when wliding through walls
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef CUBE3D_PROTO_H
|
||||
# define CUBE3D_PROTO_H
|
||||
|
||||
void plr_turn(t_plr *plr, int deg);
|
||||
|
||||
// -------------------------------
|
||||
// SRC
|
||||
// -------------------------------
|
||||
|
||||
27
maps/map_valid_14.cub
Normal file
27
maps/map_valid_14.cub
Normal file
@@ -0,0 +1,27 @@
|
||||
NO textures/coin.xpm
|
||||
SO textures/coin.xpm
|
||||
EA textures/coin.xpm
|
||||
WE textures/coin.xpm
|
||||
|
||||
F 220 , 100, 30
|
||||
|
||||
C 225 , 30 , 0
|
||||
|
||||
1111111111111111111111111111
|
||||
1N00000000000000011100000001
|
||||
1111000000000000100000110001
|
||||
1111001000000000000110000111
|
||||
1000000000000000010101000001
|
||||
1111110000000000000000001111
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1000000000000000000000000001
|
||||
1111111111111111111111111111
|
||||
@@ -42,6 +42,11 @@ int main(int ac, char **av)
|
||||
mb_init(destroy_mlx, game);
|
||||
|
||||
// draw game a first time before it start
|
||||
|
||||
// tmp
|
||||
plr_turn(&game->plr, -63);
|
||||
// tmp end
|
||||
|
||||
draw(game);
|
||||
|
||||
// receive a keypress event
|
||||
|
||||
@@ -36,13 +36,11 @@ static void wall_length(t_rcast *rcast)
|
||||
|
||||
rcast->wall.start.x = rcast->ray_nb;
|
||||
rcast->wall.end.x = rcast->ray_nb;
|
||||
// len = sqrt(pow(ray->end.x - ray->start.x, 2) + pow(ray->end.y - ray->start.y, 2));
|
||||
if (rcast->is_x == 1)
|
||||
{
|
||||
len = rcast->next_x - rcast->ray_step_x;
|
||||
if (rcast->slope_y)
|
||||
len /= ft_abs(rcast->slope_y);
|
||||
// len = (double)len * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
||||
len = rcast->screen_dist * len / (rcast->slope_x);
|
||||
}
|
||||
else if (rcast->is_x == 0)
|
||||
@@ -50,7 +48,6 @@ static void wall_length(t_rcast *rcast)
|
||||
len = rcast->next_y - rcast->ray_step_y;
|
||||
if (rcast->slope_x)
|
||||
len /= ft_abs(rcast->slope_x);
|
||||
// len = (double)len * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
|
||||
len = rcast->screen_dist * len / (rcast->slope_y);
|
||||
}
|
||||
rcast->ray_len = ft_abs(len);
|
||||
@@ -110,7 +107,6 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
draw_line(&game->map_img, &ray, 0x00FF00FF);
|
||||
// tmp end
|
||||
|
||||
|
||||
wall_length(rcast);
|
||||
wall_height(rcast);
|
||||
draw_column(game, rcast);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
// temp, to map all the keys on linux and mac
|
||||
static int print_keycode(int keycode)
|
||||
static int print_keycode(int keycode, t_plr *plr)
|
||||
{
|
||||
ft_putnbr_fd(keycode, 1);
|
||||
ft_putchar_fd(' ', 1);
|
||||
ft_putnbr_fd(plr->rot, 1);
|
||||
ft_putchar_fd('\n', 1);
|
||||
return(0);
|
||||
}
|
||||
@@ -38,7 +40,7 @@ int keypress(int keycode, t_game *game)
|
||||
unsigned i;
|
||||
|
||||
// temp
|
||||
print_keycode(keycode);
|
||||
print_keycode(keycode, &game->plr);
|
||||
// temp end
|
||||
|
||||
i = 0;
|
||||
|
||||
@@ -5,16 +5,23 @@ void plr_posx_decrement(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x - PLR_MV;
|
||||
pos.y = plr->exact.y;
|
||||
rotate_double(plr, &pos);
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
@@ -26,16 +33,23 @@ void plr_posy_decrement(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y - PLR_MV;
|
||||
rotate_double(plr, &(pos));
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
@@ -47,16 +61,23 @@ void plr_posx_increment(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x + PLR_MV;
|
||||
pos.y = plr->exact.y;
|
||||
rotate_double(plr, &(pos));
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
@@ -68,16 +89,23 @@ void plr_posy_increment(t_game *game, t_plr *plr)
|
||||
t_d_coord pos;
|
||||
int limit_x;
|
||||
int limit_y;
|
||||
int limit_xy;
|
||||
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y + PLR_MV;
|
||||
rotate_double(plr, &(pos));
|
||||
limit_x = plr_out_limits(game, pos.x, plr->pos.y);
|
||||
limit_y = plr_out_limits(game, plr->pos.x, pos.y);
|
||||
limit_xy = plr_out_limits(game, pos.x, pos.y);
|
||||
if (limit_x)
|
||||
pos.x = plr->exact.x;
|
||||
if (limit_y)
|
||||
pos.y = plr->exact.y;
|
||||
if (limit_xy && !limit_y && !limit_x)
|
||||
{
|
||||
pos.x = plr->exact.x;
|
||||
pos.y = plr->exact.y;
|
||||
}
|
||||
plr->exact.x = pos.x;
|
||||
plr->exact.y = pos.y;
|
||||
(plr->pos.x) = (int)(pos.x);
|
||||
|
||||
@@ -73,3 +73,18 @@ void plr_turn_right(t_plr *plr)
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
void plr_turn(t_plr *plr, int deg)
|
||||
{
|
||||
double radi;
|
||||
double radj;
|
||||
|
||||
plr->rot = deg;
|
||||
// calculate trigo for rotations
|
||||
radi = plr->rot * M_PI / 180;
|
||||
radj = radi + (M_PI / 2);
|
||||
plr->cosi = cos(radi);
|
||||
plr->sini = sin(radi);
|
||||
plr->cosj = cos(radj);
|
||||
plr->sinj = sin(radj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user