#include "AsteroidDestruction.h"

#include "BoundingSphere.h";
#include "Asteroid.h"
#include "AsteroidsField.h"
#include "Material.h"
#include "TextureObject.h"


AsteroidDestruction::AsteroidDestruction(	Asteroid* destroyed, 
											AsteroidsField* field, 
											Material* mat, 
											TextureObject* texture)
{
	this->field = field;
	this->mat = mat;
	this->texture = texture;
	
	float destroyedRadius = destroyed->getRadius(); 

	float volume = 1.3333 * PI * destroyedRadius;

	while(volume > 0)
	{
		float r = ((float) rand / (float) RAND_MAX) * destroyedRadius * 0.5;
		Vec3f p(	((float) rand / (float) RAND_MAX) - 0.5,
					((float) rand / (float) RAND_MAX) - 0.5,
					((float) rand / (float) RAND_MAX) - 0.5);

		Vec3f movingDir = p;
		float movingSpeed = ((float) rand / (float) RAND_MAX) * (SPEED_MAX-SPEED_MIN) + SPEED_MIN;
		p.add(destroyed->getPosition());

		chunks.push_back(new Asteroid(r,p,mat));
		chunks[chunks.size()-1]->setMovingDirection(movingDir);
		chunks[chunks.size()-1]->setMovingSpeed(movingSpeed);

		volume -= 1.3333 * PI * r;
	}
}
//-----------------------------------------------------------------------------
AsteroidDestruction::~AsteroidDestruction()
{

}
//-----------------------------------------------------------------------------
void AsteroidDestruction::update()
{
	for(int i = 0; i < chunks.size(); i++)
	{
		chunks[i]->update();
	}
}

void AsteroidDestruction::render()