#include "structures.h"
#include "m3derror.h"
#include <math.h>
#include <stdio.h>
M3D::CameraParams::CameraParams ( float f, float zn, float zf, float asp ) : fov_y ( f*GRAD2RAD ), z_near ( zn ), z_far ( zf ), aspect ( asp )
{
	char buf[10];
	if ( z_far <= 0.0 )
	{
		snprintf ( buf, 10, "%f", z_far );
		THROW ( std::string("z_far too small") + buf );
	}
	if ( z_near <= 0.0 )
	{
		snprintf ( buf, 10, "%f", z_near );
		THROW ( std::string("z_near too small") + buf);
	}
	if ( fov_y <= 0.0 )
	{
		snprintf ( buf, 10, "%f", fov_y );
		THROW ( std::string("fov_y too small") + buf);
	}
	if ( aspect <= 0.0 )
	{
		snprintf ( buf, 10, "%f", aspect );
		THROW ( std::string("aspect too small") + buf);
	}
}
void M3D::CameraParams::set_params( float f, float zn, float zf, float asp )
{
	fov_y  = f*GRAD2RAD;
	z_near = zn;
	z_far = zf;
	aspect = asp;
	char buf[10];
	if ( z_far <= 0.0 )
	{
		snprintf ( buf, 10, "%f", z_far );
		THROW ( std::string("z_far too small") + buf );
	}
	if ( z_near <= 0.0 )
	{
		snprintf ( buf, 10, "%f", z_near );
		THROW ( std::string("z_near too small") + buf);
	}
	if ( fov_y <= 0.0 )
	{
		snprintf ( buf, 10, "%f", fov_y );
		THROW ( std::string("fov_y too small") + buf);
	}
	if ( aspect <= 0.0 )
	{
		snprintf ( buf, 10, "%f", aspect );
		THROW ( std::string("aspect too small") + buf);
	}
}
