#include "ItemViewer.h"
#include "streams\ErrorStream.h"

extern ExceptionStream< ostream&, ContinueFunctor  >		KODIAK_WARNING;

void ItemViewer::simulate( float dt )
{
	for ( int i=0; i< this->models.size(); ++i)
	{
		this->models[i].rotate( this->rotationSpeed[0], this->rotationSpeed[1], this->rotationSpeed[2] );
	}

	for ( int i=0; i< this->lights.size(); ++i)
	{
		//FIXME: implementation required
	}
}
void ItemViewer::render( void )
{
	vector<Model*> modelPtrs;

	if ( this->models.empty() )
	{
		KODIAK_WARNING<<"ItemViewer::render: No model to render!";
	}

	for ( int i=0; i< this->models.size(); ++i)
	{
		modelPtrs.push_back( &this->models[i] );
	}

	assert( this->lights.size() <= 2 && "Too much lights for cg shader for Ati cards" );
	
	this->modelViewer.renderModels( this->renderer, this->lights.getLightArray(), modelPtrs );
}
void ItemViewer::handleKeyboard( Keyboard &keyboard )
{
	this->modelViewer.handleKeyboard( keyboard );
}
void ItemViewer::handleMouse( Mouse &mouse )
{
	this->modelViewer.handleMouse( mouse );
}
ItemViewer::ItemViewer( GLPhongRender &render ):renderer(render)
{
	for ( int i=0; i<3; ++i)
	{
		this->rotationSpeed[i] = 0.0;
	}

	this->modelViewer.observerData.nearCameraLimit= 16;
	this->modelViewer.observerData.farCameraLimit= 40;
}