Search in sources :

Example 1 with FloatHolder

use of org.asassecreations.engine.math.FloatHolder in project Voxel_Game by ASasseCreations.

the class Chunk method generateCube.

private float[][] generateCube(final BlockModeled b, final int x, final int y, final int z) {
    final FloatHolder vertexData = new FloatHolder();
    final FloatHolder textureData = new FloatHolder();
    final FloatHolder normalData = new FloatHolder();
    final FloatHolder lightingData = new FloatHolder();
    float[] topArray = null;
    if (b.top)
        topArray = new float[] { // 1, 1
        x + 1.0f, // 1, 1
        y + 1.0f, // 1, 1
        z + 1.0f, // 1, 0
        x + 1.0f, // 1, 0
        y + 1.0f, // 1, 0
        z + 0.0f, // 0, 0
        x + 0.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 0.0f, // 1, 1
        x + 1.0f, // 1, 1
        y + 1.0f, // 1, 1
        z + 1.0f, // 0, 0
        x + 0.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 0.0f, // 0, 1
        x + 0.0f, // 0, 1
        y + 1.0f, // 0, 1
        z + 1.0f };
    float[] bottomArray = null;
    if (b.bottom)
        bottomArray = new float[] { // 1, 0
        x + 1.0f, // 1, 0
        y + 0.0f, // 1, 0
        z + 1.0f, // 0, 1
        x + 0.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 0.0f, // 1, 1
        x + 1.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 0.0f, // 1, 0
        x + 1.0f, // 1, 0
        y + 0.0f, // 1, 0
        z + 1.0f, // 0, 0
        x + 0.0f, // 0, 0
        y + 0.0f, // 0, 0
        z + 1.0f, // 0, 1
        x + 0.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 0.0f };
    float[] leftArray = null;
    if (b.left)
        leftArray = new float[] { // 0, 1
        x + 0.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 0.0f, // 1, 1
        x + 0.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 1.0f, // 1, 0
        x + 0.0f, // 1, 0
        y + 1.0f, // 1, 0
        z + 1.0f, // 0, 1
        x + 0.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 0.0f, // 1, 0
        x + 0.0f, // 1, 0
        y + 1.0f, // 1, 0
        z + 1.0f, // 0, 0
        x + 0.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 0.0f };
    float[] rightArray = null;
    if (b.right)
        rightArray = new float[] { // 0, 0
        x + 1.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 1.0f, // 1, 1
        x + 1.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 0.0f, // 1, 0
        x + 1.0f, // 1, 0
        y + 1.0f, // 1, 0
        z + 0.0f, // 1, 1
        x + 1.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 0.0f, // 0, 0
        x + 1.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 1.0f, // 0, 1
        x + 1.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 1.0f };
    float[] frontArray = null;
    if (b.front)
        frontArray = new float[] { // 0, 0
        x + 0.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 1.0f, // 0, 1
        x + 0.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 1.0f, // 1, 1
        x + 1.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 1.0f, // 1, 0
        x + 1.0f, // 1, 0
        y + 1.0f, // 1, 0
        z + 1.0f, // 0, 0
        x + 0.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 1.0f, // 1, 1
        x + 1.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 1.0f };
    float[] backArray = null;
    if (b.back)
        backArray = new float[] { // 0, 0
        x + 1.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 0.0f, // 1, 1
        x + 0.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 0.0f, // 1, 0
        x + 0.0f, // 1, 0
        y + 1.0f, // 1, 0
        z + 0.0f, // 0, 0
        x + 1.0f, // 0, 0
        y + 1.0f, // 0, 0
        z + 0.0f, // 0, 1
        x + 1.0f, // 0, 1
        y + 0.0f, // 0, 1
        z + 0.0f, // 1, 1
        x + 0.0f, // 1, 1
        y + 0.0f, // 1, 1
        z + 0.0f };
    if (b.left)
        vertexData.add(leftArray);
    if (b.right)
        vertexData.add(rightArray);
    if (b.top)
        vertexData.add(topArray);
    if (b.bottom)
        vertexData.add(bottomArray);
    if (b.back)
        vertexData.add(backArray);
    if (b.front)
        vertexData.add(frontArray);
    if (b.left)
        textureData.add(b.preset.texture.left_uv);
    if (b.right)
        textureData.add(b.preset.texture.right_uv);
    if (b.top)
        textureData.add(b.preset.texture.top_uv);
    if (b.bottom)
        textureData.add(b.preset.texture.bottom_uv);
    if (b.back)
        textureData.add(b.preset.texture.back_uv);
    if (b.front)
        textureData.add(b.preset.texture.front_uv);
    if (b.left)
        normalData.add(ChunkModel.LEFT_NORMALS);
    if (b.right)
        normalData.add(ChunkModel.RIGHT_NORMALS);
    if (b.top)
        normalData.add(ChunkModel.TOP_NORMALS);
    if (b.bottom)
        normalData.add(ChunkModel.BOTTOM_NORMALS);
    if (b.back)
        normalData.add(ChunkModel.BACK_NORMALS);
    if (b.front)
        normalData.add(ChunkModel.FRONT_NORMALS);
    final float[] lightPerFace = new float[] { b.brightness, b.brightness, b.brightness, b.brightness, b.brightness, b.brightness };
    if (b.left)
        lightingData.add(lightPerFace);
    if (b.right)
        lightingData.add(lightPerFace);
    if (b.top)
        lightingData.add(lightPerFace);
    if (b.bottom)
        lightingData.add(lightPerFace);
    if (b.back)
        lightingData.add(lightPerFace);
    if (b.front)
        lightingData.add(lightPerFace);
    return new float[][] { vertexData.get(), textureData.get(), normalData.get(), lightingData.get() };
}
Also used : FloatHolder(org.asassecreations.engine.math.FloatHolder)

Example 2 with FloatHolder

use of org.asassecreations.engine.math.FloatHolder in project Voxel_Game by ASasseCreations.

the class Chunk method modelUpdate.

private void modelUpdate() {
    if (!generated)
        return;
    final FloatHolder positions = new FloatHolder();
    final FloatHolder textures = new FloatHolder();
    final FloatHolder normals = new FloatHolder();
    final FloatHolder lighting = new FloatHolder();
    for (int y = 0; y < V_SIZE; y++) {
        if (!layers[y])
            continue;
        for (int z = 0; z < H_SIZE; z++) for (int x = 0; x < H_SIZE; x++) {
            final BlockModeled b = blocks[x][y][z];
            if (b == null || !b.visible)
                continue;
            final float[][] data = generateCube(b, x, y, z);
            positions.add(data[0]);
            textures.add(data[1]);
            normals.add(data[2]);
            lighting.add(data[3]);
        }
    }
    ModelLoader.appendData(positions.get(), 3);
    ModelLoader.appendData(textures.get(), 2);
    ModelLoader.appendData(normals.get(), 3);
    ModelLoader.appendData(lighting.get(), 1);
    model = ModelLoader.loadToVAO(0);
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) FloatHolder(org.asassecreations.engine.math.FloatHolder)

Example 3 with FloatHolder

use of org.asassecreations.engine.math.FloatHolder in project Voxel_Game by ASasseCreations.

the class ChunkModel method getUVS.

public static final float[][] getUVS(final int x, final int y) {
    final FloatHolder _TOP_UV = TOP_UV.clone();
    final FloatHolder _BOTTOM_UV = BOTTOM_UV.clone();
    final FloatHolder _LEFT_UV = LEFT_UV.clone();
    final FloatHolder _RIGHT_UV = RIGHT_UV.clone();
    final FloatHolder _FRONT_UV = FRONT_UV.clone();
    final FloatHolder _BACK_UV = BACK_UV.clone();
    _TOP_UV.translate(x * SCALE, y * SCALE);
    _BOTTOM_UV.translate(x * SCALE, y * SCALE);
    _LEFT_UV.translate(x * SCALE, y * SCALE);
    _RIGHT_UV.translate(x * SCALE, y * SCALE);
    _FRONT_UV.translate(x * SCALE, y * SCALE);
    _BACK_UV.translate(x * SCALE, y * SCALE);
    final float[] top = _TOP_UV.get();
    final float[] bottom = _BOTTOM_UV.get();
    final float[] left = _LEFT_UV.get();
    final float[] right = _RIGHT_UV.get();
    final float[] front = _FRONT_UV.get();
    final float[] back = _BACK_UV.get();
    final float[][] data = { top, bottom, left, right, front, back };
    return data;
}
Also used : FloatHolder(org.asassecreations.engine.math.FloatHolder)

Example 4 with FloatHolder

use of org.asassecreations.engine.math.FloatHolder in project Voxel_Game by ASasseCreations.

the class ChunkModel method getTexture.

public static final void getTexture(final int scale) {
    SCALE = 1f / scale;
    TOP_UV = new FloatHolder(new float[] { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f });
    BOTTOM_UV = new FloatHolder(new float[] { 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f });
    LEFT_UV = new FloatHolder(new float[] { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f });
    RIGHT_UV = new FloatHolder(new float[] { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f });
    FRONT_UV = new FloatHolder(new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f });
    BACK_UV = new FloatHolder(new float[] { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f });
    TOP_UV.scale(SCALE, SCALE);
    BOTTOM_UV.scale(SCALE, SCALE);
    LEFT_UV.scale(SCALE, SCALE);
    RIGHT_UV.scale(SCALE, SCALE);
    FRONT_UV.scale(SCALE, SCALE);
    BACK_UV.scale(SCALE, SCALE);
}
Also used : FloatHolder(org.asassecreations.engine.math.FloatHolder)

Aggregations

FloatHolder (org.asassecreations.engine.math.FloatHolder)4 BlockModeled (org.asassecreations.voxelgame.world.block.BlockModeled)1