// ray class
// contains the rrot finding and illumnination algorithms

#pragma once

struct root {
	double val;
	bool found;
};

class ray
{

private:
	int imgsz;	// image size
	double amb, diff; // ambient and diffuse reflection terms
	vector light; // Light source direction
	int kbr, kbs, knt; // Bracket, Bisection and Newton method iterations
	int nballs; // number of metaballs defined
	double iso; // iso-contour threshold
	metaball* ball; // metaballs
	
public:
	ray(const wchar_t* fname);
	~ray(void) {delete[] ball;}
	double f(double x, double y, double z);
	double fdx(double x, double y, double z);
	double fdy(double x, double y, double z);
	double fdz(double x, double y, double z);
	double nfdx(double x, double y, double z);
	double nfdy(double x, double y, double z);
	double nfdz(double x, double y, double z);
	bool findRoot(double x, double y, double &z);
	double illuminate(double x, double y, double z);
	void writeImg(const wchar_t *fname, System::Windows::Forms::ProgressBar^ progressBar1);
};
