/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   env.c                                              :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: gbrochar <gbrochar@student.42.fr>          +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/12/22 18:56:21 by gbrochar          #+#    #+#             */
/*   Updated: 2020/12/26 09:37:56 by gbrochar         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "scop.h"

void			free_env(t_env *e)
{
	free(e->file_name);
	free(e->object.vertices.data);
	free(e->object.uvs.data);
	free(e->object.normals.data);
	free(e->object.vertices_indices.data);
	free(e->object.uvs_indices.data);
	free(e->object.normals_indices.data);
}

void			init_window(t_env *e)
{
	e->window.width = 640;
	e->window.height = 480;
}

void			init_camera(t_env *e)
{
	e->camera.fov = 45;
	e->camera.near = 0.001;
	e->camera.far = 1000;
	e->camera.aspect = 1;
}

void			init_object(t_env *e)
{
	e->object.vertices.data = (double *)malloc(sizeof(double) * BUFFER_SIZE);
	e->object.uvs.data = (double *)malloc(sizeof(double) * BUFFER_SIZE);
	e->object.normals.data = (double *)malloc(sizeof(double) * BUFFER_SIZE);
	e->object.vertices_indices.data = (unsigned int *)malloc(
		sizeof(unsigned int) * BUFFER_SIZE);
	e->object.uvs_indices.data = (unsigned int *)malloc(
		sizeof(unsigned int) * BUFFER_SIZE);
	e->object.normals_indices.data = (unsigned int *)malloc(
		sizeof(unsigned int) * BUFFER_SIZE);
	e->object.vertices.ptr = 0;
	e->object.uvs.ptr = 0;
	e->object.normals.ptr = 0;
	e->object.vertices_indices.ptr = 0;
	e->object.uvs_indices.ptr = 0;
	e->object.normals_indices.ptr = 0;
	e->object.vertices.len = BUFFER_SIZE;
	e->object.uvs.len = BUFFER_SIZE;
	e->object.normals.len = BUFFER_SIZE;
	e->object.vertices_indices.len = BUFFER_SIZE;
	e->object.uvs_indices.len = BUFFER_SIZE;
	e->object.normals_indices.len = BUFFER_SIZE;
}

void			init_transformations(t_env *e)
{
	e->translate.x = 0;
	e->translate.y = 0;
	e->translate.z = 0;
	e->rotate.x = 0;
	e->rotate.y = 0;
	e->rotate.z = 0;
	e->scale.x = 1;
	e->scale.y = 1;
	e->scale.z = 1;
}

void			init_env(t_env *e)
{
	init_window(e);
	init_camera(e);
	init_object(e);
	init_transformations(e);
}

