#include "cylinder.h"

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

		Cylinder::Cylinder(const MeshParam& params,const FLOAT Radius1, const FLOAT Radius2, const FLOAT Length, const UINT Slices, const UINT Stacks, const std::string& name) : Mesh(params, name)
		{
			this->Radius1 = Radius1;
			this->Radius2 = Radius2;
			this->Length = Length;
			this->Slices = Slices;
			this->Stacks = Stacks;
		}

		Cylinder& Cylinder::resize(const FLOAT Radius1, const FLOAT Radius2, const FLOAT Length, const UINT Slices, const UINT Stacks)
		{
			this->Radius1 = Radius1;
			this->Radius2 = Radius2;
			this->Length = Length;
			this->Slices = Slices;
			this->Stacks = Stacks;

			return *this;
		}

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

		//Create is called automatically when a device is set
			//With no parameters, create should generate a default sized version
		item& Cylinder::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);
			
			D3DXCreateCylinder(_device, Radius1, Radius2, Length, Slices, Stacks, &_mesh, 0);
			_subsets = 1;

			return *this;
		}
	}
}