Example usage for com.badlogic.gdx.math Matrix4 translate

List of usage examples for com.badlogic.gdx.math Matrix4 translate

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Matrix4 translate.

Prototype

public Matrix4 translate(Vector3 translation) 

Source Link

Document

Postmultiplies this matrix by a translation matrix.

Usage

From source file:com.github.fauu.helix.editor.system.TileHighlightingSystem.java

License:Open Source License

@Override
protected void process(Entity e) {
    if (!mouseMoved()) {
        return;/*from  w  w w .j av  a2 s  .  com*/
    }

    Entity highlight = tagManager.getEntity("tileHighlight");

    Tile[][] tiles = tilesMapper.get(e).get();

    Ray ray = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY());

    boolean hovering = false;

    for (int y = 0; y < tiles.length; y++) {
        for (int x = 0; x < tiles[y].length; x++) {
            BoundingBox boundingBox = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 0));

            Matrix4 transformation = new Matrix4();
            transformation.translate(new Vector3(x, y, 0));

            boundingBox.mul(transformation);

            if (Intersector.intersectRayBoundsFast(ray, boundingBox)) {
                if (tiles[y][x] != highlightedTile) {
                    // FIXME
                    //            ModelDisplayable highlightDisplayable
                    //                = (ModelDisplayable) displayableMapper.get(highlight).get();
                    //            highlightDisplayable.updateTranslation(new Vector3(x, y, 0));

                    //            highlight.edit().create(VisibilityComponent.class);

                    highlightedTile = tiles[y][x];
                }

                hovering = true;

                break;
            }
        }
    }

    if (!hovering) {
        highlightedTile = null;

        highlight.edit().remove(VisibilityComponent.class);
    }
}

From source file:com.github.fauu.helix.editor.World.java

License:Open Source License

private Tile matchHoveredTile(int screenX, int screenY) {
    final Ray ray = camera.getPickRay(screenX, screenY);
    final GeometrySet geometrySet = mapRegion.getGeometrySet();
    final Tile[] tiles = mapRegion.getTiles();
    Tile newMatchedTile = null;/*from w ww .  j a v a2  s.  c  o  m*/

    for (Tile tile : tiles) {
        final BoundingBox boundingBox = geometrySet.getGeometryBoundingBox(tile.getGeometryId());
        final Matrix4 transformationMatrix = new Matrix4();
        transformationMatrix
                .translate(new Vector3(0.5f + tile.getPosition().x, 0, 0.5f + tile.getPosition().y));
        boundingBox.mul(transformationMatrix);

        if (Intersector.intersectRayBoundsFast(ray, boundingBox)) {
            newMatchedTile = tile;

            break;
        }
    }

    return newMatchedTile;
}

From source file:com.github.fauu.helix.editor.World.java

License:Open Source License

private Object matchHoveredObject(int screenX, int screenY) {
    final Ray ray = camera.getPickRay(screenX, screenY);
    final Array<Object> objects = mapRegion.getObjects();
    Object matchedObject = null;/*  www.  j  a  v a 2s  .com*/

    for (Object object : objects) {
        final BoundingBox boundingBox = new BoundingBox();
        object.getModelInstance().calculateBoundingBox(boundingBox);
        final Matrix4 transformationMatrix = new Matrix4();
        transformationMatrix
                .translate(new Vector3(2f + object.getPosition().x, 0, 0.5f + object.getPosition().y));
        boundingBox.mul(transformationMatrix);

        if (Intersector.intersectRayBoundsFast(ray, boundingBox)) {
            matchedObject = object;

            break;
        }
    }

    return matchedObject;
}