#ifndef LIGHTFILELD_H
#define LIGHTFIELD_H

#include <malloc.h>
//--------------------------------------------------------
// Point class
//--------------------------------------------------------
class cPoint
{
public:
	cPoint();
	cPoint(double vX, double vY, double vZ);
	~cPoint(){};

	double X, Y, Z;

	double Distance(const cPoint& p) const;
	bool operator==(cPoint& p) const;
};

//--------------------------------------------------------
// Vector class
//--------------------------------------------------------
class cVector
{
public:
	cVector();
	cVector(const cPoint& p1, const cPoint& p2);
	cVector(double vI, double vJ, double vK);
	~cVector(){};

	double I, J, K;

	cVector Normalize() const; // returns a unit vector of this vector
	double Magnitude() const;
	double DotProd(const cVector& v) const; // returns the dot product of this and rVector
	cVector CrossProd(const cVector& v) const; // returns the cross product of this and rVector
	cVector operator+ (cVector v) const; // returns the sum of two vectors
	cVector operator- (cVector v) const; // returns the difference of two vectors
	cPoint operator+ (cPoint p) const; // returns the sum of a vector and a Point 
	cVector operator* (double s) const; // returns multiplication of a scalar with a vector
	cPoint VectorToPoint() const;	// converts a vector to a point
};

//--------------------------------------------------------
// Image class
//--------------------------------------------------------
class cImage
{
public:
	cImage(){};
	~cImage(){free(data);};

	unsigned char *data;
	void ReadFromFile(const char *fname);
	void ReadFromBMP(const char *fname);
	void ReadFromPPM(const char *fname);
};

//--------------------------------------------------------
// Light Field class
//--------------------------------------------------------
class cLightField
{
public:
	
	cPoint Eye;
	cVector vEye;
	cVector u,v,o,lookAt,upVector;//camera parameters
	double camFOV;
	int camWidth, camHeight;//image size for desired camera
	double dataFocalLength;//distance between st and uv planes dimesnsions
	double desiredFocalLength;//distance between st plane and desired camera

	cImage *images;
	unsigned char *fb;//frame buffer
	int uvWidth,uvHeight;
	int stWidth,stHeight;
	double W2,H2,uvW2,uvH2,stW2,stH2,NdotVE, ST2scene;//precomputed vars
	cVector Normal;//normal on the two planes
	cPoint uvPoint, stPoint;//points on each plane
	double distanceBetweenCameras;
	int imageRowSize;
	int frameNo;

	GLuint stTex, uvTex;
	GLubyte *stImg, *uvImg;

	cLightField(char *filename);
	~cLightField();

	void ComputeImage();
	void SetupCamera();
	void SaveToPPM();
};

#endif
