#include <math.h>
#include <stdio.h>

#include "project_screen.h"
#include "project_opencl.h"
#include "project_controls.h"
#include "project_colors.h"

#include "math_matrix.h"
#include "math_vector3D.h"

#include "part_volume1.h"
#include "part_opencl1.h"
#include "data_volumes.h"

#include "fx_plasma.h"

bool volume1_init = false;

const int voldat1_num = VOL_FX;

vol_control vctrl1;

unsigned int vcols1[256];

void volume1_init_frame()
{
	SetVctrl(&vctrl1);
}

void volume1_make_colors()
{
	get_fx_plasma_cols(vcols1);
}

void volume1_precalcs()
{
	opencl_example1_init(volumes[voldat1_num]);
	opencl_example1_load_volume(volumes[voldat1_num]);

	volume1_make_colors();
	opencl_example1_load_colors(vcols1);


	vctrl1.iso_surf = volumes[voldat1_num]->GetIsoDepth();

	vctrl1.cam_zoom = 1.5f;
	vctrl1.rot_vecs.x = vctrl1.rot_vecs.y = vctrl1.rot_vecs.z = 0;

    volume1_init = true;
}


void DrawVolume1(int ptime)
{
	Cmatrix rot_matrix;
	rot_matrix.set_rot_matrix(vctrl1.rot_vecs.x, vctrl1.rot_vecs.y, vctrl1.rot_vecs.z);

	Cvector pos = Cvector(0, 0, vctrl1.cam_zoom);
	Cvector dir = Cvector(0, 0, -1);
	Cvector up = Cvector(0, 1, 0);
	Cvector right = Cvector(1, 0, 0);

	pos = rot_matrix.mul_vec(pos);
	dir = rot_matrix.mul_vec(dir);
	up = rot_matrix.mul_vec(up);
	right = rot_matrix.mul_vec(right);

	volumes[voldat1_num]->SetIsoDepth(vctrl1.iso_surf);

	unsigned int *gfx = opencl_example1_run(pos, dir, up, right, volumes[voldat1_num]->GetWidth(), vctrl1.iso_surf, ptime);
	RenderScreen(gfx);
}

void volume1_run(int ptime)
{
	if (!volume1_init) volume1_precalcs();

	volume1_init_frame();
	DrawVolume1(ptime);
}
