1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#ifndef MODELOBJECT_H
#define MODELOBJECT_H
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <d3d9.h>
#include <d3dx9.h>
#include <string>
#include "structures.h"
void getModel();
using namespace std;
class modelObject
{
public:
D3DXVECTOR3 position;
CUSTOMVERTEX* vertices;
short* indices;
int numVertices;
int numFaces;
IDirect3DTexture9* mFaceTex;
private:
LPDIRECT3DDEVICE9 d3ddev;
IDirect3DVertexBuffer9* vBuffer;
IDirect3DIndexBuffer9* iBuffer;
char* fileName;
char* textureName;
int numV;
int numVT;
int numVN;
int numF;
void getModel()
{
//rather lengthy file reading function, no errors here as I've tested multiple times, removed for ease of reading
}
void initialiseBuffer()
{
d3ddev->CreateVertexBuffer(numVertices*sizeof(CUSTOMVERTEX), 0, 0, D3DPOOL_MANAGED, &vBuffer, NULL);
VOID* pVoid;
vBuffer->Lock(0, 0, (void**)pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
vBuffer->Unlock();
d3ddev->CreateIndexBuffer(numVertices*sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &iBuffer, NULL);
iBuffer->Lock(0, 0, (void**)iBuffer, 0);
memcpy(pVoid, indices, sizeof(indices));
iBuffer->Unlock();
}
public:
modelObject(LPDIRECT3DDEVICE9 dev)
{
d3ddev = dev;
numVertices = 0;
numFaces = 0;
numV = 0;
numVT = 0;
numVN = 0;
numF = 0;
}
modelObject(LPDIRECT3DDEVICE9 dev, D3DXVECTOR3 pos, char* fN, char* tN)
{
d3ddev = dev;
numVertices = 0;
numFaces = 0;
numV = 0;
numVT = 0;
numVN = 0;
numF = 0;
position = pos;
fileName = fN;
D3DXCreateTextureFromFile(d3ddev, tN, &mFaceTex);
getModel();
}
~modelObject()
{
vBuffer->Release();
iBuffer->Release();
delete [] vertices;
delete [] indices;
}
void draw()
{
d3ddev->SetStreamSource(0, vBuffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->SetIndices(iBuffer);
d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, numVertices, 0, numFaces);
}
};
#endif
|