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