aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_floor_cast.c
blob: e7d3b0fa7eb898302b75efcad409afbe673e8266 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_raycasting.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:22:57 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:23:42 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <cub3d.h>
#include <stdint.h>

void
	ft_floor_cast(t_cub *cl)
{
	t_ray			*rl;
	const uint32_t	map_x = (uint32_t)&cl->plist.pos_x;
	const uint32_t	map_y = (uint32_t)&cl->plist.pos_y;

	rl = &cl->rlist;
	if (rl->side == 0 && rl->x_ray_dir > 0)
	{
		rl->floor_x_wall = (double)map_x;
		rl->floor_y_wall = (double)map_y + rl->wall_hit_x;
	}
	else if (rl->side == 0 && rl->x_ray_dir < 0)
	{
		rl->floor_x_wall = (double)map_x + 1.0;
		rl->floor_y_wall = (double)map_y + rl->wall_hit_x;
	}
	else if (rl->side == 1 && rl->y_ray_dir > 0)
	{
		rl->floor_x_wall = (double)map_x + rl->wall_hit_x;
		rl->floor_y_wall = (double)map_y;
	}
	else
	{
		rl->floor_x_wall = (double)map_x + rl->wall_hit_x;
		rl->floor_y_wall = (double)map_y + 1.0;
	}
}