Example usage for com.badlogic.gdx.graphics.g2d Batch getProjectionMatrix

List of usage examples for com.badlogic.gdx.graphics.g2d Batch getProjectionMatrix

Introduction

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

Prototype

public Matrix4 getProjectionMatrix();

Source Link

Document

Returns the current projection matrix.

Usage

From source file:CB_UI_Base.GL_UI.Activitys.ImageActivity.java

License:Open Source License

@Override
public void render(Batch batch) {

    imageHeading = Gdx.input.getRotation();
    float x = Gdx.input.getAccelerometerX();
    float y = Gdx.input.getAccelerometerY();
    float z = Gdx.input.getAccelerometerZ();

    //  (|Gpz| < 0.5g) AND (Gpx > 0.5g) AND (|Gpy| < 0.4g): Change orientation to Left
    //  (|Gpz| < 0.5g) AND (Gpx < -0.5g) AND (|Gpy| < 0.4g): Change orientation to Right
    //  (|Gpz| < 0.5g) AND (Gpy > 0.5g) AND (|Gpx| < 0.4g): Change orientation to Bottom
    //  (|Gpz| < 0.5g) AND (Gpy < -0.5g) AND (|Gpx| < 0.4g): Change orientation to Top.

    if (z < 5 && x > 5 && y < 4) {
        imageHeading = -90;//  w  ww. ja  v a 2 s  .co  m
        //       Log.debug(log, "LEFT");
    } else if (z < 5 && x < -5 && y < 4) {
        imageHeading = 90;
        //       Log.debug(log, "RIGHT");
    } else if (z < 5 && y > 5 && x < 4) {
        //       Log.debug(log, "BOTTOM");
    } else {
        imageHeading = 0;
        //       Log.debug(log, "TOP");
    }

    // do not rotate until there is a button
    imageHeading = 0;

    super.render(batch);
    boolean reduceFps = ((kineticZoom != null) || ((kineticPan != null) && (kineticPan.getStarted())));
    if (kineticZoom != null) {
        camera.zoom = kineticZoom.getAktZoom();
        // float tmpZoom = mapTileLoader.convertCameraZommToFloat(camera);
        // aktZoom = (int) tmpZoom;

        int zoom = MAX_MAP_ZOOM;
        float tmpZoom = camera.zoom;
        float faktor = 1.5f;

        while (tmpZoom > faktor) {
            tmpZoom /= 2;
            zoom--;
        }
        aktZoom = zoom;

        if (kineticZoom.getFertig()) {
            GL.that.removeRenderView(this);
            kineticZoom = null;
        } else
            reduceFps = false;

    }

    if ((kineticPan != null) && (kineticPan.getStarted())) {
        if (kineticPan.getFertig()) {
            kineticPan = null;
        } else
            reduceFps = false;
    }

    if (reduceFps) {
        GL.that.removeRenderView(this);
    }
    Matrix4 mat = batch.getProjectionMatrix();
    renderImage(batch);
    batch.setProjectionMatrix(mat);
}

From source file:com.github.mkjensen.breakall.actor.Box2DActor.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();//from   w ww.  j a  v  a  2  s .  c  o  m
    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());
    draw(renderer);
    batch.begin();
}

From source file:com.luongbui.gdx.libpd.pianotest.character.PianoKey.java

License:Apache License

@Override
public void draw(Batch batch, float delta) {

    batch.end();/*  w w  w .ja v a2  s .  co m*/

    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());
    renderer.translate(getX(), getY(), 0);

    if (isLight) {
        if (!isPressed)
            renderer.begin(ShapeType.Line);
        else
            renderer.begin(ShapeType.Filled);
    } else {
        if (isPressed)
            renderer.begin(ShapeType.Line);
        else
            renderer.begin(ShapeType.Filled);
    }

    renderer.setColor(Color.BLACK);
    renderer.rect(0, 0, getWidth(), getHeight());
    renderer.end();

    batch.begin();

}

From source file:com.quadbits.gdxhelper.actors.BackgroundActor.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    // ------------------------------------------------------------------------
    // We are going to use a shapeRenderer -> end current batch
    // ------------------------------------------------------------------------
    batch.end();/*from  ww  w  .ja  v a  2s  .  com*/

    // ------------------------------------------------------------------------
    // Draw a rectangle with the specified colors
    // ------------------------------------------------------------------------
    shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

    shapeRenderer.rect(getX(), getY(), getWidth(), getHeight(), bottomLeftColor, bottomRightColor,
            topRightColor, topLeftColor);
    shapeRenderer.end();

    // ------------------------------------------------------------------------
    // We are done -> begin a batch again for the next actors
    // ------------------------------------------------------------------------
    batch.begin();
}

From source file:com.ray3k.skincomposer.GradientDrawable.java

License:Open Source License

@Override
public void draw(Batch batch, float x, float y, float width, float height) {
    float[] alphas = { col1.a, col2.a, col3.a, col4.a };
    col1.a = batch.getColor().a * col1.a;
    col2.a = batch.getColor().a * col2.a;
    col3.a = batch.getColor().a * col3.a;
    col4.a = batch.getColor().a * col4.a;

    g.begin(ShapeRenderer.ShapeType.Filled);
    g.setProjectionMatrix(batch.getProjectionMatrix());
    g.setTransformMatrix(batch.getTransformMatrix());
    batch.end();//from   w w w .  j a va 2  s  .  c  om
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    g.rect(x + borderLeft, y + borderBottom, width - borderLeft - borderRight,
            height - borderBottom - borderTop, col1, col2, col3, col4);
    g.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();

    col1.a = alphas[0];
    col2.a = alphas[1];
    col3.a = alphas[2];
    col4.a = alphas[3];
}

From source file:com.vlaaad.dice.ui.components.Rain.java

License:Open Source License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();//from   ww  w.j a v a 2 s  .com
    batch.end();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ShapeRenderer renderer = Config.shapeRenderer;
    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());

    renderer.begin(ShapeRenderer.ShapeType.Filled);
    renderer.setColor(style.color.r, style.color.g, style.color.b, style.color.a * parentAlpha);
    float usedWidth = getWidth() - style.pad;
    int count = (int) (usedWidth / (style.dropWidth + style.pad));
    if (count == 0)
        return;
    float step = usedWidth / ((float) count);
    float x = style.pad;
    for (int i = 0, n = rows.size; i < n; i++) {
        Row row = rows.get(i);
        drawRow(x, row);
        x += step;
    }
    renderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
}

From source file:es.eucm.ead.editor.components.EditorImageActor.java

License:Open Source License

protected void drawCollider(Batch batch) {
    if (getCollider() != null) {
        batch.end();/*from ww  w . j  a  va 2s  .c  o m*/
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_DST_COLOR);
        Gdx.gl.glBlendEquation(GL20.GL_FUNC_SUBTRACT);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
        shapeRenderer.begin(ShapeType.Line);
        shapeRenderer.setColor(Color.WHITE);
        for (Polygon polygon : getCollider()) {
            float[] vertices = polygon.getVertices();
            shapeRenderer.polygon(vertices);
        }
        shapeRenderer.end();
        Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD);
        Gdx.gl.glDisable(GL20.GL_BLEND);
        batch.begin();
    }
}

From source file:es.eucm.ead.editor.view.builders.scene.draw.MeshHelper.java

License:Open Source License

/**
 * Renders everything necessary to edit and draw brush strokes.
 * /*from   w  ww.jav  a 2s.  c om*/
 * @param batch
 * @param parentAlpha
 */
void draw(Batch batch, float parentAlpha) {
    if (!erasing) {
        drawShowingTexture(batch);
        if (this.recalculateMatrix) {
            this.recalculateMatrix = false;
            this.combinedMatrix.set(batch.getProjectionMatrix()).mul(batch.getTransformMatrix());
        }
        if (this.vertexIndex > MIN_VERTICES) {
            batch.end();
            drawMesh();
            batch.begin();
        }
    } else {
        if (this.vertexIndex > MIN_VERTICES && minX != Float.MAX_VALUE) {
            batch.end();
            fbo.begin();
            drawMesh();
            fbo.end();
            batch.begin();
        }
        drawShowingTexture(batch);
    }
}

From source file:es.eucm.ead.editor.view.widgets.groupeditor.GroupEditor.java

License:Open Source License

@Override
protected void drawChildren(Batch batch, float parentAlpha) {
    if (background != null) {
        background.draw(batch, 0, 0, getWidth(), getHeight());
    }/*from w ww  .  ja  v  a2  s .c  o m*/
    super.drawChildren(batch, parentAlpha);
    if (selection.getWidth() != 0 && selection.getHeight() != 0) {
        batch.end();
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
        drawSelectionRectangle();
        Gdx.gl.glDisable(GL20.GL_BLEND);
        batch.begin();
    }
}

From source file:es.eucm.ead.editor.view.widgets.groupeditor.Handles.java

License:Open Source License

@Override
protected void drawChildren(Batch batch, float parentAlpha) {
    batch.end();//from w w  w. j  av  a  2 s  .c o m
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_DST_COLOR);
    Gdx.gl.glBlendEquation(GL20.GL_FUNC_SUBTRACT);
    shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
    shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
    shapeRenderer.begin(ShapeType.Line);
    shapeRenderer.setColor(Color.WHITE);
    shapeRenderer.line(handles[0].getX(), handles[0].getY(), handles[2].getX(), handles[2].getY());
    shapeRenderer.line(handles[0].getX(), handles[0].getY(), handles[6].getX(), handles[6].getY());
    shapeRenderer.line(handles[2].getX(), handles[2].getY(), handles[8].getX(), handles[8].getY());
    shapeRenderer.line(handles[8].getX(), handles[8].getY(), handles[6].getX(), handles[6].getY());
    shapeRenderer.end();
    super.drawChildren(batch, parentAlpha);
    Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD);
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
}