| 8 | { |
| 9 | |
| 10 | void SpriteSheetLoader::initializePolygonInfo(const Vec2& textureSize, |
| 11 | const Vec2& spriteSize, |
| 12 | const std::vector<int>& vertices, |
| 13 | const std::vector<int>& verticesUV, |
| 14 | const std::vector<int>& triangleIndices, |
| 15 | PolygonInfo& info) |
| 16 | { |
| 17 | const auto vertexCount = vertices.size(); |
| 18 | const auto indexCount = triangleIndices.size(); |
| 19 | |
| 20 | const auto scaleFactor = AX_CONTENT_SCALE_FACTOR(); |
| 21 | |
| 22 | auto* vertexData = new V3F_C4B_T2F[vertexCount]; |
| 23 | for (size_t i = 0; i < vertexCount / 2; i++) |
| 24 | { |
| 25 | vertexData[i].colors = Color4B::WHITE; |
| 26 | vertexData[i].vertices = |
| 27 | Vec3(vertices[i * 2] / scaleFactor, (spriteSize.height - vertices[i * 2 + 1]) / scaleFactor, 0); |
| 28 | vertexData[i].texCoords = |
| 29 | Tex2F(verticesUV[i * 2] / textureSize.width, verticesUV[i * 2 + 1] / textureSize.height); |
| 30 | } |
| 31 | |
| 32 | auto* indexData = new unsigned short[indexCount]; |
| 33 | for (size_t i = 0; i < indexCount; i++) |
| 34 | { |
| 35 | indexData[i] = static_cast<unsigned short>(triangleIndices[i]); |
| 36 | } |
| 37 | |
| 38 | info.triangles.vertCount = static_cast<int>(vertexCount); |
| 39 | info.triangles.verts = vertexData; |
| 40 | info.triangles.indexCount = static_cast<int>(indexCount); |
| 41 | info.triangles.indices = indexData; |
| 42 | info.setRect(Rect(0, 0, spriteSize.width, spriteSize.height)); |
| 43 | } |
| 44 | |
| 45 | } |