#pragma once class FlexFormat { public: unsigned int posByteOffset; unsigned int normalByteOffset; unsigned int diffuseByteOffset; unsigned int specularByteOffset; unsigned int texByteOffset[16]; unsigned int nTex; FlexFormat(); }; class FlexVertex { static FlexFormat* format; public: static void setFormat(FlexFormat* format); D3DXVECTOR3& pos() { return *(D3DXVECTOR3*)(((char*)this) + format->posByteOffset); } D3DXVECTOR3& normal() { return *(D3DXVECTOR3*)(((char*)this) + format->normalByteOffset); } D3DXVECTOR2& tex0() { return *(D3DXVECTOR2*)(((char*)this) + format->texByteOffset[0]); } D3DXVECTOR2& tex1() { return *(D3DXVECTOR2*)(((char*)this) + format->texByteOffset[1]); } D3DXVECTOR2& tex(unsigned int i) { return *(D3DXVECTOR2*)(((char*)this) + format->texByteOffset[i]); } D3DCOLOR& diffuse() { return *(D3DCOLOR*)(((char*)this) + format->diffuseByteOffset); } D3DCOLOR& specular() { return *(D3DCOLOR*)(((char*)this) + format->specularByteOffset); } void operator=(const FlexVertex& o) { bool kamu = false; // use FlexVertexArray.assign to copy data } }; class FlexVertexArray { unsigned int nBytesPerVertex; FlexFormat format; public: void setFormat(D3DVERTEXELEMENT9* decl); FlexVertex* arrayStart; FlexVertex& operator[](unsigned int index) { FlexVertex::setFormat(&format); return *((FlexVertex*)((char*)arrayStart + nBytesPerVertex * index)); } void** getDataPointerReference() { return (void**)&arrayStart; } FlexVertexArray(unsigned int nBytesPerVertex) { this->nBytesPerVertex = nBytesPerVertex; } void assign(unsigned int index, FlexVertex& o) { memcpy( (void**)((char*)arrayStart + nBytesPerVertex * index), &o, nBytesPerVertex); } };