Example usage for com.badlogic.gdx.graphics.glutils ShapeRenderer setProjectionMatrix

List of usage examples for com.badlogic.gdx.graphics.glutils ShapeRenderer setProjectionMatrix

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.glutils ShapeRenderer setProjectionMatrix.

Prototype

public void setProjectionMatrix(Matrix4 matrix) 

Source Link

Document

Sets the projection matrix to be used for rendering.

Usage

From source file:spaceisnear.game.ui.TextField.java

@Override
public void paint(Batch batch) {
    if (checkKeys(keycode)) {
        keycode = 0;//from   w  ww .  j  ava  2 s . c om
    }
    ShapeRenderer renderer = getRenderer();
    focused = getStage().getKeyboardFocus() == this;
    int start = 0;
    int end = text.length();
    int startingXText = 0;
    //TODO
    GlyphLayout glyphLayout = new GlyphLayout(font, text);
    if (glyphLayout.width > getWidthWithoutPaddings()) {
        end = text.length();
        start = end - 1;
        glyphLayout.setText(font, text, start, end, textColor, getWidthWithoutPaddings(), 0, false, null);
        while (start > 0 && glyphLayout.width < getWidthWithoutPaddings()) {
            start--;
        }
        glyphLayout.setText(font, text, 0, start, textColor, getWidthWithoutPaddings(), 0, false, null);
        startingXText = (int) -glyphLayout.width;
    }
    //
    {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        renderer.setProjectionMatrix(batch.getProjectionMatrix());
        renderer.begin(ShapeRenderer.ShapeType.Filled);
        renderer.setColor(backgroundColor);
        renderer.rect(0, 0, getWidth(), getHeight());
        renderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }
    {
        renderer.begin(ShapeRenderer.ShapeType.Line);
        renderer.setColor(borderColor);
        renderer.rect(0, 0, getWidth() + 1, getHeight());
        renderer.end();
    }
    //cursor
    renderer.begin(ShapeRenderer.ShapeType.Line);
    font.setColor(Color.BLACK);
    if (focused) {
        glyphLayout.setText(font, text, 0, currentPosition, textColor, getWidthWithoutPaddings(), 0, false,
                null);
        final float x = 10 + glyphLayout.width + startingXText;
        renderer.line(x, 3, x, font.getLineHeight() + 2);
        renderer.line(x + 1, 3, x + 1, font.getLineHeight() + 2);
    }
    renderer.end();
    batch.begin();
    font.setColor(Color.BLACK);
    font.draw(batch, text.subSequence(start, end), WIDTH_PADDING + getX(), 3 + getY());
    batch.end();
}

From source file:us.thirdmillenium.strategicassaultsimulator.environment.GameEnvironment.java

License:Apache License

@Override
public void simulate(float deltaTime) {
    // Compute time delta (max of frame speed)
    deltaTime = (float) Math.min(deltaTime, 1 / Params.FramesPerSecond);

    if (DRAW) {/* w  ww  . jav  a 2 s .  c o  m*/
        // Clear Background
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        // Draw Map
        this.Camera.update();
        this.TiledMapRenderer.setView(this.Camera);
        this.TiledMapRenderer.render();
    }

    // Test if Bullets Intersected with Anything
    MapObjects wallMapObjects = this.TiledMap.getLayers().get(2).getObjects();
    Iterator<GreenBullet> bullets = this.BulletTracker.iterator();
    this.SpriteBatchRenderer.setProjectionMatrix(this.Camera.combined);
    this.SpriteBatchRenderer.begin();

    while (bullets.hasNext()) {
        // Collect a Bullet to consider
        GreenBullet currentBullet = bullets.next();

        if (DRAW) {
            currentBullet.drawSprite(this.SpriteBatchRenderer);
        }

        currentBullet.updateBullet(deltaTime);

        // If bullet is off-screen, remove it.
        if (currentBullet.getBulletVector().x < 0 || currentBullet.getBulletVector().x > this.width
                || currentBullet.getBulletVector().y < 0 || currentBullet.getBulletVector().y > this.height) {
            this.BulletTracker.remove(currentBullet);
        } else {
            // Compare with all Agents
            Rectangle agentBound;

            Iterator<AgentModel> shootItr = this.shooters.iterator();

            while (shootItr.hasNext()) {
                AgentModel currShooter = shootItr.next();

                if (!currentBullet.thisAgentShotMe(currShooter) && Intersector.overlapConvexPolygons(
                        GraphicsHelpers.convertRectangleToPolygon(currShooter.getBoundingRectangle()),
                        currentBullet.getBulletPath())) {
                    currShooter.agentHit();
                    this.BulletTracker.remove(currentBullet);
                }
            }

            Iterator<AgentModel> agentItr = this.trainees.iterator();

            while (agentItr.hasNext()) {
                AgentModel currAgent = agentItr.next();

                if (!currentBullet.thisAgentShotMe(currAgent) && Intersector.overlapConvexPolygons(
                        GraphicsHelpers.convertRectangleToPolygon(currAgent.getBoundingRectangle()),
                        currentBullet.getBulletPath())) {
                    currAgent.agentHit();
                    this.BulletTracker.remove(currentBullet);
                }
            }

            // Compare with all Wall Boundaries
            for (int i = 0; i < wallMapObjects.getCount(); i++) {
                Object rectangleMapObject = wallMapObjects.get(i);

                // Make sure this is a Rectangle from Tiled describing a wall.
                if (rectangleMapObject.getClass() == RectangleMapObject.class) {
                    Rectangle wallRectangle = ((RectangleMapObject) rectangleMapObject).getRectangle();
                    Polygon polyBound = GraphicsHelpers.convertRectangleToPolygon(wallRectangle);

                    // Terminate when hitting a wall
                    if (Intersector.overlapConvexPolygons(polyBound, currentBullet.getBulletPath())) {
                        this.BulletTracker.remove(currentBullet);
                    }
                }
            }
        }
    }

    this.SpriteBatchRenderer.end();

    // Draw DEBUG information
    if (DEBUG && DRAW) {
        // Draw Map Nodes
        /*this.MapNodeSR.setProjectionMatrix(this.Camera.combined);
        this.MapNodeSR.setColor(Color.OLIVE);
        this.MapNodeSR.begin(ShapeRenderer.ShapeType.Filled);
                
        if (this.TraverseNodes != null) {
        for (Integer key : this.TraverseNodes.keySet()) {
            this.MapNodeSR.circle(this.TraverseNodes.get(key).getPixelX(), this.TraverseNodes.get(key).getPixelY(), 10);
        }
        }
                
        this.MapNodeSR.end();*/

        // Draw Overlay Lines
        this.LineRenderer.setProjectionMatrix(this.Camera.combined);
        this.LineRenderer.begin(ShapeRenderer.ShapeType.Filled);

        // For each Agent.  Different Colors?
        this.LineRenderer.setColor(Color.BLACK);

        /*if( PUPPET ) {
           this.puppet.drawPath(this.LineRenderer);
        }*/

        Iterator<AgentModel> agentItr = this.trainees.iterator();

        while (agentItr.hasNext()) {
            AgentModel currAgent = agentItr.next();
            currAgent.drawPath(this.LineRenderer);
        }

        this.LineRenderer.end();
    }

    // Draw Agent Sprites

    this.SpriteBatchRenderer.begin();

    /*if( PUPPET ) {
       this.puppet.updateAgent(deltaTime);
       this.puppet.drawAgent(this.SpriteBatchRenderer);
    }*/

    Iterator<AgentModel> shootItr = this.shooters.iterator();

    while (shootItr.hasNext()) {
        AgentModel currShooter = shootItr.next();

        currShooter.updateAgent(deltaTime);
        if (DRAW) {
            currShooter.drawAgent(this.SpriteBatchRenderer);
        }
    }

    Iterator<AgentModel> agentItr = this.trainees.iterator();

    while (agentItr.hasNext()) {
        AgentModel currAgent = agentItr.next();

        currAgent.updateAgent(deltaTime);

        if (DRAW) {
            currAgent.drawAgent(this.SpriteBatchRenderer);
        }
    }

    this.SpriteBatchRenderer.end();

    if (DEBUG) {
        Iterator<AgentModel> agentItr2 = this.trainees.iterator();

        ShapeRenderer visionCone = new ShapeRenderer();
        visionCone.setProjectionMatrix(this.Camera.combined);
        visionCone.begin(ShapeRenderer.ShapeType.Line);
        visionCone.setColor(Color.YELLOW);

        while (agentItr2.hasNext()) {
            AgentModel currAgent = agentItr2.next();

            currAgent.drawVision(visionCone);
        }

        visionCone.end();
    }

    /*// Test Draw the Collision Boxes
    if( DEBUG && DRAW ) {
    ShapeRenderer anotherShapeRenderer = new ShapeRenderer();
            
       anotherShapeRenderer.setProjectionMatrix(this.Camera.combined);
       anotherShapeRenderer.begin(ShapeRenderer.ShapeType.Line);
            
       bullets = this.BulletTracker.iterator();
            
       while(bullets.hasNext()) {
      GreenBullet currentBullet = bullets.next();
      anotherShapeRenderer.polygon(currentBullet.getBulletPath().getTransformedVertices());
       }
            
       for(int i = 0; i < wallMapObjects.getCount(); i++ ){
      Object obj = wallMapObjects.get(i);
            
      if( obj.getClass() == RectangleMapObject.class ) {
         Rectangle boundary = ((RectangleMapObject)obj).getRectangle();
         anotherShapeRenderer.rect(boundary.x, boundary.y, boundary.width, boundary.height);
            
         float[] vertices = {
            boundary.x, boundary.y,
            boundary.x + boundary.width, boundary.y,
            boundary.x + boundary.width, boundary.y + boundary.height,
            boundary.x, boundary.y + boundary.height
         };
            
         //Polygon polyBound = new Polygon(vertices);
         anotherShapeRenderer.setColor(Color.BLUE);
         anotherShapeRenderer.polygon(vertices);
      }
       }
            
       anotherShapeRenderer.end();
    }*/

}

From source file:vault.clockwork.controllers.CameraController.java

License:Open Source License

/**
 * Wykonuje sie przed rysowaniem debug screena.
 * @param gizmo /*from ww  w . java2s  .c o m*/
 */
@Override
public void preDebug(ShapeRenderer gizmo) {
    gizmo.setProjectionMatrix(camera.combined);

    // enable alpha channel usage
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // draw scene regions
    gizmo.begin(ShapeRenderer.ShapeType.Line);
    gizmo.setColor(1.f, 0.1f, 0.f, 0.5f);
    gizmo.rect(CameraController.SCREEN_BOUNDS.x, CameraController.SCREEN_BOUNDS.y,
            CameraController.SCREEN_BOUNDS.width, CameraController.SCREEN_BOUNDS.height);
    gizmo.end();
}