Android Open Source - TinyVoxel Box






From Project

Back to project page TinyVoxel.

License

The source code is released under:

GNU General Public License

If you think the Android project TinyVoxel listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.toet.TinyVoxel.Util;
//from   ww  w .j av  a2s  . c o  m
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.collision.BoundingBox;
import com.toet.TinyVoxel.Shaders.ShaderManager;

import java.nio.FloatBuffer;

/**
 * Created by Kajos on 9/13/2014.
 */
public class Box {
    private static Box INSTANCE = null;

    public static Box get() {
        if (INSTANCE == null)
            INSTANCE = new Box();

        return INSTANCE;
    }

    Mesh mesh;
    ShaderProgram shader;

    public static final boolean[] CUBE = {

            // x-
            false,false,false,
            false,false, true,
            false, true, true,

            false,false,false,
            false, true, true,
            false, true,false,

            // x+
            true, true, true,
            true,false,false,
            true, true,false,

            true,false,false,
            true, true, true,
            true,false, true,

            // y-
            true,false, true,
            false,false, true,
            false,false,false,

            true,false, true,
            false,false,false,
            true,false,false,

            // y+
            true, true, true,
            true, true,false,
            false, true,false,

            true, true, true,
            false, true,false,
            false, true, true,

            // z-
            true, true,false,
            false,false,false,
            false, true,false,

            true, true,false,
            true,false,false,
            false,false,false,

            // z+
            true, true, true,
            false, true, true,
            true, false, true,

            false, true, true,
            false, false, true,
            true,false, true,
    };

    public Box() {
        mesh = new Mesh(Mesh.VertexDataType.VertexBufferObject, true, CUBE.length / 3, 0, createAttributes());
        FloatBuffer vertices = mesh.getVerticesBuffer();
        vertices.rewind();
        vertices.limit(CUBE.length);
        for (int i = 0; i < CUBE.length; i += 3) {
            if (CUBE[i])
                vertices.put(1f);
            else
                vertices.put(0f);

            if (CUBE[i + 1])
                vertices.put(1f);
            else
                vertices.put(0f);

            if (CUBE[i + 2])
                vertices.put(1f);
            else
                vertices.put(0f);
        }

        vertices.rewind();

        shader = ShaderManager.get().getShader("shaders/BoxFragment.glsl", "shaders/BoxVertex.glsl");
    }

    protected VertexAttribute[] createAttributes() {
        VertexAttribute attr = new VertexAttribute(VertexAttributes.Usage.Position, 3, "position");
        return new VertexAttribute[] { attr };
    }

    public void begin(PerspectiveCamera camera) {
        shader.begin();
        shader.setUniformMatrix("cameraTrans", camera.combined);
    }

    public void render(Matrix4 dimensions) {
        shader.setUniformMatrix("modelTrans", dimensions);
        mesh.render(shader, GL20.GL_LINES);
    }

    Matrix4 tmp = new Matrix4();
    Matrix4 tmp2 = new Matrix4();
    public void render(BoundingBox dimensions, Matrix4 transform, Color color) {
        tmp2.idt();
        tmp2.translate(dimensions.getMin());
        tmp2.scl(dimensions.getDimensions());

        tmp.set(transform);

        tmp.mul(tmp2);

        shader.setUniformMatrix("modelTrans", tmp);
        shader.setUniformf("color", color);
        mesh.render(shader, GL20.GL_TRIANGLES);
    }

    public void end() {
        shader.end();
    }
}




Java Source Code List

com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration.java
com.badlogic.gdx.backends.gwt.GwtApplication.java
com.badlogic.gdx.backends.gwt.GwtGL20.java
com.badlogic.gdx.backends.gwt.GwtInput.java
com.badlogic.gdx.backends.gwt.GwtNet.java
com.badlogic.gdx.graphics.Pixmap.java
com.toet.TinyVoxel.Config.java
com.toet.TinyVoxel.Game.java
com.toet.TinyVoxel.IOSConfig.java
com.toet.TinyVoxel.IOSLauncher.java
com.toet.TinyVoxel.OuyaController.java
com.toet.TinyVoxel.Time.java
com.toet.TinyVoxel.Character.Character.java
com.toet.TinyVoxel.Debug.LogHandler.java
com.toet.TinyVoxel.GameControllers.CharacterController.java
com.toet.TinyVoxel.GameControllers.CustomTouchPad.java
com.toet.TinyVoxel.GameControllers.KeyBoardController.java
com.toet.TinyVoxel.GameControllers.TouchPadController.java
com.toet.TinyVoxel.Importer.BinvoxImporter.java
com.toet.TinyVoxel.Importer.DataInputStream.java
com.toet.TinyVoxel.Importer.MeshImporter.java
com.toet.TinyVoxel.Renderer.BlockBuilder.java
com.toet.TinyVoxel.Renderer.Floor.java
com.toet.TinyVoxel.Renderer.Manager.java
com.toet.TinyVoxel.Renderer.Bundles.ArrayBundle.java
com.toet.TinyVoxel.Renderer.Bundles.Bundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridBundle.java
com.toet.TinyVoxel.Renderer.Bundles.GridInterface.java
com.toet.TinyVoxel.Renderer.Bundles.Grid.java
com.toet.TinyVoxel.Renderer.Bundles.GroundBundle.java
com.toet.TinyVoxel.Renderer.Bundles.SingleBundle.java
com.toet.TinyVoxel.Renderer.Bundles.TinyGrid.java
com.toet.TinyVoxel.Renderer.Tools.BrushUtils.java
com.toet.TinyVoxel.Renderer.Tools.GridUtils.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedBoolean.java
com.toet.TinyVoxel.Renderer.Wrapped.WrappedInteger.java
com.toet.TinyVoxel.Screens.GUI.java
com.toet.TinyVoxel.Screens.Menu.java
com.toet.TinyVoxel.Shaders.ShaderManager.java
com.toet.TinyVoxel.Shadow.ShadowManager.java
com.toet.TinyVoxel.Util.Box.java
com.toet.TinyVoxel.Util.FullscreenQuad.java
com.toet.TinyVoxel.Util.JobManager.java
com.toet.TinyVoxel.Util.NonBackedTexture.java
com.toet.TinyVoxel.Util.Position.java
com.toet.TinyVoxel.Util.RLEInputStream.java
com.toet.TinyVoxel.Util.RLEOutputStream.java
com.toet.TinyVoxel.Util.SimpleMath.java
com.toet.TinyVoxel.Util.StreamUtil.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidConfig.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.android.AndroidLauncher.java
com.toet.TinyVoxel.client.GwtConfig.java
com.toet.TinyVoxel.client.HtmlLauncher.java
com.toet.TinyVoxel.desktop.DesktopConfig.java
com.toet.TinyVoxel.desktop.DesktopLauncher.java