diff options
Diffstat (limited to 'src/render.c')
| -rw-r--r-- | src/render.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/src/render.c b/src/render.c index 5d3c5d4..87379a0 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/02/02 09:56:37 by cacharle ### ########.fr */ +/* Updated: 2020/02/02 23:30:17 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,33 +23,27 @@ int render_update(void *param) exit(EXIT_SUCCESS); return (0); } - state->surface = &state->window; - render_update_window(state, CELL_WALL); - mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, - state->surface->id, 0, 0); - state->surface = &state->sprite_window; - for (int i = 0; i < state->surface->width * state->surface->height; i++) - ((unsigned int*)state->surface->data)[i] = 0xff000000; - render_update_window(state, CELL_ITEM); - mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, - state->surface->id, 0, 0); + render_update_window(state); + render_update_sprite(state); + mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->window.id, 0, 0); + /* for (int i = 0; i < state->window.width * state->window.height; i++) */ + /* ((unsigned int*)state->window.data)[i] = 0xff000000; */ return (0); } -void render_update_window(t_state *state, t_cell target) +void render_update_window(t_state *state) { int x; x = -1; - while (++x < state->surface->width) - render_column(state, x, target); + while (++x < state->window.width) + render_column(state, x); } -void render_column(t_state *state, int x, t_cell target) +void render_column(t_state *state, int x) { t_render_state rstate; - rstate.target = target; rstate.x = x; rstate_ray(state, &rstate); rstate.map_pos = vector_new((double)((int)state->pos.x), (double)((int)state->pos.y)); @@ -60,19 +54,19 @@ void render_column(t_state *state, int x, t_cell target) { rstate.side = rstate.probe.x < rstate.probe.y ? SIDE_WE : SIDE_NS; rstate_next_probe(&rstate); - if (target == CELL_ITEM && state->map[(int)rstate.map_pos.y][(int)rstate.map_pos.x] == CELL_WALL) - return ; - if (state->map[(int)rstate.map_pos.y][(int)rstate.map_pos.x] == target) + if (state->map[(int)rstate.map_pos.y][(int)rstate.map_pos.x] == CELL_WALL) break ; } rstate_perp_dist(state, &rstate); + state->z_buffer[x] = rstate.perp_dist; + /* printf("%f\n", state->z_buffer[x]); */ rstate_line_height(state, &rstate); - rstate.draw_start = state->surface->height / 2 - rstate.line_height / 2; - rstate.draw_end = state->surface->height / 2 + rstate.line_height / 2; + rstate.draw_start = state->window.height / 2 - rstate.line_height / 2; + rstate.draw_end = state->window.height / 2 + rstate.line_height / 2; if (rstate.draw_start < 0) rstate.draw_start = 0; - if (rstate.draw_end > state->surface->height - 1) - rstate.draw_end = state->surface->height - 1; + if (rstate.draw_end > state->window.height - 1) + rstate.draw_end = state->window.height - 1; render_window_column(state, &rstate); } @@ -84,12 +78,11 @@ void render_window_column(t_state *state, t_render_state *rstate) white.hexcode = 0x00ffffff; i = 0; while (i < rstate->draw_start) - ((t_color*)state->surface->data)[i++ * state->surface->width + rstate->x] = - state->ceilling_color; + ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = state->ceilling_color; i--; render_texture(state, rstate, &i); - while (i < state->surface->height) - ((t_color*)state->surface->data)[i++ * state->surface->width + rstate->x] = + while (i < state->window.height) + ((t_color*)state->window.data)[i++ * state->window.width + rstate->x] = state->floor_color; } @@ -104,12 +97,12 @@ void render_texture(t_state *state, t_render_state *rstate, int *i) 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->surface->height / 2 + rstate->line_height / 2) * tex_step; + 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 += tex_step; - ((t_color*)state->surface->data)[*i * state->surface->width + rstate->x] = + ((t_color*)state->window.data)[*i * state->window.width + rstate->x] = ((t_color*)texture->data)[texture->height * tex_y + tex_x]; } } |
