Example usage for com.badlogic.gdx.graphics.g2d Sprite getVertices

List of usage examples for com.badlogic.gdx.graphics.g2d Sprite getVertices

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d Sprite getVertices.

Prototype

public float[] getVertices() 

Source Link

Document

Returns the packed vertices, colors, and texture coordinates for this sprite.

Usage

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

private void RenderTargetArrow(Batch batch) {

    if (GlobalCore.getSelectedCache() == null)
        return;// www  .  j  av a  2 s.  c o m

    Coordinate coord = (GlobalCore.getSelectedWaypoint() != null) ? GlobalCore.getSelectedWaypoint().Pos
            : GlobalCore.getSelectedCache().Pos;

    if (coord == null) {
        return;
    }
    float x = (float) (256.0 * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, coord.getLongitude()));
    float y = (float) (-256.0 * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, coord.getLatitude()));

    float halfHeight = (mapIntHeight / 2) - ySpeedVersatz;
    float halfWidth = mapIntWidth / 2;

    // create ScreenRec
    try {
        if (TargetArrowScreenRec == null) {
            TargetArrowScreenRec = new CB_RectF(0, 0, mapIntWidth, mapIntHeight);
            if (Mode != MapMode.Compass) {
                TargetArrowScreenRec.ScaleCenter(0.9f);

                if (Mode == MapMode.Normal) {
                    TargetArrowScreenRec.setHeight(TargetArrowScreenRec.getHeight()
                            - (TargetArrowScreenRec.getHeight() - info.getY()) - zoomBtn.getHeight());
                    TargetArrowScreenRec.setY(zoomBtn.getMaxY());
                }
            }
        }

        Vector2 ScreenCenter = new Vector2(halfWidth, halfHeight);

        Vector2 screen = worldToScreen(new Vector2(x, y));
        Vector2 target = new Vector2(screen.x, screen.y);

        Vector2 newTarget = TargetArrowScreenRec.getIntersection(ScreenCenter, target);

        // Rotation berechnen
        if (newTarget != null) {

            float direction = get_angle(ScreenCenter.x, ScreenCenter.y, newTarget.x, newTarget.y);
            direction = 180 - direction;

            // draw sprite
            Sprite arrow = Sprites.Arrows.get(4);
            arrow.setRotation(direction);

            float boundsX = newTarget.x - GL_UISizes.TargetArrow.halfWidth;
            float boundsY = newTarget.y - GL_UISizes.TargetArrow.height;

            arrow.setBounds(boundsX, boundsY, GL_UISizes.TargetArrow.width, GL_UISizes.TargetArrow.height);

            arrow.setOrigin(GL_UISizes.TargetArrow.halfWidth, GL_UISizes.TargetArrow.height);
            arrow.draw(batch);

            // get real bounding box of TargetArrow
            float t[] = arrow.getVertices();
            float maxX = Math.max(Math.max(t[0], t[5]), Math.max(t[10], t[15]));
            float minX = Math.min(Math.min(t[0], t[5]), Math.min(t[10], t[15]));
            float maxY = Math.max(Math.max(t[1], t[6]), Math.max(t[11], t[16]));
            float minY = Math.min(Math.min(t[1], t[6]), Math.min(t[11], t[16]));
            TargetArrow.set(minX, minY, maxX - minX, maxY - minY);
        } else {
            TargetArrow.set(0, 0, 0, 0);
        }
    } catch (Exception e) {
        TargetArrow.set(0, 0, 0, 0);
    }
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified sprite to the cache. */
public void add(Sprite sprite) {
    if (mesh.getNumIndices() > 0) {
        add(sprite.getTexture(), sprite.getVertices(), 0, SPRITE_SIZE);
        return;/*from ww w .  j  av a2 s . co  m*/
    }

    float[] spriteVertices = sprite.getVertices();
    System.arraycopy(spriteVertices, 0, tempVertices, 0, 3 * VERTEX_SIZE); // temp0,1,2=sprite0,1,2
    System.arraycopy(spriteVertices, 2 * VERTEX_SIZE, tempVertices, 3 * VERTEX_SIZE, VERTEX_SIZE); // temp3=sprite2
    System.arraycopy(spriteVertices, 3 * VERTEX_SIZE, tempVertices, 4 * VERTEX_SIZE, VERTEX_SIZE); // temp4=sprite3
    System.arraycopy(spriteVertices, 0, tempVertices, 5 * VERTEX_SIZE, VERTEX_SIZE); // temp5=sprite0
    add(sprite.getTexture(), tempVertices, 0, 30);
}

From source file:de.bioviz.ui.BioVizSpriteBatch.java

License:Open Source License

/**
 * Draws a sprite using a given matrix at a given depth.
 * @param s the sprite to be drawn./*from ww  w. j a  v  a2 s  .com*/
 * @param m the matrix to use.
 * @param z the depth value of the sprite.
 */
public void draw(final Sprite s, final Matrix4 m, final float z) {
    float[] vertices = s.getVertices().clone();
    Texture tex = s.getTexture();
    drawCalls.add(new Pair<>(z, () -> {
        Matrix4 old = sb.getProjectionMatrix();
        if (!(old.equals(m))) {
            sb.end();
            sb.setProjectionMatrix(m);
            sb.begin();
        }
        sb.draw(tex, vertices, 0, 20);
    }));
}