1 | #pragma once
|
---|
2 |
|
---|
3 | class FlexVertex
|
---|
4 | {
|
---|
5 | static unsigned int posByteOffset;
|
---|
6 | static unsigned int normalByteOffset;
|
---|
7 | static unsigned int diffuseByteOffset;
|
---|
8 | static unsigned int specularByteOffset;
|
---|
9 | static unsigned int texByteOffset[16];
|
---|
10 | static unsigned int nTex;
|
---|
11 | public:
|
---|
12 | static void setFormat(D3DVERTEXELEMENT9* decl);
|
---|
13 |
|
---|
14 | D3DXVECTOR3& pos()
|
---|
15 | {
|
---|
16 | return *(D3DXVECTOR3*)(((char*)this) + posByteOffset);
|
---|
17 | }
|
---|
18 | D3DXVECTOR3& normal()
|
---|
19 | {
|
---|
20 | return *(D3DXVECTOR3*)(((char*)this) + normalByteOffset);
|
---|
21 | }
|
---|
22 | D3DXVECTOR2& tex0()
|
---|
23 | {
|
---|
24 | return *(D3DXVECTOR2*)(((char*)this) + texByteOffset[0]);
|
---|
25 | }
|
---|
26 | D3DXVECTOR2& tex1()
|
---|
27 | {
|
---|
28 | return *(D3DXVECTOR2*)(((char*)this) + texByteOffset[1]);
|
---|
29 | }
|
---|
30 | D3DXVECTOR2& tex(unsigned int i)
|
---|
31 | {
|
---|
32 | return *(D3DXVECTOR2*)(((char*)this) + texByteOffset[i]);
|
---|
33 | }
|
---|
34 | D3DCOLOR& diffuse()
|
---|
35 | {
|
---|
36 | return *(D3DCOLOR*)(((char*)this) + diffuseByteOffset);
|
---|
37 | }
|
---|
38 | D3DCOLOR& specular()
|
---|
39 | {
|
---|
40 | return *(D3DCOLOR*)(((char*)this) + specularByteOffset);
|
---|
41 | }
|
---|
42 |
|
---|
43 | void operator=(const FlexVertex& o)
|
---|
44 | {
|
---|
45 | bool kamu = false; // use FlexVertexArray.assign to copy data
|
---|
46 | }
|
---|
47 | };
|
---|
48 |
|
---|
49 | class FlexVertexArray
|
---|
50 | {
|
---|
51 | unsigned int nBytesPerVertex;
|
---|
52 | public:
|
---|
53 |
|
---|
54 | FlexVertex* arrayStart;
|
---|
55 | FlexVertex& operator[](unsigned int index)
|
---|
56 | {
|
---|
57 | return *((FlexVertex*)((char*)arrayStart + nBytesPerVertex * index));
|
---|
58 | }
|
---|
59 |
|
---|
60 | void** getDataPointerReference()
|
---|
61 | {
|
---|
62 | return (void**)&arrayStart;
|
---|
63 | }
|
---|
64 |
|
---|
65 | FlexVertexArray(unsigned int nBytesPerVertex)
|
---|
66 | {
|
---|
67 | this->nBytesPerVertex = nBytesPerVertex;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void assign(unsigned int index, FlexVertex& o)
|
---|
71 | {
|
---|
72 | memcpy(
|
---|
73 | (void**)((char*)arrayStart + nBytesPerVertex * index),
|
---|
74 | &o,
|
---|
75 | nBytesPerVertex);
|
---|
76 | }
|
---|
77 | }; |
---|