Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/13 move objects #44

Merged
merged 16 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[#40][fix] can disable low resolution rendering
  • Loading branch information
davfront committed Jun 29, 2023
commit 584f79905b382b0f6757d8ba3adec7f419369346
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: dapereir <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/12/14 16:34:41 by dapereir #+# #+# #
# Updated: 2023/06/27 16:07:57 by dapereir ### ########.fr #
# Updated: 2023/06/29 10:53:23 by dapereir ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -95,6 +95,7 @@ SRCS_FILES = \
\
raytracer/rt_get_view_ray.c\
raytracer/rt_draw_frame.c\
raytracer/rt_draw_frame_lowres.c \
raytracer/rt_draw_frame_thread.c \
raytracer/rt_hit_default.c\
raytracer/rt_get_plane_hit.c \
Expand Down
3 changes: 2 additions & 1 deletion include/minirt.h
davfront marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dapereir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/14 16:35:14 by dapereir #+# #+# */
/* Updated: 2023/06/27 16:33:11 by dapereir ### ########.fr */
/* Updated: 2023/06/29 10:53:05 by dapereir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -173,6 +173,7 @@ void rt_help(t_data *data);
// raytracer
t_ray rt_get_view_ray(t_cam cam, int x, int y);
void rt_draw_frame(t_data *data);
void rt_draw_frame_lowres(t_data *data);
void *rt_draw_frame_thread(void *tv);
t_hit rt_hit_default(void);
int rt_get_sphere_hit(t_ray ray, t_obj *obj, t_float t_max, t_hit *hit);
Expand Down
8 changes: 7 additions & 1 deletion src/help/rt_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ static void rt_help_viewer(t_data *data)
{
int line;
int i;
int step_max;

line = 1;
rt_help_label(data, line++, "VIEWER");
line++;
rt_help_label(data, line, "FPS");
rt_help_value_f(data, line++, data->fps, GREEN);
rt_help_label(data, line, "Image quality");
i = (t_float)data->buf_step / (TILE_SIZE * TILE_SIZE - 1) * 100;
i = 100;
if (TILE_SIZE > 1)
{
step_max = TILE_SIZE * TILE_SIZE - 1;
i *= (t_float)data->buf_step / step_max;
}
if (i == 100)
rt_help_value_perc(data, line++, i, GREEN);
else
Expand Down
93 changes: 12 additions & 81 deletions src/raytracer/rt_draw_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,30 @@
/* By: dapereir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/14 16:35:43 by dapereir #+# #+# */
/* Updated: 2023/06/26 16:35:07 by dapereir ### ########.fr */
/* Updated: 2023/06/29 10:51:50 by dapereir ### ########.fr */
/* */
/* ************************************************************************** */

#include "minirt.h"

static void rt_clear_buffer(t_data *data)
{
ft_bzero(data->buf, sizeof(t_buf) * WIN_WIDTH * WIN_HEIGHT);
}

static void rt_cast_rays_to_buffer(t_data *data, int step)
void rt_draw_frame(t_data *data)
{
int tx;
int ty;
int x;
int y;
t_ray ray;

tx = 0;
while (tx < WIN_WIDTH / TILE_SIZE)
{
ty = 0;
while (ty < WIN_HEIGHT / TILE_SIZE)
{
x = tx * TILE_SIZE + step / TILE_SIZE;
y = ty * TILE_SIZE + step % TILE_SIZE;
if (!data->buf[x][y].done)
{
ray = rt_get_view_ray(*data->cam, x, y);
ray.hit = rt_get_closest_hit(data, ray);
data->buf[x][y].color = rt_get_hit_color(data, ray);
data->buf[x][y].done = 1;
}
ty++;
}
tx++;
}
}

void rt_draw_tile(t_data *data, int tx, int ty)
{
int x;
int y;
t_rgb color;

color = rgb(0, 0, 0);
y = ty * TILE_SIZE;
while (y < (ty + 1) * TILE_SIZE && y < WIN_HEIGHT)
x = 0;
while (x < WIN_WIDTH)
{
x = tx * TILE_SIZE;
if (data->buf[x][y].done)
color = data->buf[x][y].color;
while (x < (tx + 1) * TILE_SIZE && x < WIN_WIDTH)
y = 0;
while (y < WIN_HEIGHT)
{
if (data->buf[x][y].done)
color = data->buf[x][y].color;
rt_viewer_draw_pixel(data, x, y, color);
x++;
ray = rt_get_view_ray(*data->cam, x, y);
ray.hit = rt_get_closest_hit(data, ray);
if (ray.hit.obj)
rt_viewer_draw_pixel(data, x, y, rt_get_hit_color(data, ray));
y++;
}
y++;
}
}

void rt_draw_buffer(t_data *data)
{
int tx;
int ty;

tx = 0;
while (tx < WIN_WIDTH / TILE_SIZE)
{
ty = 0;
while (ty < WIN_HEIGHT / TILE_SIZE)
{
rt_draw_tile(data, tx, ty);
ty++;
}
tx++;
}
}

void rt_draw_frame(t_data *data)
{
if (data->ui.changed)
{
data->buf_step = 0;
rt_clear_buffer(data);
x++;
}
if (data->buf_step < TILE_SIZE * TILE_SIZE)
rt_cast_rays_to_buffer(data, data->buf_step);
rt_draw_buffer(data);
if (data->buf_step < TILE_SIZE * TILE_SIZE - 1)
data->buf_step++;
data->ui.changed = 0;
}
104 changes: 104 additions & 0 deletions src/raytracer/rt_draw_frame_lowres.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_draw_frame_lowres.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dapereir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/14 16:35:43 by dapereir #+# #+# */
/* Updated: 2023/06/29 10:51:14 by dapereir ### ########.fr */
/* */
/* ************************************************************************** */

#include "minirt.h"

static void rt_clear_buffer(t_data *data)
{
ft_bzero(data->buf, sizeof(t_buf) * WIN_WIDTH * WIN_HEIGHT);
}

static void rt_cast_rays_to_buffer(t_data *data, int step)
{
int tx;
int ty;
int x;
int y;
t_ray ray;

tx = 0;
while (tx < WIN_WIDTH / TILE_SIZE)
{
ty = 0;
while (ty < WIN_HEIGHT / TILE_SIZE)
{
x = tx * TILE_SIZE + step / TILE_SIZE;
y = ty * TILE_SIZE + step % TILE_SIZE;
if (!data->buf[x][y].done)
{
ray = rt_get_view_ray(*data->cam, x, y);
ray.hit = rt_get_closest_hit(data, ray);
data->buf[x][y].color = rt_get_hit_color(data, ray);
data->buf[x][y].done = 1;
}
ty++;
}
tx++;
}
}

void rt_draw_tile(t_data *data, int tx, int ty)
{
int x;
int y;
t_rgb color;

color = rgb(0, 0, 0);
y = ty * TILE_SIZE;
while (y < (ty + 1) * TILE_SIZE && y < WIN_HEIGHT)
{
x = tx * TILE_SIZE;
if (data->buf[x][y].done)
color = data->buf[x][y].color;
while (x < (tx + 1) * TILE_SIZE && x < WIN_WIDTH)
{
if (data->buf[x][y].done)
color = data->buf[x][y].color;
rt_viewer_draw_pixel(data, x, y, color);
x++;
}
y++;
}
}

void rt_draw_buffer(t_data *data)
{
int tx;
int ty;

tx = 0;
while (tx < WIN_WIDTH / TILE_SIZE)
{
ty = 0;
while (ty < WIN_HEIGHT / TILE_SIZE)
{
rt_draw_tile(data, tx, ty);
ty++;
}
tx++;
}
}

void rt_draw_frame_lowres(t_data *data)
{
if (data->ui.changed)
{
data->buf_step = 0;
rt_clear_buffer(data);
}
if (data->buf_step < TILE_SIZE * TILE_SIZE)
rt_cast_rays_to_buffer(data, data->buf_step);
rt_draw_buffer(data);
if (data->buf_step < TILE_SIZE * TILE_SIZE - 1)
data->buf_step++;
data->ui.changed = 0;
}
6 changes: 4 additions & 2 deletions src/viewer/rt_viewer_thread_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* rt_viewer_thread_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atchougo <atchougo@student.42lyon.fr> +#+ +:+ +#+ */
/* By: dapereir <dapereir@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/21 21:48:55 by atchougo #+# #+# */
/* Updated: 2023/06/21 22:25:37 by atchougo ### ########.fr */
/* Updated: 2023/06/29 10:52:24 by dapereir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,6 +49,8 @@ void rt_viewer_thread_handler(t_data *data)
rt_launch_threads(data);
rt_wait_for_threads(data);
}
else if (TILE_SIZE > 1)
rt_draw_frame_lowres(data);
else
rt_draw_frame(data);
}