diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-16 10:10:19 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-16 10:10:19 +0100 |
| commit | 75c7e5548de908c37c0fbdd49df50f3e7447e120 (patch) | |
| tree | 5b4511d817e8d2b8d294b935e7157bb4a0756c77 /render.c | |
| parent | 83ca51f2cc760dca7635232b4b6e40db9616534f (diff) | |
| download | cub3d-75c7e5548de908c37c0fbdd49df50f3e7447e120.tar.gz cub3d-75c7e5548de908c37c0fbdd49df50f3e7447e120.tar.bz2 cub3d-75c7e5548de908c37c0fbdd49df50f3e7447e120.zip | |
fixing raycasting things and braking computers
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 41 |
1 files changed, 35 insertions, 6 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/11 13:37:17 by cacharle #+# #+# */ -/* Updated: 2020/01/15 15:09:32 by cacharle ### ########.fr */ +/* Updated: 2020/01/16 10:06:04 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,11 @@ void render_update_window(t_state *state) x = -1; while (++x < state->window.width) + { + /* x = state->window.width / 2 + 1; */ + /* printf("\nx %d\n", x); */ render_column(state, x); + } } void render_column(t_state *state, int x) @@ -43,34 +47,59 @@ void render_column(t_state *state, int x) t_render_state rstate; rstate.x = x; + /* printf("1\n"); */ rstate_ray(state, &rstate); - vector_new((double)((int)state->pos.x), (double)((int)state->pos.y)); + /* printf("ray [%f %f]\n", rstate.ray.x, rstate.ray.y); */ + rstate.map_pos = vector_new((double)((int)state->pos.x), (double)((int)state->pos.y)); //floor? + /* printf("map_pos [%f %f]\n", rstate.map_pos.x, rstate.map_pos.y); */ rstate_delta(&rstate); + /* printf("delta [%f %f]\n", rstate.delta.x, rstate.delta.y); */ rstate_init_probe(state, &rstate); - vector_new(rstate.ray.x < 0.0 ? -1.0 : 1.0, rstate.ray.y < 0.0 ? -1.0 : 1.0); + /* printf("probe [%f %f]\n", rstate.probe.x, rstate.probe.y); */ + rstate.map_step = vector_new(rstate.ray.x < 0.0 ? -1.0 : 1.0, rstate.ray.y < 0.0 ? -1.0 : 1.0); + /* printf("map_step [%f %f]\n", rstate.map_step.x, rstate.map_step.y); */ while (TRUE) { rstate.side = rstate.probe.x < rstate.probe.y ? SIDE_WE : SIDE_WE; + /* printf("side %s\n", rstate.side == SIDE_WE ? "side we" : "side ns"); */ rstate_next_probe(&rstate); + /* printf("2\n"); */ + /* printf("> [%d %d]\n", (int)rstate.map_pos.x, (int)rstate.map_pos.y); */ if (state->map[(int)rstate.map_pos.y][(int)rstate.map_pos.x] == CELL_WALL) break ; + /* printf("3\n"); */ } + /* printf("[%d %d]\n", (int)rstate.map_pos.x, (int)rstate.map_pos.y); */ rstate_line_height(state, &rstate); + /* printf("perp dist %f\n", rstate_perp_dist(state, &rstate)); */ + printf("line height %d\n", rstate.line_height); + rstate.draw_start = WINDOW_MID_HEIGHT(state) - rstate.line_height / 2; + rstate.draw_end = WINDOW_MID_HEIGHT(state) + rstate.line_height / 2; + printf("%d -> %d\n", rstate.draw_start, rstate.draw_end); render_window_column(state, &rstate); - // WINDOW_MID_HEIGHT(state) - line_height / 2 - // WINDOW_MID_HEIGHT(state) + line_height / 2 } void render_window_column(t_state *state, t_render_state *rstate) { int i; t_color white; + t_color black; white.hexcode = 0x00ffffff; + black.hexcode = 0x00000000; i = -1; - /* while (++i < draw_start) */ + while (++i < rstate->draw_start) + ((t_color*)state->window.data)[i * state->window.width + rstate->x] = black; + while (++i < rstate->draw_end) + ((t_color*)state->window.data)[i * state->window.width + rstate->x] = white; + while (++i < state->window_height) + ((t_color*)state->window.data)[i * state->window.width + rstate->x] = black; + + /* printf("%d -> %d\n", rstate->draw_start, rstate->draw_end); */ + /* while (++i < rstate->draw_start) */ /* ((t_color*)state->window.data)[i * state->window.width + rstate->x] = */ /* state->ceilling_color; */ + /* i = rstate->draw_end; */ /* i = render_texture(state, rstate); */ /* while (++i < state->window_height) */ /* ((t_color*)state->window.data)[i * state->window.width + rstate->x] = */ |
