List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion getV2
public float getV2()
From source file:br.com.animvs.koalory.entities.engine.graphics.tiles.TileRenderer.java
License:Apache License
@Override public void renderTileLayer(TiledMapTileLayer layer) { final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity()); final int layerWidth = layer.getWidth(); final int layerHeight = layer.getHeight(); final float layerTileWidth = layer.getTileWidth() * unitScale; final float layerTileHeight = layer.getTileHeight() * unitScale; final int col1 = Math.max(0, (int) (cacheBounds.x / layerTileWidth)); final int col2 = Math.min(layerWidth, (int) ((cacheBounds.x + cacheBounds.width + layerTileWidth) / layerTileWidth)); final int row1 = Math.max(0, (int) (cacheBounds.y / layerTileHeight)); final int row2 = Math.min(layerHeight, (int) ((cacheBounds.y + cacheBounds.height + layerTileHeight) / layerTileHeight)); canCacheMoreN = row2 < layerHeight; canCacheMoreE = col2 < layerWidth; canCacheMoreW = col1 > 0;/* ww w. j ava 2 s . c o m*/ canCacheMoreS = row1 > 0; float[] vertices = this.vertices; for (int row = row2; row >= row1; row--) { for (int col = col1; col < col2; col++) { final TiledMapTileLayer.Cell cell = layer.getCell(col, row); if (cell == null) continue; final TiledMapTile tile = cell.getTile(); if (tile == null) continue; count++; final boolean flipX = cell.getFlipHorizontally(); final boolean flipY = cell.getFlipVertically(); final int rotations = cell.getRotation(); final TextureRegion region = tile.getTextureRegion(); final Texture texture = region.getTexture(); final float x1 = col * layerTileWidth + tile.getOffsetX() * unitScale; final float y1 = row * layerTileHeight + tile.getOffsetY() * unitScale; final float x2 = x1 + region.getRegionWidth() * unitScale; final float y2 = y1 + region.getRegionHeight() * unitScale; final float adjustX = 0.5f / texture.getWidth(); final float adjustY = 0.5f / texture.getHeight(); final float u1 = region.getU() + adjustX; final float v1 = region.getV2() - adjustY; final float u2 = region.getU2() - adjustX; final float v2 = region.getV() + adjustY; vertices[X1] = x1; vertices[Y1] = y1; vertices[C1] = color; vertices[U1] = u1; vertices[V1] = v1; vertices[X2] = x1; vertices[Y2] = y2; vertices[C2] = color; vertices[U2] = u1; vertices[V2] = v2; vertices[X3] = x2; vertices[Y3] = y2; vertices[C3] = color; vertices[U3] = u2; vertices[V3] = v2; vertices[X4] = x2; vertices[Y4] = y1; vertices[C4] = color; vertices[U4] = u2; vertices[V4] = v1; if (flipX) { float temp = vertices[U1]; vertices[U1] = vertices[U3]; vertices[U3] = temp; temp = vertices[U2]; vertices[U2] = vertices[U4]; vertices[U4] = temp; } if (flipY) { float temp = vertices[V1]; vertices[V1] = vertices[V3]; vertices[V3] = temp; temp = vertices[V2]; vertices[V2] = vertices[V4]; vertices[V4] = temp; } if (rotations != 0) { switch (rotations) { case Cell.ROTATE_90: { float tempV = vertices[V1]; vertices[V1] = vertices[V2]; vertices[V2] = vertices[V3]; vertices[V3] = vertices[V4]; vertices[V4] = tempV; float tempU = vertices[U1]; vertices[U1] = vertices[U2]; vertices[U2] = vertices[U3]; vertices[U3] = vertices[U4]; vertices[U4] = tempU; break; } case Cell.ROTATE_180: { float tempU = vertices[U1]; vertices[U1] = vertices[U3]; vertices[U3] = tempU; tempU = vertices[U2]; vertices[U2] = vertices[U4]; vertices[U4] = tempU; float tempV = vertices[V1]; vertices[V1] = vertices[V3]; vertices[V3] = tempV; tempV = vertices[V2]; vertices[V2] = vertices[V4]; vertices[V4] = tempV; break; } case Cell.ROTATE_270: { float tempV = vertices[V1]; vertices[V1] = vertices[V4]; vertices[V4] = vertices[V3]; vertices[V3] = vertices[V2]; vertices[V2] = tempV; float tempU = vertices[U1]; vertices[U1] = vertices[U4]; vertices[U4] = vertices[U3]; vertices[U3] = vertices[U2]; vertices[U2] = tempU; break; } } } spriteCache.add(texture, vertices, 0, 20); } } }
From source file:com.agateau.pixelwheels.racer.SkidmarksRenderer.java
License:Open Source License
private void drawSkidmark(Batch batch, Vector2 pos1, Vector2 pos2, float alpha1, float alpha2) { TextureRegion region = mAssets.skidmark; float c = Color.toFloatBits(1, 1, 1, alpha1); float c2 = Color.toFloatBits(1, 1, 1, alpha2); float u = region.getU(); float v = region.getV(); float u2 = region.getU2(); float v2 = region.getV2(); /*/*from w w w. ja v a 2 s . c o m*/ 0 3 x----------x ^ | | | pos1 x x pos2 | thickness | | x----------x 1 2 */ float x0 = pos1.x + mThickX1; float y0 = pos1.y + mThickY1; float x1 = pos1.x - mThickX1; float y1 = pos1.y - mThickY1; float x2 = pos2.x - mThickX2; float y2 = pos2.y - mThickY2; float x3 = pos2.x + mThickX2; float y3 = pos2.y + mThickY2; initVertex(0, x0, y0, c, u, v); initVertex(1, x1, y1, c, u2, v); initVertex(2, x2, y2, c2, u2, v2); initVertex(3, x3, y3, c2, u, v2); batch.draw(region.getTexture(), mVertices, 0, mVertices.length); }
From source file:com.anythingmachine.gdxwrapper.SpriteCache.java
License:Apache License
/** Adds the specified region to the cache. */ public void add(TextureRegion region, float x, float y, float width, float height) { final float fx2 = x + width; final float fy2 = y + height; final float u = region.getU(); final float v = region.getV2(); final float u2 = region.getU2(); final float v2 = region.getV(); tempVertices[0] = x;// w ww.j a va 2s. c om tempVertices[1] = y; tempVertices[2] = color; tempVertices[3] = u; tempVertices[4] = v; tempVertices[5] = x; tempVertices[6] = fy2; tempVertices[7] = color; tempVertices[8] = u; tempVertices[9] = v2; tempVertices[10] = fx2; tempVertices[11] = fy2; tempVertices[12] = color; tempVertices[13] = u2; tempVertices[14] = v2; if (mesh.getNumIndices() > 0) { tempVertices[15] = fx2; tempVertices[16] = y; tempVertices[17] = color; tempVertices[18] = u2; tempVertices[19] = v; add(region.getTexture(), tempVertices, 0, 20); } else { tempVertices[15] = fx2; tempVertices[16] = fy2; tempVertices[17] = color; tempVertices[18] = u2; tempVertices[19] = v2; tempVertices[20] = fx2; tempVertices[21] = y; tempVertices[22] = color; tempVertices[23] = u2; tempVertices[24] = v; tempVertices[25] = x; tempVertices[26] = y; tempVertices[27] = color; tempVertices[28] = u; tempVertices[29] = v; add(region.getTexture(), tempVertices, 0, 30); } }
From source file:com.anythingmachine.gdxwrapper.SpriteCache.java
License:Apache License
/** Adds the specified region to the cache. */ public void add(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { // bottom left and top right corner points relative to origin final float worldOriginX = x + originX; final float worldOriginY = y + originY; float fx = -originX; float fy = -originY; float fx2 = width - originX; float fy2 = height - originY; // scale/*from w ww. j a va2 s.com*/ if (scaleX != 1 || scaleY != 1) { fx *= scaleX; fy *= scaleY; fx2 *= scaleX; fy2 *= scaleY; } // construct corner points, start from top left and go counter clockwise final float p1x = fx; final float p1y = fy; final float p2x = fx; final float p2y = fy2; final float p3x = fx2; final float p3y = fy2; final float p4x = fx2; final float p4y = fy; float x1; float y1; float x2; float y2; float x3; float y3; float x4; float y4; // rotate if (rotation != 0) { final float cos = MathUtils.cosDeg(rotation); final float sin = MathUtils.sinDeg(rotation); x1 = cos * p1x - sin * p1y; y1 = sin * p1x + cos * p1y; x2 = cos * p2x - sin * p2y; y2 = sin * p2x + cos * p2y; x3 = cos * p3x - sin * p3y; y3 = sin * p3x + cos * p3y; x4 = x1 + (x3 - x2); y4 = y3 - (y2 - y1); } else { x1 = p1x; y1 = p1y; x2 = p2x; y2 = p2y; x3 = p3x; y3 = p3y; x4 = p4x; y4 = p4y; } x1 += worldOriginX; y1 += worldOriginY; x2 += worldOriginX; y2 += worldOriginY; x3 += worldOriginX; y3 += worldOriginY; x4 += worldOriginX; y4 += worldOriginY; final float u = region.getU(); final float v = region.getV2(); final float u2 = region.getU2(); final float v2 = region.getV(); tempVertices[0] = x1; tempVertices[1] = y1; tempVertices[2] = color; tempVertices[3] = u; tempVertices[4] = v; tempVertices[5] = x2; tempVertices[6] = y2; tempVertices[7] = color; tempVertices[8] = u; tempVertices[9] = v2; tempVertices[10] = x3; tempVertices[11] = y3; tempVertices[12] = color; tempVertices[13] = u2; tempVertices[14] = v2; if (mesh.getNumIndices() > 0) { tempVertices[15] = x4; tempVertices[16] = y4; tempVertices[17] = color; tempVertices[18] = u2; tempVertices[19] = v; add(region.getTexture(), tempVertices, 0, 20); } else { tempVertices[15] = x3; tempVertices[16] = y3; tempVertices[17] = color; tempVertices[18] = u2; tempVertices[19] = v2; tempVertices[20] = x4; tempVertices[21] = y4; tempVertices[22] = color; tempVertices[23] = u2; tempVertices[24] = v; tempVertices[25] = x1; tempVertices[26] = y1; tempVertices[27] = color; tempVertices[28] = u; tempVertices[29] = v; add(region.getTexture(), tempVertices, 0, 30); } }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.realistic.MainShader.java
License:Apache License
public void bindDirectionalShadows(final Attributes attributes) { final DirectionalLightsAttribute dla = attributes.get(DirectionalLightsAttribute.class, DirectionalLightsAttribute.Type); final Array<DirectionalLight> dirs = dla == null ? null : dla.lights; if (dirLightsLoc >= 0) { for (int i = 0; i < directionalLights.length; i++) { if (dirs == null || dirs.size <= i) { continue; }// ww w. j a va 2 s . co m int idx = dirShadowsLoc + i * dirShadowsSize; // Shadow ObjectMap<DirectionalLight, LightProperties> dirCameras = shadowSystem.getDirectionalCameras(); DirectionalLight dl = dirs.get(i); if (shadowSystem.hasLight(dl)) { // UVTransform final TextureRegion tr = dirCameras.get(dl).region; Camera cam = dirCameras.get(dl).camera; if (cam != null) { program.setUniformf(idx + dirShadowsUvTransformOffset, tr.getU(), tr.getV(), tr.getU2() - tr.getU(), tr.getV2() - tr.getV()); // ProjViewTrans idx = dirShadowMapProjViewTransLoc + i * dirShadowMapProjViewTransSize; program.setUniformMatrix(idx, dirCameras.get(dl).camera.combined); } } if (dirLightsSize <= 0) break; } } }
From source file:com.badlogic.gdx.tests.g3d.shadows.system.realistic.MainShader.java
License:Apache License
public void bindSpotShadows(final Attributes attributes) { final SpotLightsAttribute sla = attributes.get(SpotLightsAttribute.class, SpotLightsAttribute.Type); final Array<SpotLight> spots = sla == null ? null : sla.lights; if (spotLightsLoc >= 0) { for (int i = 0; i < spotLights.length; i++) { if (spots == null || spots.size <= i) { continue; }// ww w . j av a 2s . c om int idx = spotShadowsLoc + i * spotShadowsSize; // Shadow ObjectMap<SpotLight, LightProperties> spotCameras = shadowSystem.getSpotCameras(); SpotLight sl = spots.get(i); if (shadowSystem.hasLight(sl)) { // UVTransform final TextureRegion tr = spotCameras.get(sl).region; Camera cam = spotCameras.get(sl).camera; if (cam != null) { program.setUniformf(idx + spotShadowsUvTransformOffset, tr.getU(), tr.getV(), tr.getU2() - tr.getU(), tr.getV2() - tr.getV()); // ProjViewTrans idx = spotShadowMapProjViewTransLoc + i * spotShadowMapProjViewTransSize; program.setUniformMatrix(idx, spotCameras.get(sl).camera.combined); } } if (spotLightsSize <= 0) break; } } }
From source file:com.balloongame.handlers.CustomSpriteBatch.java
License:Apache License
/** Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. */ public void draw(TextureRegion region, float x, float y, float width, float height) { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw."); Texture texture = region.getTexture(); if (texture != lastTexture) { switchTexture(texture);/* w w w . j ava2 s . com*/ } else if (idx == vertices.length) // renderMesh(); final float fx2 = x + width; final float fy2 = y + height; final float u = region.getU(); final float v = region.getV2(); final float u2 = region.getU2(); final float v2 = region.getV(); vertices[idx++] = x; vertices[idx++] = y; vertices[idx++] = color; vertices[idx++] = u; vertices[idx++] = v; vertices[idx++] = x; vertices[idx++] = fy2; vertices[idx++] = color; vertices[idx++] = u; vertices[idx++] = v2; vertices[idx++] = fx2; vertices[idx++] = fy2; vertices[idx++] = color; vertices[idx++] = u2; vertices[idx++] = v2; vertices[idx++] = fx2; vertices[idx++] = y; vertices[idx++] = color; vertices[idx++] = u2; vertices[idx++] = v; }
From source file:com.balloongame.handlers.CustomSpriteBatch.java
License:Apache License
/** Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. The * rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle * should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around * originX, originY. */// ww w .j a v a 2s . c o m public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw."); Texture texture = region.getTexture(); if (texture != lastTexture) { switchTexture(texture); } else if (idx == vertices.length) // renderMesh(); // bottom left and top right corner points relative to origin final float worldOriginX = x + originX; final float worldOriginY = y + originY; float fx = -originX; float fy = -originY; float fx2 = width - originX; float fy2 = height - originY; // scale if (scaleX != 1 || scaleY != 1) { fx *= scaleX; fy *= scaleY; fx2 *= scaleX; fy2 *= scaleY; } // construct corner points, start from top left and go counter clockwise final float p1x = fx; final float p1y = fy; final float p2x = fx; final float p2y = fy2; final float p3x = fx2; final float p3y = fy2; final float p4x = fx2; final float p4y = fy; float x1; float y1; float x2; float y2; float x3; float y3; float x4; float y4; // rotate if (rotation != 0) { final float cos = MathUtils.cosDeg(rotation); final float sin = MathUtils.sinDeg(rotation); x1 = cos * p1x - sin * p1y; y1 = sin * p1x + cos * p1y; x2 = cos * p2x - sin * p2y; y2 = sin * p2x + cos * p2y; x3 = cos * p3x - sin * p3y; y3 = sin * p3x + cos * p3y; x4 = x1 + (x3 - x2); y4 = y3 - (y2 - y1); } else { x1 = p1x; y1 = p1y; x2 = p2x; y2 = p2y; x3 = p3x; y3 = p3y; x4 = p4x; y4 = p4y; } x1 += worldOriginX; y1 += worldOriginY; x2 += worldOriginX; y2 += worldOriginY; x3 += worldOriginX; y3 += worldOriginY; x4 += worldOriginX; y4 += worldOriginY; final float u = region.getU(); final float v = region.getV2(); final float u2 = region.getU2(); final float v2 = region.getV(); vertices[idx++] = x1; vertices[idx++] = y1; vertices[idx++] = color; vertices[idx++] = u; vertices[idx++] = v; vertices[idx++] = x2; vertices[idx++] = y2; vertices[idx++] = color; vertices[idx++] = u; vertices[idx++] = v2; vertices[idx++] = x3; vertices[idx++] = y3; vertices[idx++] = color; vertices[idx++] = u2; vertices[idx++] = v2; vertices[idx++] = x4; vertices[idx++] = y4; vertices[idx++] = color; vertices[idx++] = u2; vertices[idx++] = v; }
From source file:com.balloongame.handlers.CustomSpriteBatch.java
License:Apache License
/** Draws a rectangle with the texture coordinates rotated 90 degrees. The bottom left corner at x,y and stretching the region * to cover the given width and height. The rectangle is offset by originX, originY relative to the origin. Scale specifies the * scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter * clockwise rotation of the rectangle around originX, originY. * @param clockwise If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees * counter clockwise. */ public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise) { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw."); Texture texture = region.getTexture(); if (texture != lastTexture) { switchTexture(texture);/*from w w w.ja va 2 s. c om*/ } else if (idx == vertices.length) // renderMesh(); // bottom left and top right corner points relative to origin final float worldOriginX = x + originX; final float worldOriginY = y + originY; float fx = -originX; float fy = -originY; float fx2 = width - originX; float fy2 = height - originY; // scale if (scaleX != 1 || scaleY != 1) { fx *= scaleX; fy *= scaleY; fx2 *= scaleX; fy2 *= scaleY; } // construct corner points, start from top left and go counter clockwise final float p1x = fx; final float p1y = fy; final float p2x = fx; final float p2y = fy2; final float p3x = fx2; final float p3y = fy2; final float p4x = fx2; final float p4y = fy; float x1; float y1; float x2; float y2; float x3; float y3; float x4; float y4; // rotate if (rotation != 0) { final float cos = MathUtils.cosDeg(rotation); final float sin = MathUtils.sinDeg(rotation); x1 = cos * p1x - sin * p1y; y1 = sin * p1x + cos * p1y; x2 = cos * p2x - sin * p2y; y2 = sin * p2x + cos * p2y; x3 = cos * p3x - sin * p3y; y3 = sin * p3x + cos * p3y; x4 = x1 + (x3 - x2); y4 = y3 - (y2 - y1); } else { x1 = p1x; y1 = p1y; x2 = p2x; y2 = p2y; x3 = p3x; y3 = p3y; x4 = p4x; y4 = p4y; } x1 += worldOriginX; y1 += worldOriginY; x2 += worldOriginX; y2 += worldOriginY; x3 += worldOriginX; y3 += worldOriginY; x4 += worldOriginX; y4 += worldOriginY; float u1, v1, u2, v2, u3, v3, u4, v4; if (clockwise) { u1 = region.getU2(); v1 = region.getV2(); u2 = region.getU(); v2 = region.getV2(); u3 = region.getU(); v3 = region.getV(); u4 = region.getU2(); v4 = region.getV(); } else { u1 = region.getU(); v1 = region.getV(); u2 = region.getU2(); v2 = region.getV(); u3 = region.getU2(); v3 = region.getV2(); u4 = region.getU(); v4 = region.getV2(); } vertices[idx++] = x1; vertices[idx++] = y1; vertices[idx++] = color; vertices[idx++] = u1; vertices[idx++] = v1; vertices[idx++] = x2; vertices[idx++] = y2; vertices[idx++] = color; vertices[idx++] = u2; vertices[idx++] = v2; vertices[idx++] = x3; vertices[idx++] = y3; vertices[idx++] = color; vertices[idx++] = u3; vertices[idx++] = v3; vertices[idx++] = x4; vertices[idx++] = y4; vertices[idx++] = color; vertices[idx++] = u4; vertices[idx++] = v4; }
From source file:com.company.minery.utils.spine.attachments.RegionAttachment.java
License:Open Source License
public void setRegion(TextureRegion region) { if (region == null) throw new IllegalArgumentException("region cannot be null."); this.region = region; float[] vertices = this.vertices; if (region instanceof AtlasRegion && ((AtlasRegion) region).rotate) { vertices[U3] = region.getU();//from w ww .j a v a2 s . co m vertices[V3] = region.getV2(); vertices[U4] = region.getU(); vertices[V4] = region.getV(); vertices[U1] = region.getU2(); vertices[V1] = region.getV(); vertices[U2] = region.getU2(); vertices[V2] = region.getV2(); } else { vertices[U2] = region.getU(); vertices[V2] = region.getV2(); vertices[U3] = region.getU(); vertices[V3] = region.getV(); vertices[U4] = region.getU2(); vertices[V4] = region.getV(); vertices[U1] = region.getU2(); vertices[V1] = region.getV2(); } }