/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   pixel.c                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: bszilas <bszilas@student.42vienna.com>     +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/09/12 17:44:38 by vvobis            #+#    #+#             */
/*   Updated: 2025/05/31 13:05:44 by victor           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "../../minirt.h"

void    set_pixel_distances(t_pixel *array, uint size, double dist)
{
    uint    i;

    i = 0;
    while (i < size)
    {
        array[i].dist = dist;
        i++;
    }
}

void    pixels_clear(t_pixel *pixel, uint wi, uint hi)
{
    uint    x;
    uint    y;

    y = 0;
    while (y < hi)
    {
        x = 0;
        while (x < wi)
        {
            pixel[y * data.scene.w + x].id = 0;
            *pixel[y * data.scene.w + x].color = uint_to_color(0x0);
            pixel[y * data.scene.w + x].dist = -1;
            x++;
        }
        y++;
    }
}

t_pixel    *pixel_plane_create(void)
{
    t_pixel    *pixels;

    pixels = ft_calloc(data.scene.h * data.scene.w, sizeof(*pixels));
    lst_memory(pixels, free, ADD);
    set_pixel_distances(pixels, data.scene.w * data.scene.h, -1);
    return (pixels);
}

void    pixel_fill(t_pixel *pixel, t_scene *scene)
{
    uint    i;
    uint    j;
    t_pixel    pixel_new;

    i = 0;
    pixel_new = *pixel;
    while (i < scene->resolution_y)
    {
        j = 0;
        while (j < scene->resolution_x)
        {
            *pixel[i * data.scene.w + j].color = *pixel_new.color;
            pixel[i * data.scene.w + j].id = pixel_new.id;
            pixel[i * data.scene.w + j].dist = pixel_new.dist;
            j++;
        }
        i++;
    }
}

void    set_info_to_pixel(t_pixel *pixel, t_body *body, double dist)
{
    pixel->id = body->id;
    pixel->dist = dist;
    pixel->surface_smoothness = body->surface_smoothness;
}
