#include "stdio.h"
#include "Collisions.h"

//////////////////////////////////////////////////////////////
// cCollision class functions
//////////////////////////////////////////////////////////////
cCollision::cCollision()
{
	m_NumObjects = 0;
	m_Objects = NULL;
}

cCollision::~cCollision()
{
	Free();
}

void cCollision::Free()
{
	// Delete linked list of objects
	delete m_Objects; m_Objects = NULL;
	m_NumObjects = 0;
}

void cCollision::AddSphere(D3DXVECTOR3 *vecPos, float Radius)
{
	// Allocate a new object
	cCollisionObject *Sphere = new cCollisionObject();

	// Set sphere data
	Sphere->m_Type = COLLISION_SPHERE;
	Sphere->m_vecPos = (*vecPos);
	Sphere->m_Radius = Radius;

	// Link sphere into list and increase count
	Sphere->m_Next = m_Objects;
	m_Objects = Sphere;
	m_NumObjects++;
}

void cCollision::AddPlane(D3DXPLANE *PlaneParam)
{
	// Allocate a new object
	cCollisionObject *Plane = new cCollisionObject();

	// Set plane data
	Plane->m_Type = COLLISION_PLANE;
	Plane->m_Plane = (*PlaneParam);

	// Link plane into list and increase count
	Plane->m_Next = m_Objects;
	m_Objects = Plane;
	m_NumObjects++;
}

void cCollision::AddCylinder(D3DXVECTOR3 vecPosStart, D3DXVECTOR3 vecPosEnd, float Radius)
{
	// Allocate a new object
	cCollisionObject *Cylinder = new cCollisionObject();

	// Set Cylinder data
	Cylinder->m_Type = COLLISION_CYLINDER;
	Cylinder->m_vecPosStart = vecPosStart;
	Cylinder->m_vecPosEnd = vecPosEnd;
	Cylinder->m_CylinderRadius = Radius;

	// Link Cylinder into list and increase count
	Cylinder->m_Next = m_Objects;
	m_Objects = Cylinder;
	m_NumObjects++;
}
