#pragma once

#include <d3dx9.h>

struct Vertex
{
 D3DXVECTOR3 position;
 D3DXVECTOR3 normal;
 DWORD color;
 float u,v; 

 static const DWORD FVF;
};

struct BasicVertex
{
 float x,y,z; 

};

interface ObjectModel
{
public:
	//Calculations
	virtual D3DXVECTOR3 ObjectCenter() = 0;
	virtual double ObjectSpeed() = 0;
};

interface IRenderable
{
public:
	//Calculations
	virtual void Render() = 0;
};


class C3DObject : ObjectModel,IRenderable
{
protected:
	IDirect3DDevice9* device;
	IDirect3DVertexBuffer9* VB;  //Vertex Buffer
	IDirect3DIndexBuffer9* IB;   //Indecies Buffer

	long vertex_count;
	long faces_count;   

	void CopyFrom(C3DObject &inst);

public:
	C3DObject(IDirect3DDevice9* device);
	C3DObject(C3DObject &inst);

	void LoadFromFile (char *filename);
	virtual void Render();
	
	//Transformation
	void Translate(float x, float y, float z);
	void Scale(float sx, float sy, float sz);
	void Rotate(float ax, float ay, float az);
	//Calculations
	virtual D3DXVECTOR3 ObjectCenter();
	//Функции возвращают точки главной диагонали
	D3DXVECTOR3 getBack();
	D3DXVECTOR3 getFront();

	virtual IDirect3DVertexBuffer9 * getVertexBuffer();
	virtual DWORD getVertexCount();
	virtual DWORD getBytesPerVertex();
	virtual double ObjectSpeed();
public:
	~C3DObject(void);

friend class CGround;
};


void DrawLine(IDirect3DDevice9* device, D3DXVECTOR3 a, D3DXVECTOR3 b);
