Example usage for com.badlogic.gdx.graphics Mesh calculateBoundingBox

List of usage examples for com.badlogic.gdx.graphics Mesh calculateBoundingBox

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Mesh calculateBoundingBox.

Prototype

public BoundingBox calculateBoundingBox() 

Source Link

Document

Calculates the BoundingBox of the vertices contained in this mesh.

Usage

From source file:com.andgate.ikou.render.FloorRender.java

License:Open Source License

private void calculateSize() {
    size.x = 0;//from  ww w .  ja v a 2 s. com
    size.y = 0;
    size.z = 0;

    for (SectorMesh[] sectorMeshRow : sectorMeshes) {
        for (SectorMesh sectorMesh : sectorMeshRow) {
            Mesh mesh = sectorMesh.getMesh();

            if (mesh != null) {
                BoundingBox bbox = mesh.calculateBoundingBox();

                size.x += bbox.getWidth();
                size.y = Math.max(size.y, bbox.getHeight());
                size.z += bbox.getDepth();
            }
        }
    }
}

From source file:com.hajnar.GravityShip.GameObjects.Terrain.java

License:Apache License

public void generateMeshes() {
    ArrayList<Fixture> terrainFixtures = objectBody.getFixtureList();
    Vector2 boxVertex = new Vector2();
    meshes = new ArrayList<Mesh>();
    boundingBoxes = new ArrayList<BoundingBox>();
    EarClippingTriangulator ear = new EarClippingTriangulator();

    for (Fixture terrainFixture : terrainFixtures) {
        PolygonShape shape = (PolygonShape) terrainFixture.getShape();
        boxVertex = new Vector2();
        int vc = shape.getVertexCount();
        ArrayList<Vector2> boxVertices = new ArrayList<Vector2>();
        ArrayList<Vector2> triaBoxVertices = new ArrayList<Vector2>();

        for (int i = 0; i < vc; i++) {
            shape.getVertex(i, boxVertex);
            boxVertex = objectBody.getWorldPoint(boxVertex).mul(Helper.BOX_TO_WORLD);
            boxVertices.add(boxVertex.cpy());
        }//from   w  ww.j a v a 2s. c  o m
        triaBoxVertices = (ArrayList<Vector2>) ear.computeTriangles(boxVertices);
        float[] meshVertices = new float[triaBoxVertices.size() * 4];
        short[] meshIndices = new short[triaBoxVertices.size()];
        for (int i = 0; i < triaBoxVertices.size(); i++) {
            meshVertices[i * 4] = triaBoxVertices.get(i).x;
            meshVertices[i * 4 + 1] = triaBoxVertices.get(i).y;
            meshVertices[i * 4 + 2] = triaBoxVertices.get(i).x * TEXTURE_SCALE;
            meshVertices[i * 4 + 3] = triaBoxVertices.get(i).y * TEXTURE_SCALE;
            meshIndices[i] = (short) i;
        }

        Mesh mesh = new Mesh(true, triaBoxVertices.size(), triaBoxVertices.size(),
                new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE),
                new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
        mesh.setVertices(meshVertices);
        mesh.setIndices(meshIndices);
        meshes.add(mesh);
        boundingBoxes.add(mesh.calculateBoundingBox());
    }
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.VisibleObject.java

License:Open Source License

private void loadGraphics(Mesh mesh) {
    //mesh = Shapes.insertColour(mesh, colour);
    //mesh = Shapes.insertTangents(mesh);

    SubMesh[] meshes = { new StillSubMesh("SubMesh1", mesh, primitive_type) };
    model = new StillModel(meshes);

    Material material = new Material("basic");
    material.setColour(colour);/*w  w  w.j a  v  a2 s  . c  o m*/
    material.setTexture(texture);
    material.create();

    BoundingBox box = mesh.calculateBoundingBox();

    attributes = new StillModelAttributes(material,
            (box.getDimensions().x > box.getDimensions().z) ? box.getDimensions().x : box.getDimensions().z,
            scale, box.getDimensions());

    disposed = false;
}