// Author : Chris Tolley
// Date   : 3/9/2004
// viewFrustum.h contains the class declaration for a view frustum
// class to be used with OpenGL.  The view frustum is the thing in OpenGL that
// is the area that can be seen on the screen by the camera.

#if !defined(AFX_VIEWFRUSTUM_H__55883BBE_93F7_4588_AC34_5B2D91CD0E9C__INCLUDED_)
#define AFX_VIEWFRUSTUM_H__55883BBE_93F7_4588_AC34_5B2D91CD0E9C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class viewFrustum  
{
public:
	// Destructor
	virtual ~viewFrustum();

	// Calculates the view frustum.  This is best called at the end of the
	// camera's update function.
	static void calculateFrustum();

	// These functions return true if the point is inside the view frustum.
	static bool isInFrustum( const float x, const float y, const float z );
	static bool isInFrustum( const float point[3] );

	// These functions return true if the sphere is at least partly inside 
	// the view frustum.  The sphere is made up of a center point and a
	// radius point.  The radius point can be any point on the sphere, I just
	// need it to calculate the distance from the center point.
	static bool sphereInFrustum( const float cx, const float cy, const float cz,
						  const float rx, const float ry, const float rz );
	static bool sphereInFrustum( const float center[3], const float radius[3] );


	// Returns the distance from the near plane of the view frustum. In
	// other words, this function returns the distance of a point from 
	// the camera.
	static float distanceFromNear( const float point[3] );
	static float distanceFromNear( const float x, 
								   const float y, const float z );
private:
	// The frustum data
	static float frustum_[6][4];

	// Constructor, private cause we never actually need an instance of it.
	viewFrustum();

	// Multiplies two matricies.  A matrix in this case is a 16 element array
	// of floats.  Stores the product of one and two in result.  I am writing 
	// this so that I will not need to depend on an implementation 
	// of a matrix class
	static void matrixMultiply( float* one, float* two, float* result );
};

#endif
