List of usage examples for com.badlogic.gdx.graphics.g2d PolygonRegion getRegion
public TextureRegion getRegion()
From source file:com.esotericsoftware.spine.utils.TwoColorPolygonBatch.java
License:Open Source License
/** Draws a polygon region with the bottom left corner at x,y having the width and height of the region. */ public void draw(PolygonRegion region, float x, float y) { if (!drawing) throw new IllegalStateException("begin must be called before draw."); final short[] triangles = this.triangles; final short[] regionTriangles = region.getTriangles(); final int regionTrianglesLength = regionTriangles.length; final float[] regionVertices = region.getVertices(); final int regionVerticesLength = regionVertices.length; final Texture texture = region.getRegion().getTexture(); if (texture != lastTexture) switchTexture(texture);//from ww w . j a v a2 s .co m else if (triangleIndex + regionTrianglesLength > triangles.length || vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush(); int triangleIndex = this.triangleIndex; int vertexIndex = this.vertexIndex; final int startVertex = vertexIndex / VERTEX_SIZE; for (int i = 0; i < regionTrianglesLength; i++) triangles[triangleIndex++] = (short) (regionTriangles[i] + startVertex); this.triangleIndex = triangleIndex; final float[] vertices = this.vertices; final float light = this.lightPacked; final float dark = this.darkPacked; final float[] textureCoords = region.getTextureCoords(); for (int i = 0; i < regionVerticesLength; i += 2) { vertices[vertexIndex++] = regionVertices[i] + x; vertices[vertexIndex++] = regionVertices[i + 1] + y; vertices[vertexIndex++] = light; vertices[vertexIndex++] = dark; vertices[vertexIndex++] = textureCoords[i]; vertices[vertexIndex++] = textureCoords[i + 1]; } this.vertexIndex = vertexIndex; }
From source file:com.esotericsoftware.spine.utils.TwoColorPolygonBatch.java
License:Open Source License
/** Draws a polygon region with the bottom left corner at x,y and stretching the region to cover the given width and height. */ public void draw(PolygonRegion region, float x, float y, float width, float height) { if (!drawing) throw new IllegalStateException("begin must be called before draw."); final short[] triangles = this.triangles; final short[] regionTriangles = region.getTriangles(); final int regionTrianglesLength = regionTriangles.length; final float[] regionVertices = region.getVertices(); final int regionVerticesLength = regionVertices.length; final TextureRegion textureRegion = region.getRegion(); final Texture texture = textureRegion.getTexture(); if (texture != lastTexture) switchTexture(texture);// ww w . ja v a 2 s . c o m else if (triangleIndex + regionTrianglesLength > triangles.length || vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush(); int triangleIndex = this.triangleIndex; int vertexIndex = this.vertexIndex; final int startVertex = vertexIndex / VERTEX_SIZE; for (int i = 0, n = regionTriangles.length; i < n; i++) triangles[triangleIndex++] = (short) (regionTriangles[i] + startVertex); this.triangleIndex = triangleIndex; final float[] vertices = this.vertices; final float light = this.lightPacked; final float dark = this.darkPacked; final float[] textureCoords = region.getTextureCoords(); final float sX = width / textureRegion.getRegionWidth(); final float sY = height / textureRegion.getRegionHeight(); for (int i = 0; i < regionVerticesLength; i += 2) { vertices[vertexIndex++] = regionVertices[i] * sX + x; vertices[vertexIndex++] = regionVertices[i + 1] * sY + y; vertices[vertexIndex++] = light; vertices[vertexIndex++] = dark; vertices[vertexIndex++] = textureCoords[i]; vertices[vertexIndex++] = textureCoords[i + 1]; } this.vertexIndex = vertexIndex; }
From source file:com.esotericsoftware.spine.utils.TwoColorPolygonBatch.java
License:Open Source License
/** Draws the polygon region with the bottom left corner at x,y and stretching the region to cover the given width and height. * The polygon region is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the * polygon region should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the * rectangle around originX, originY. */ public void draw(PolygonRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { if (!drawing) throw new IllegalStateException("begin must be called before draw."); final short[] triangles = this.triangles; final short[] regionTriangles = region.getTriangles(); final int regionTrianglesLength = regionTriangles.length; final float[] regionVertices = region.getVertices(); final int regionVerticesLength = regionVertices.length; final TextureRegion textureRegion = region.getRegion(); Texture texture = textureRegion.getTexture(); if (texture != lastTexture) switchTexture(texture);/*from w w w . jav a 2s . c o m*/ else if (triangleIndex + regionTrianglesLength > triangles.length || vertexIndex + regionVerticesLength * VERTEX_SIZE / 2 > vertices.length) flush(); int triangleIndex = this.triangleIndex; int vertexIndex = this.vertexIndex; final int startVertex = vertexIndex / VERTEX_SIZE; for (int i = 0; i < regionTrianglesLength; i++) triangles[triangleIndex++] = (short) (regionTriangles[i] + startVertex); this.triangleIndex = triangleIndex; final float[] vertices = this.vertices; final float light = this.lightPacked; final float dark = this.darkPacked; final float[] textureCoords = region.getTextureCoords(); final float worldOriginX = x + originX; final float worldOriginY = y + originY; final float sX = width / textureRegion.getRegionWidth(); final float sY = height / textureRegion.getRegionHeight(); final float cos = MathUtils.cosDeg(rotation); final float sin = MathUtils.sinDeg(rotation); float fx, fy; for (int i = 0; i < regionVerticesLength; i += 2) { fx = (regionVertices[i] * sX - originX) * scaleX; fy = (regionVertices[i + 1] * sY - originY) * scaleY; vertices[vertexIndex++] = cos * fx - sin * fy + worldOriginX; vertices[vertexIndex++] = sin * fx + cos * fy + worldOriginY; vertices[vertexIndex++] = light; vertices[vertexIndex++] = dark; vertices[vertexIndex++] = textureCoords[i]; vertices[vertexIndex++] = textureCoords[i + 1]; } this.vertexIndex = vertexIndex; }
From source file:org.ams.prettypaint.PrettyPolygonBatch.java
License:Open Source License
protected void drawTexture(PolygonRegion region, float pos_x, float pos_y, float width, float height, float scaleX, float scaleY, float rotation, float texture_pos_x, float texture_pos_y, float tex_trans_x, float tex_trans_y, float region_width, float region_height, float packedColor) { if (!isStarted) throw new RuntimeException("You must call begin() before calling this method."); final float[] regionVertices = region.getVertices(); final int regionVerticesLength = regionVertices.length; final TextureRegion textureRegion = region.getRegion(); Texture texture = textureRegion.getTexture(); float vertexCount = 3f; float degenerateVertexCount = 2f; float totalData = dataPerVertex * (vertexCount + degenerateVertexCount); if (texture != lastTexture) { flush();// w w w. j a va 2 s . c o m lastTexture = texture; } else if (dataCount + totalData > maxData) { flush(); } final float[] textureCoordinates = region.getTextureCoords(); final float worldOriginX = pos_x; final float worldOriginY = pos_y; final float sX = width / textureRegion.getRegionWidth(); final float sY = height / textureRegion.getRegionHeight(); final float cos = MathUtils.cos(rotation); final float sin = MathUtils.sin(rotation); float fx, fy; int i = 0; { fx = (regionVertices[i] * sX) * scaleX; fy = (regionVertices[i + 1] * sY) * scaleY; data[dataCount++] = cos * fx - sin * fy + worldOriginX; data[dataCount++] = sin * fx + cos * fy + worldOriginY; data[dataCount++] = packedColor; data[dataCount++] = textureCoordinates[i] + tex_trans_x; data[dataCount++] = textureCoordinates[i + 1] + tex_trans_y; data[dataCount++] = texture_pos_x; data[dataCount++] = texture_pos_y; data[dataCount++] = region_width; data[dataCount++] = region_height; } for (; i < regionVerticesLength; i += 2) { fx = (regionVertices[i] * sX) * scaleX; fy = (regionVertices[i + 1] * sY) * scaleY; data[dataCount++] = cos * fx - sin * fy + worldOriginX; data[dataCount++] = sin * fx + cos * fy + worldOriginY; data[dataCount++] = packedColor; data[dataCount++] = textureCoordinates[i] + tex_trans_x; data[dataCount++] = textureCoordinates[i + 1] + tex_trans_y; data[dataCount++] = texture_pos_x; data[dataCount++] = texture_pos_y; data[dataCount++] = region_width; data[dataCount++] = region_height; } { i -= 2; fx = (regionVertices[i] * sX) * scaleX; fy = (regionVertices[i + 1] * sY) * scaleY; data[dataCount++] = cos * fx - sin * fy + worldOriginX; data[dataCount++] = sin * fx + cos * fy + worldOriginY; data[dataCount++] = packedColor; data[dataCount++] = textureCoordinates[i] + tex_trans_x; data[dataCount++] = textureCoordinates[i + 1] + tex_trans_y; data[dataCount++] = texture_pos_x; data[dataCount++] = texture_pos_y; data[dataCount++] = region_width; data[dataCount++] = region_height; } }
From source file:org.ams.prettypaint.TexturePolygon.java
License:Open Source License
/** * With texture angle you can rotate the texture without rotating the edges of the polygon. * * @param textureAngle the angle of the texture in radians. */// w w w . ja v a2s .co m public void setTextureAngle(float textureAngle) { Vector2 v = new Vector2(); for (int i = 0; i < polygonRegions.size; i++) { PolygonRegion toReplace = polygonRegions.get(i); float[] vertices = toReplace.getVertices(); for (int j = 0; j < vertices.length;) { v.set(vertices[j], vertices[j + 1]); v.rotateRad(this.textureAngle - textureAngle); vertices[j] = v.x; vertices[j + 1] = v.y; j += 2; } PolygonRegion replacement = new PolygonRegion(toReplace.getRegion(), vertices, toReplace.getTriangles()); polygonRegions.set(i, replacement); } this.textureAngle = textureAngle; }
From source file:org.ams.prettypaint.TexturePolygon.java
License:Open Source License
/** Set the texture to be upright at the polygons current angle. */ public void setTextureUprightForCurrentAngle() { Vector2 v = new Vector2(); for (int i = 0; i < polygonRegions.size; i++) { PolygonRegion toReplace = polygonRegions.get(i); float[] vertices = toReplace.getVertices(); for (int j = 0; j < vertices.length;) { v.set(vertices[j], vertices[j + 1]); v.rotateRad(textureAngle + angleRad); vertices[j] = v.x;/*from www . j av a 2s .c o m*/ vertices[j + 1] = v.y; j += 2; } PolygonRegion replacement = new PolygonRegion(toReplace.getRegion(), vertices, toReplace.getTriangles()); polygonRegions.set(i, replacement); } textureAngle = -angleRad; }