diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-01 12:33:55 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-01 12:33:55 +0100 |
| commit | a0f26d0407a2e514e9dcfd2baeef5ccd98f7b3dd (patch) | |
| tree | fc919296727d6a6dc4eda868d143cb86017ed2bc /src/render.c | |
| parent | 57867bbbdc24b734d85f8d3569c7ad27dcd9504d (diff) | |
| download | cub3d-a0f26d0407a2e514e9dcfd2baeef5ccd98f7b3dd.tar.gz cub3d-a0f26d0407a2e514e9dcfd2baeef5ccd98f7b3dd.tar.bz2 cub3d-a0f26d0407a2e514e9dcfd2baeef5ccd98f7b3dd.zip | |
texture selector, collision detection
Diffstat (limited to 'src/render.c')
| -rw-r--r-- | src/render.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/render.c b/src/render.c index 88b0cae..820036d 100644 --- a/src/render.c +++ b/src/render.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/11 13:37:17 by cacharle #+# #+# */ -/* Updated: 2020/01/30 15:17:49 by cacharle ### ########.fr */ +/* Updated: 2020/02/01 12:06:58 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,8 @@ int render_update(void *param) return (0); } render_update_window(state); - mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->window.id, 0, 0); + mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, + state->window.id, 0, 0); return (0); } @@ -43,7 +44,7 @@ void render_column(t_state *state, int x) rstate.x = x; rstate_ray(state, &rstate); - rstate.map_pos = vector_new((double)((int)state->pos.x), (double)((int)state->pos.y)); //floor? + rstate.map_pos = vector_new((double)((int)state->pos.x), (double)((int)state->pos.y)); rstate_delta(&rstate); rstate_init_probe(state, &rstate); rstate.map_step = vector_new(rstate.ray.x < 0.0 ? -1.0 : 1.0, rstate.ray.y < 0.0 ? -1.0 : 1.0); @@ -73,35 +74,32 @@ void render_window_column(t_state *state, t_render_state *rstate) white.hexcode = 0x00ffffff; i = 0; while (i < rstate->draw_start) - ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = state->ceilling_color; - while (i < rstate->draw_end) - ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = white; - render_texture(state, rstate); - i = rstate->draw_end; + ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = + state->ceilling_color; + render_texture(state, rstate, &i); while (i < state->window.height) - ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = state->floor_color; + ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = + state->floor_color; } -void render_texture(t_state *state, t_render_state *rstate) +void render_texture(t_state *state, t_render_state *rstate, int *i) { - int i; - double step; - double tex_pos; - int tex_y; int tex_x; + int tex_y; + double tex_step; + double tex_pos; t_image *texture; - texture = get_tex(state, rstate); - tex_x = get_tex_x(state, rstate, texture); - step = 1.0 * texture->height / rstate->line_height; - tex_pos = (rstate->draw_start - state->window.height / 2 + rstate->line_height / 2) * step; - i = rstate->draw_start - 1; - while (++i < rstate->draw_end) + texture = texture_select(state, rstate); + tex_x = texture_x(state, rstate, texture); + tex_step = (double)texture->height / (double)rstate->line_height; + tex_pos = (rstate->draw_start - state->window.height / 2 + rstate->line_height / 2) * tex_step; + while (++(*i) < rstate->draw_end) { tex_y = (int)tex_pos & (texture->height - 1); - tex_pos += step; - ((t_color*)state->window.data)[i * state->window.width + rstate->x] = + tex_pos += tex_step; + ((t_color*)state->window.data)[*i * state->window.width + rstate->x] = ((t_color*)texture->data)[texture->height * tex_y + tex_x]; } } |
