Example usage for com.badlogic.gdx.math.collision BoundingBox mul

List of usage examples for com.badlogic.gdx.math.collision BoundingBox mul

Introduction

In this page you can find the example usage for com.badlogic.gdx.math.collision BoundingBox mul.

Prototype

public BoundingBox mul(Matrix4 transform) 

Source Link

Document

Multiplies the bounding box by the given 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   www.  j a v  a  2  s . c o m*/
    }

    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;/* w  w  w  .j a v a 2 s  .co  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;//from ww w.j av  a  2s.c  om

    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;
}