#include "Model.h"
#include "Camera.h"


void Model::setName(string _name)
{
	name = _name;
}

string Model::getName()
{
	return name;
}

void Model::setBoundingSphere(float* bsCenter,float bsRadius)
{
	bs.center = bsCenter;
	bs.radius = bsRadius;
}

void Model::addGeometry(PosGeometry* geometry,PosMaterial *material)
{
	geometries.insert(pair<Geometry*,Material*>(dynamic_cast<Geometry*>(geometry),dynamic_cast<Material*>(material)));
}

BoundingSphere Model::getBoundingSphere()
{
	return bs;
}

void Model::render(Effect* effect, ID3D10EffectPass* pass)
{
	for (GeometryMap::iterator it = geometries.begin(); it!=geometries.end(); ++it)
	{
			(*it).second->sendToEffect(effect);
			pass->Apply( 0 );
			(*it).first->render(pass);
	}
}

void Model::createVBOs(ID3D10Effect* effect)
{
	for (GeometryMap::iterator it = geometries.begin(); it!=geometries.end(); ++it)
	{
			(*it).first->createVBO(effect);
	}
}

Model::~Model()
{
	geometries.clear();
}