@Override public void init() { int len = text.length(); TFloatList verticles = new TFloatArrayList(12 * len); TFloatList textCoords = new TFloatArrayList(8 * len); TIntList indices = new TIntArrayList(6 * len); float textureWidth = gameFont.getFontTextureWidth(); float position = 0.0f; for (int i = 0; i < len; i++) { Glyph glyph = gameFont.getGlyphs().get(text.charAt(i)); add(verticles, position, 0.0f, 0.0f); add(verticles, position, glyph.getHeight(), 0.0f); add(verticles, glyph.getWidth() + position, glyph.getHeight(), 0.0f); add(verticles, glyph.getWidth() + position, 0.0f, 0.0f); position += glyph.getWidth(); float textCoordX1 = glyph.getX() / textureWidth; float textCoordX2 = (glyph.getX() + glyph.getWidth()) / textureWidth; add(textCoords, textCoordX1, 0.0f); add(textCoords, textCoordX1, 1.0f); add(textCoords, textCoordX2, 1.0f); add(textCoords, textCoordX2, 0.0f); int firstIndice = i * 4; indices.add(firstIndice + 0); indices.add(firstIndice + 1); indices.add(firstIndice + 3); indices.add(firstIndice + 3); indices.add(firstIndice + 1); indices.add(firstIndice + 2); } mesh = new Mesh(verticles.toArray(), textCoords.toArray(), indices.toArray()); mesh.setTextureId(gameFont.getFontTextureId()); }
public GameMapMesh generateMapMesh(GameMap map) { Mesh mesh = new Mesh( true, 25 * map.getSize(), 36 * map.getSize(), new VertexAttribute(VertexAttributes.Usage.Position, 3, "a_position"), new VertexAttribute(VertexAttributes.Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 3, "a_texcoords")); TextureArray textureMap = new TextureArray( "mp09901.bmp", "mp09902.bmp", "mp09903.bmp", "mp09904.bmp", "mp09905.bmp", "mp09906.bmp", "mp09907.bmp", "mp09908.bmp", "mp09991.bmp"); /** Cube vertices */ short[] indices = { 0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 15, 14, 12, 14, 13, 16, 17, 18, 16, 18, 19, 20, 23, 22, 20, 22, 21 }; // F ----- G // /| /| // E ------H | ^ Y Z // | | | | | / // | |B ---|-|C | / // |/ |/ | / // A ------D |------>X TFloatList vertList = new TFloatArrayList(9 * 24 * map.getSize()); TShortList indList = new TShortArrayList(36 * map.getSize()); int i = 0; for (int x = 0; x < map.getWidth(); x++) { for (int y = 0; y < map.getLength(); y++) { Tile t = map.getTile(x, y); if (t == null) continue; float size = 0.5f; Vector3 pta = new Vector3(x - size, 0, y - size); Vector3 ptb = new Vector3(x - size, 0, y + size); Vector3 ptc = new Vector3(x + size, 0, y + size); Vector3 ptd = new Vector3(x + size, 0, y - size); Vector3 pte = new Vector3(x - size, 0.1f * t.heightData.get(Tile.Corner.UPPER_SOUTH_WEST), y - size); Vector3 ptf = new Vector3(x - size, 0.1f * t.heightData.get(Tile.Corner.UPPER_SOUTH_EAST), y + size); Vector3 ptg = new Vector3(x + size, 0.1f * t.heightData.get(Tile.Corner.UPPER_NORTH_EAST), y + size); Vector3 pth = new Vector3(x + size, 0.1f * t.heightData.get(Tile.Corner.UPPER_NORTH_WEST), y - size); Rect2f[] texReg = new Rect2f[5]; texReg[0] = getTextureBounds(t.screenData.get(Tile.Screen.UPPER), textureMap); texReg[1] = getTextureBounds(t.screenData.get(Tile.Screen.SOUTH), textureMap); texReg[2] = getTextureBounds(t.screenData.get(Tile.Screen.NORTH), textureMap); texReg[3] = getTextureBounds(t.screenData.get(Tile.Screen.WEST), textureMap); texReg[4] = getTextureBounds(t.screenData.get(Tile.Screen.EAST), textureMap); int[] texUnits = new int[5]; texUnits[0] = t.screenData.get(Tile.Screen.UPPER).texUnit; texUnits[1] = t.screenData.get(Tile.Screen.SOUTH).texUnit; texUnits[2] = t.screenData.get(Tile.Screen.NORTH).texUnit; texUnits[3] = t.screenData.get(Tile.Screen.WEST).texUnit; texUnits[4] = t.screenData.get(Tile.Screen.EAST).texUnit; float[] verts = { // bottom (-y) pta.x, pta.y, pta.z, 1, 1, 1, 1, 0, 0, 0, ptb.x, ptb.y, ptb.z, 1, 1, 1, 1, 0, 0, 0, ptc.x, ptc.y, ptc.z, 1, 1, 1, 1, 0, 0, 0, ptd.x, ptd.y, ptd.z, 1, 1, 1, 1, 0, 0, 0, // top (+y) pte.x, pte.y, pte.z, 1, 1, 1, 1, texReg[0].minX(), texReg[0].maxY(), texUnits[0], ptf.x, ptf.y, ptf.z, 1, 1, 1, 1, texReg[0].maxX(), texReg[0].maxY(), texUnits[0], ptg.x, ptg.y, ptg.z, 1, 1, 1, 1, texReg[0].maxX(), texReg[0].minY(), texUnits[0], pth.x, pth.y, pth.z, 1, 1, 1, 1, texReg[0].minX(), texReg[0].minY(), texUnits[0], // back (-z) (south) pta.x, pta.y, pta.z, 1, 1, 1, 1, texReg[1].maxX(), texReg[1].maxY(), texUnits[1], pte.x, pte.y, pte.z, 1, 1, 1, 1, texReg[1].maxX(), texReg[1].minY(), texUnits[1], pth.x, pth.y, pth.z, 1, 1, 1, 1, texReg[1].minX(), texReg[1].minY(), texUnits[1], ptd.x, ptd.y, ptd.z, 1, 1, 1, 1, texReg[1].minX(), texReg[1].maxY(), texUnits[1], // front (+z) (north) ptb.x, ptb.y, ptb.z, 1, 1, 1, 1, texReg[2].minX(), texReg[2].maxY(), texUnits[2], ptf.x, ptf.y, ptf.z, 1, 1, 1, 1, texReg[2].minX(), texReg[2].minY(), texUnits[2], ptg.x, ptg.y, ptg.z, 1, 1, 1, 1, texReg[2].maxX(), texReg[2].minY(), texUnits[2], ptc.x, ptc.y, ptc.z, 1, 1, 1, 1, texReg[2].maxX(), texReg[2].maxY(), texUnits[2], // left (-x) (west) pta.x, pta.y, pta.z, 1, 1, 1, 1, texReg[3].minX(), texReg[3].maxY(), texUnits[3], ptb.x, ptb.y, ptb.z, 1, 1, 1, 1, texReg[3].maxX(), texReg[3].maxY(), texUnits[3], ptf.x, ptf.y, ptf.z, 1, 1, 1, 1, texReg[3].maxX(), texReg[3].minY(), texUnits[3], pte.x, pte.y, pte.z, 1, 1, 1, 1, texReg[3].minX(), texReg[3].minY(), texUnits[3], // right (+x) (east) ptd.x, ptd.y, ptd.z, 1, 1, 1, 1, texReg[4].maxX(), texReg[4].maxY(), texUnits[4], ptc.x, ptc.y, ptc.z, 1, 1, 1, 1, texReg[4].minX(), texReg[4].maxY(), texUnits[4], ptg.x, ptg.y, ptg.z, 1, 1, 1, 1, texReg[4].minX(), texReg[4].minY(), texUnits[4], pth.x, pth.y, pth.z, 1, 1, 1, 1, texReg[4].maxX(), texReg[4].minY(), texUnits[4], }; vertList.add(verts); short[] curIndices = new short[indices.length]; for (int j = 0; j < indices.length; j++) { curIndices[j] = (short) (indices[j] + (24 * i)); } indList.add(curIndices); i++; } } mesh.setVertices(vertList.toArray()); mesh.setIndices(indList.toArray()); // textureMap.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); mesh.getVertexAttribute(VertexAttributes.Usage.Position).alias = "a_position"; return new GameMapMesh(mesh, textureMap); }
/** {@inheritDoc} */ public void sort(int fromIndex, int toIndex) { TFloatList tmp = subList(fromIndex, toIndex); float[] vals = tmp.toArray(); Arrays.sort(vals); set(fromIndex, vals); }