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 102 103 104 105 106 107
|
struct bVertex { //resides in bMesh
D3DXVECTOR3 pos;
D3DXVECTOR4 color;
D3DXVECTOR2 texCoord;
bVertex::bVertex() {}
bVertex::bVertex(float x, float y, float z, float r, float g, float b, float a, float u, float v) {
pos = D3DXVECTOR3(x, y, z);
color = D3DXVECTOR4(r, g, b, a);
texCoord = D3DXVECTOR2(u, v);
}
};
struct bMesh { //resides in heap
bVertex* Vertices;
unsigned int* Indices;
unsigned int CountVertex;
unsigned int CountIndex;
unsigned int MaxVertices;
unsigned int MaxIndices;
bMesh::bMesh(unsigned int VertexCount, unsigned int IndexCount) {
Vertices = new bVertex[VertexCount];
Indices = new unsigned int[IndexCount];
MaxVertices = VertexCount;
MaxIndices = IndexCount;
CountVertex = 0;
CountIndex = 0;
}
bMesh::~bMesh() {
delete[] Vertices;
delete[] Indices;
}
bMesh* Clone() {
bMesh* ret = new bMesh(MaxVertices, MaxIndices);
ret->CountIndex = CountIndex;
ret->CountVertex = CountVertex;
ret->Vertices = new bVertex[MaxVertices];
ret->Indices = new unsigned int[MaxIndices];
memcpy(ret->Vertices, Vertices, sizeof(bVertex) * CountVertex);
memcpy(ret->Indices, Indices, sizeof(unsigned int) * CountIndex);
return ret;
}
void AddVertex(bVertex vertex) {
if (CountVertex == MaxVertices) return;
Vertices[CountVertex] = vertex;
CountVertex++;
}
void AddIndex(unsigned int index) {
if (CountIndex == MaxIndices) return;
Indices[CountIndex] = index;
CountIndex++;
}
};
struct bMeshInstance { //resides in bCollection
bMesh* pIn;
bMesh* pOut;
bMeshInstance::bMeshInstance() {}
bMeshInstance::bMeshInstance(bMesh* base) {
pIn = base;
pOut = pIn->Clone();
}
bMeshInstance::~bMeshInstance() {
delete pOut;
}
};
struct bCollection {
bMeshInstance* Collection;
unsigned int MaxCollection;
unsigned int CountCollection;
unsigned int CountIndex;
bCollection::bCollection(unsigned int size) {
Collection = new bMeshInstance[size];
MaxCollection = size;
CountCollection = 0;
CountIndex = 0;
}
bCollection::~bCollection() {
delete[] Collection;
}
void AddInstance(bMesh* pMesh) {
if (MaxCollection == CountCollection) return;
Collection[CountCollection] = bMeshInstance(pMesh);
CountCollection++;
CountIndex += pMesh->CountIndex;
}
void* DumpVertices(void* dest) { //returns new start position for further dumps
unsigned int Copied = 0;
void* To = dest;
for (int i = 0; i < CountCollection; i++) {
memcpy(To, Collection[i].pOut->Vertices, Collection[i].pOut->CountVertex);
Copied += Collection[i].pOut->CountVertex;
To = (void*)((unsigned int)dest + Copied * sizeof(bVertex));
}
return To;
}
void* DumpIndices(void* dest) { //returns new start position for further dumps
unsigned int Copied = 0;
void* To = dest;
for (int i = 0; i < CountCollection; i++) {
memcpy(To, Collection[i].pOut->Indices, Collection[i].pOut->CountIndex);
Copied += Collection[i].pOut->CountIndex;
To = (void*)((unsigned int)dest + Copied * sizeof(unsigned int));
}
return To;
}
};
| |