#ifndef FRUSTUM_H
#define FRUSTUM_H

#include "Plane.h"
#include "Vector.h"

struct D3DXMATRIX;
struct _D3DVIEWPORT9;
struct D3DXVECTOR3;
typedef _D3DVIEWPORT9 D3DVIEWPORT9;
struct IDirect3DDevice9;

namespace cbk
{
	class BoundingBox;

	class Frustum
	{
	public:
		enum Direction
		{
			DIR_Behind = -1,
			DIR_Inside = 0,
			DIR_Front = 1,
		};

		Frustum(const Plane& Left, const Plane& Right, const Plane& Top, const Plane& Bottom, const Plane& Front, const Plane& Back);
		Frustum(const D3DXMATRIX& view, const D3DXMATRIX& proj, const D3DVIEWPORT9& viewPort);

		/*
		Determines if the specified point lies within or without the
		frustrum. A point on the frustrum is inside.
		*/
		const bool isInside(const Vector& p) const;

		/*
		Returns true if any part or all of the bounding box is inside
		the frustrum.
		*/
		const bool isInside(const BoundingBox& b) const;

		/*
		Returns true if any part or all of the bounding box is inside
		the frustrum. The bounding box is scaled by Scale then translated
		by location prior to testing.
		*/
		const bool isInside(const BoundingBox& b, const Vector& location, const float& scale) const;

		/*
		Determines whether the specified plane corss inside the
		frustum. If it does, returns DIR_Inside. If not, it determines
		if the frustrum is in front or behind the plane, and returns the
		proper Direction enum.
		*/
		const Direction isInside(const Plane& p) const;

	protected:

	private:
		Plane left;
		Plane right;
		Plane top;
		Plane bottom;
		Plane front;
		Plane back;

		Vector p[8];
	};
}

#endif //FRUSTUM_H