1 | |
---|
2 | /////////////////////////////////////////////////////////////////////////// |
---|
3 | // |
---|
4 | // Realistic rain real-time simulation program |
---|
5 | // |
---|
6 | // Pierre Rousseau |
---|
7 | // |
---|
8 | /////////////////////////////////////////////////////////////////////////// |
---|
9 | // |
---|
10 | // Definition of the mesh for the particles |
---|
11 | // |
---|
12 | /////////////////////////////////////////////////////////////////////////// |
---|
13 | |
---|
14 | |
---|
15 | #ifndef __HARDWARE_BILLBOARD_LOADER__ |
---|
16 | #define __HARDWARE_BILLBOARD_LOADER__ |
---|
17 | |
---|
18 | |
---|
19 | #include <OgreResource.h> |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | class ManualHardwareBillboardMeshLoader : public ManualResourceLoader |
---|
24 | { |
---|
25 | private : |
---|
26 | String mMaterialName; |
---|
27 | |
---|
28 | public : |
---|
29 | |
---|
30 | ManualHardwareBillboardMeshLoader(String materialName) |
---|
31 | { |
---|
32 | mMaterialName = materialName; |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | void loadResource(Resource *res) |
---|
37 | { |
---|
38 | Mesh* msh = static_cast<Mesh*>(res); |
---|
39 | SubMesh* sm = msh->createSubMesh(); |
---|
40 | sm->useSharedVertices = false; |
---|
41 | sm->vertexData = new VertexData(); |
---|
42 | sm->vertexData->vertexStart = 0; |
---|
43 | sm->vertexData->vertexCount = 4; |
---|
44 | VertexDeclaration* dcl = sm->vertexData->vertexDeclaration; |
---|
45 | size_t offset = 0; |
---|
46 | dcl->addElement(0, offset, VET_FLOAT3, VES_POSITION); |
---|
47 | offset += VertexElement::getTypeSize(VET_FLOAT3); |
---|
48 | dcl->addElement(0, offset, VET_FLOAT4, VES_TEXTURE_COORDINATES); // xy will serve as regular texCoords, zw, for positionning in the texture |
---|
49 | offset += VertexElement::getTypeSize(VET_FLOAT4); |
---|
50 | |
---|
51 | HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(offset, 4, HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
52 | float* pReal = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
53 | |
---|
54 | |
---|
55 | // vertex 0 |
---|
56 | // position |
---|
57 | *pReal++ = 0; |
---|
58 | *pReal++ = 0; |
---|
59 | *pReal++ = 0; |
---|
60 | // uv |
---|
61 | *pReal++ = 1; |
---|
62 | *pReal++ = 0; |
---|
63 | // position texture coordinates |
---|
64 | *pReal++ = 0; |
---|
65 | *pReal++ = 0; |
---|
66 | |
---|
67 | // vertex 1 |
---|
68 | // position |
---|
69 | *pReal++ = 0; |
---|
70 | *pReal++ = 0; |
---|
71 | *pReal++ = 0; |
---|
72 | // uv |
---|
73 | *pReal++ = 0; |
---|
74 | *pReal++ = 0; |
---|
75 | // position texture coordinates |
---|
76 | *pReal++ = 0; |
---|
77 | *pReal++ = 0; |
---|
78 | |
---|
79 | // vertex 2 |
---|
80 | // position |
---|
81 | *pReal++ = 0; |
---|
82 | *pReal++ = 0; |
---|
83 | *pReal++ = 0; |
---|
84 | // uv |
---|
85 | *pReal++ = 0; |
---|
86 | *pReal++ = 1; |
---|
87 | // position texture coordinates |
---|
88 | *pReal++ = 0; |
---|
89 | *pReal++ = 0; |
---|
90 | |
---|
91 | // vertex 3 |
---|
92 | // position |
---|
93 | *pReal++ = 0; |
---|
94 | *pReal++ = 0; |
---|
95 | *pReal++ = 0; |
---|
96 | // uv |
---|
97 | *pReal++ = 1; |
---|
98 | *pReal++ = 1; |
---|
99 | // position texture coordinates |
---|
100 | *pReal++ = 0; |
---|
101 | *pReal++ = 0; |
---|
102 | |
---|
103 | |
---|
104 | vbuf->unlock(); |
---|
105 | |
---|
106 | sm->vertexData->vertexBufferBinding->setBinding(0, vbuf); |
---|
107 | sm->indexData->indexCount = 6; |
---|
108 | sm->indexData->indexBuffer = HardwareBufferManager::getSingleton() |
---|
109 | .createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 6, |
---|
110 | HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
111 | uint16* pI = static_cast<uint16*>( |
---|
112 | sm->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)) |
---|
113 | ; |
---|
114 | |
---|
115 | // we link vertices 0, 1, and 2 |
---|
116 | *pI++ = 0; |
---|
117 | *pI++ = 1; |
---|
118 | *pI++ = 2; |
---|
119 | |
---|
120 | // second triangle : we link vertices 0, 2, and 3 |
---|
121 | *pI++ = 0; |
---|
122 | *pI++ = 2; |
---|
123 | *pI++ = 3; |
---|
124 | |
---|
125 | sm->indexData->indexBuffer->unlock(); |
---|
126 | |
---|
127 | sm->setMaterialName(mMaterialName); |
---|
128 | |
---|
129 | |
---|
130 | msh->_setBounds(AxisAlignedBox(0,0,0,0,0,0), true); |
---|
131 | msh->_setBoundingSphereRadius(1); |
---|
132 | } |
---|
133 | }; |
---|
134 | |
---|
135 | |
---|
136 | #endif //__HARDWARE_BILLBOARD_LOADER__ |
---|