Android Open Source - TinyVoxel Floor






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.Renderer;
//from   w ww. j av a  2  s.co  m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.Ray;
import com.toet.TinyVoxel.Config;
import com.toet.TinyVoxel.Shaders.ShaderManager;
import com.toet.TinyVoxel.Shadow.ShadowManager;

import static com.badlogic.gdx.graphics.GL20.GL_TRIANGLES;

/**
 * Created by Kajos on 8/10/2014.
 */
public class Floor {
    public float VERTICES[] = new float[] {
        -Config.FAR, 0f, Config.FAR,
            Config.FAR, 0f, Config.FAR,
        -Config.FAR, 0f, -Config.FAR,

        -Config.FAR, 0f, -Config.FAR,
            Config.FAR, 0f, Config.FAR,
            Config.FAR, 0f, -Config.FAR
    };

    Mesh mesh;
    ShaderProgram shader;

    Matrix4 model = new Matrix4();

    Texture texture;

    public Floor() {
        mesh = new Mesh(Mesh.VertexDataType.VertexBufferObject, true, VERTICES.length / 3, 0, createAttributes());
        mesh.getVerticesBuffer().rewind();
        mesh.getVerticesBuffer().limit(VERTICES.length);
        mesh.getVerticesBuffer().put(VERTICES);
        mesh.getVerticesBuffer().rewind();

        shader = ShaderManager.get().getShader("shaders/FloorFragment.glsl", "shaders/FloorVertex.glsl");

        texture = new Texture(Gdx.files.internal("textures/desert4.jpg"), true);
        texture.setFilter(Texture.TextureFilter.MipMap, Texture.TextureFilter.Nearest);
        texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);

        model.idt();
        model.setToScaling(.05f, 1f, .05f);
    }

    public boolean collidesPoint(Vector3 position) {
        return position.y < 0.0f;
    }

    public boolean collidesSphere(Vector3 position, float radius) {
        return position.y < radius;
    }

    public boolean collidesWith(Ray ray, Vector3 intersection, float maxDistance) {
        if (ray.direction.y > 0f)
            return false;

        float dist = ray.origin.y / -ray.direction.y;
        if (dist > maxDistance)
            return false;

        intersection.set(ray.direction);
        intersection.scl(dist);
        intersection.add(ray.origin);

        return true;
    }

    public void render(PerspectiveCamera camera, float lod) {
        shader.begin();
        shader.setUniformf("backgroundColor", Config.get().BACKGROUND_COLOR);
        shader.setUniformf("lod", lod);
        shader.setUniformf("cameraPos", camera.position);
        shader.setUniformMatrix("modelTrans", model);
        shader.setUniformMatrix("cameraTrans", camera.combined);
        shader.setUniformMatrix("shadowTrans", ShadowManager.get().depthBiasMatrix());
        texture.bind(0);
        shader.setUniformi("texture", 0);
        ShadowManager.get().getTexture().bind(1);
        shader.setUniformi("shadowTexture", 1);
        mesh.render(shader, GL_TRIANGLES, 0, VERTICES.length / 3);
        shader.end();
    }

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

    public void dispose() {
        shader.dispose();
        texture.dispose();
        mesh.dispose();
    }
}




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