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

#include "math_matrix.h"
#include "math_vector3D.h"
#include "project_screen.h"
#include "part_volume0.h"
#include "part_opencl0.h"
#include "data_volumes.h"
#include "project_opencl.h"
#include "project_controls.h"

bool volume0_init = false;

const int voldat0_num = VOL_PLASMA1;

vol_control vctrl0;

void volume0_init_frame()
{
	SetVctrl(&vctrl0);
}

void volume0_precalcs()
{
	opencl_example0_init(volumes[voldat0_num]);
	opencl_example0_load_volume(volumes[voldat0_num]);

	vctrl0.iso_surf = volumes[voldat0_num]->GetIsoDepth();

	vctrl0.cam_zoom = 2.0f;
	vctrl0.rot_vecs.x = vctrl0.rot_vecs.y = vctrl0.rot_vecs.z = 0;

    volume0_init = true;
}


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

	Cvector pos = Cvector(0, 0, vctrl0.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[voldat0_num]->SetIsoDepth(vctrl0.iso_surf);

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

void volume0_run(int ptime)
{
	if (!volume0_init) volume0_precalcs();

	volume0_init_frame();
	DrawVolume0(ptime);
}
