//#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9mesh.h>
#include <D3dx9tex.h>
#include <math.h>
#include <vector>
#include "d3dx9xof.h"
#include "MeshObject.h"
#include "D3D9Types.h"

#define DIRECTINPUT_VERSION 0x0800
#define POINTS 1000

#include <windows.h>
#include <d3dx9core.h>


class SubdivisionAlgorithm{
private:
	LPD3DXMESH clothes;
	LPD3DXMESH bodyModel;
	MeshObject *body;
	std::vector<float> distancesToBody;
	std::vector<int> pointsForMassSpringSystem;
	float avgDistance;
	float minDistance;
	float maxDistance;
	IDirect3DDevice9 *pDevice;

public:
	MeshObject *animatedClothes;	

private:
	int Compare(const void * a, const void * b);

	int* QSort(int* points, int numOfPoints);

public:
	SubdivisionAlgorithm(MeshObject*, const char*, IDirect3DDevice9*, LPD3DXMESH body, LPD3DXMESH clothes);

	//Subdivide cloths mesh into 3 parts: skinny parts, more loose parts and very loose parts
	void Subdivision();

	//Draw animatedCloths
	void DrawClothes();

	//Get array of points for mass-spring system
	std::vector<int> GetPointsForMassSpringSystem();

};
