// __author__ = Juan Carlos De Abreu (jcabreur@gmail.com)

/**
 * TODO(jcabreur): write a general comment here
 * Define the information about a plane ...
 */

#ifndef MATH_PLANE_H__
#define MATH_PLANE_H__

#include "../../global.h"
#include "../Vector.h"

BEGIN_TEG_NAMESPACE();

namespace math {

// Simple defines to represent the state of something tested on the plane.
#define ON_PLANE     1
#define FRONT_PLANE  2
#define BEHIND_PLANE 3

// Definition of the ecuation of a plane
class Plane {
public:
	// Attributes
	union {
		struct { float a, b, c, d; };
		float values[4];
	};

	// Constructor
	Plane();
	Plane(const Vec3f& n, const float& d_);
	Plane(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3);
	Plane(const float& a_, const float& b_, const float& c_, const float& d_);

	// Destructor
	~Plane();

	// Operators
	void operator = (const Plane& p);

	// Methods
	float module();
	void normalize();
	void setPlaneNormal(float A, float B, float C);
	void setPlaneIntercept(float D);
	int ClassifyPoint(Vec3f v);
};

float distance(const Plane& p, const Vec3f& v);

Plane Lerp(Plane p1, Plane p2, float amount);
Plane createPlaneFromTri(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3);
bool Intersect(Plane p1, Plane p2, Plane p3, Vec3f &intersectPoint);

};	// Namespace math

END_TEG_NAMESPACE();

#endif  // MATH_PLANE_H__
