/////////////////////////////////////////////////////////////////////////// // // Realistic rain real-time simulation program // // Pierre Rousseau // /////////////////////////////////////////////////////////////////////////// // // Definition of the mesh for the particles // /////////////////////////////////////////////////////////////////////////// #ifndef __HARDWARE_BILLBOARD_LOADER__ #define __HARDWARE_BILLBOARD_LOADER__ #include class ManualHardwareBillboardMeshLoader : public ManualResourceLoader { private : String mMaterialName; public : ManualHardwareBillboardMeshLoader(String materialName) { mMaterialName = materialName; } void loadResource(Resource *res) { Mesh* msh = static_cast(res); SubMesh* sm = msh->createSubMesh(); sm->useSharedVertices = false; sm->vertexData = new VertexData(); sm->vertexData->vertexStart = 0; sm->vertexData->vertexCount = 4; VertexDeclaration* dcl = sm->vertexData->vertexDeclaration; size_t offset = 0; dcl->addElement(0, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); dcl->addElement(0, offset, VET_FLOAT4, VES_TEXTURE_COORDINATES); // xy will serve as regular texCoords, zw, for positionning in the texture offset += VertexElement::getTypeSize(VET_FLOAT4); HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(offset, 4, HardwareBuffer::HBU_STATIC_WRITE_ONLY); float* pReal = static_cast(vbuf->lock(HardwareBuffer::HBL_DISCARD)); // vertex 0 // position *pReal++ = 0; *pReal++ = 0; *pReal++ = 0; // uv *pReal++ = 1; *pReal++ = 0; // position texture coordinates *pReal++ = 0; *pReal++ = 0; // vertex 1 // position *pReal++ = 0; *pReal++ = 0; *pReal++ = 0; // uv *pReal++ = 0; *pReal++ = 0; // position texture coordinates *pReal++ = 0; *pReal++ = 0; // vertex 2 // position *pReal++ = 0; *pReal++ = 0; *pReal++ = 0; // uv *pReal++ = 0; *pReal++ = 1; // position texture coordinates *pReal++ = 0; *pReal++ = 0; // vertex 3 // position *pReal++ = 0; *pReal++ = 0; *pReal++ = 0; // uv *pReal++ = 1; *pReal++ = 1; // position texture coordinates *pReal++ = 0; *pReal++ = 0; vbuf->unlock(); sm->vertexData->vertexBufferBinding->setBinding(0, vbuf); sm->indexData->indexCount = 6; sm->indexData->indexBuffer = HardwareBufferManager::getSingleton() .createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 6, HardwareBuffer::HBU_STATIC_WRITE_ONLY); uint16* pI = static_cast( sm->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)) ; // we link vertices 0, 1, and 2 *pI++ = 0; *pI++ = 1; *pI++ = 2; // second triangle : we link vertices 0, 2, and 3 *pI++ = 0; *pI++ = 2; *pI++ = 3; sm->indexData->indexBuffer->unlock(); sm->setMaterialName(mMaterialName); msh->_setBounds(AxisAlignedBox(0,0,0,0,0,0), true); msh->_setBoundingSphereRadius(1); } }; #endif //__HARDWARE_BILLBOARD_LOADER__