Geometry BubbleEmitter::CreateGeometry( unsigned int numOfPatch ) { unsigned int numVertex = numOfPatch*4u; std::vector<Vertex> vertexData; vertexData.reserve( numVertex ); unsigned int numIndex = numOfPatch*6u; Vector<unsigned int> indexData; indexData.Reserve( numIndex ); for(unsigned int i = 0; i < numOfPatch; i++) { float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y, mRandomSeed); float index = static_cast<float>( i ); vertexData.push_back( Vertex( index, Vector2(0.f,0.f), Vector2(0.f,0.f) ) ); vertexData.push_back( Vertex( index, Vector2(0.f,curSize), Vector2(0.f,1.f) ) ); vertexData.push_back( Vertex( index, Vector2(curSize,curSize), Vector2(1.f,1.f) ) ); vertexData.push_back( Vertex( index, Vector2(curSize,0.f), Vector2(1.f,0.f) ) ); unsigned int idx = index * 4; indexData.PushBack( idx ); indexData.PushBack( idx+1 ); indexData.PushBack( idx+2 ); indexData.PushBack( idx ); indexData.PushBack( idx+2 ); indexData.PushBack( idx+3 ); } Property::Map vertexFormat; vertexFormat["aIndex"] = Property::FLOAT; vertexFormat["aPosition"] = Property::VECTOR2; vertexFormat["aTexCoord"] = Property::VECTOR2; PropertyBuffer vertices = PropertyBuffer::New( vertexFormat, numVertex ); vertices.SetData( &vertexData[0] ); Property::Map indexFormat; indexFormat["indices"] = Property::INTEGER; PropertyBuffer indices = PropertyBuffer::New( indexFormat, numIndex ); indices.SetData( &indexData[0] ); Geometry geometry = Geometry::New(); geometry.AddVertexBuffer( vertices ); geometry.SetIndexBuffer( indices ); return geometry; }
/** * @brief Creates a geometry object from vertices and indices. * @param[in] vertices The object vertices * @param[in] indices The object indices * @return A geometry object */ Geometry CreateTexturedGeometry( Vector<TexturedVertex>& vertices, Vector<unsigned short>& indices ) { // Vertices Property::Map vertexFormat; vertexFormat[POSITION] = Property::VECTOR3; vertexFormat[NORMAL] = Property::VECTOR3; vertexFormat[TEXTURE] = Property::VECTOR2; PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat ); surfaceVertices.SetData( &vertices[0u], vertices.Size() ); Geometry geometry = Geometry::New(); geometry.AddVertexBuffer( surfaceVertices ); // Indices for triangle formulation geometry.SetIndexBuffer( &indices[0u], indices.Size() ); return geometry; }
Geometry CreateQuadGeometry(void) { PropertyBuffer vertexData = CreatePropertyBuffer(); const float halfQuadSize = .5f; struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; TexturedQuadVertex texturedQuadVertexData[4] = { { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) }, { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) }, { Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f) }, { Vector2( halfQuadSize, halfQuadSize), Vector2(1.f, 1.f) } }; vertexData.SetData(texturedQuadVertexData, 4); unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 }; Geometry geometry = Geometry::New(); geometry.AddVertexBuffer( vertexData ); geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) ); return geometry; }