#include "sphere.h"

namespace CBK
{
	namespace Shapes
	{
		Sphere::Sphere(const MeshParam& params, const std::string& name) : Mesh(params, name)
		{
			Radius = 1.0f;
			Slices = 20;
			Stacks = 20;
		}

		Sphere::Sphere(const MeshParam& params, const FLOAT Radius, const UINT Slices, const UINT Stacks, const std::string& name) : Mesh(params, name)
		{
			this->Radius = Radius;
			this->Slices = Slices;
			this->Stacks = Stacks;
		}

		Sphere& Sphere::resize(const FLOAT Radius, const UINT Slices, const UINT Stacks)
		{
			this->Radius = Radius;
			this->Slices = Slices;
			this->Stacks = Stacks;

			return *this;
		}

		item& Sphere::load(const std::string& name, const MeshParam& params)
		{
			if (params.device != 0)
				_device = params.device;
			if (_device == 0) return *this;
			if (_mesh != 0) d3d::Release<ID3DXMesh*>(_mesh);
			
			D3DXCreateSphere(_device, Radius, Slices, Stacks, &_mesh, 0);
			_subsets = 1;
			_yOffset = 10.0f;

			return *this;
		}

		//Clean up
		Sphere::~Sphere(void)
		{
		}
	}
}