Search in sources :

Example 1 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project lwjgl by LWJGL.

the class Gears method init.

/**
	 *
	 */
private void init() throws LWJGLException {
    final int WIDTH = 640;
    final int HEIGHT = 480;
    Display.setLocation((Display.getDisplayMode().getWidth() - WIDTH) / 2, (Display.getDisplayMode().getHeight() - HEIGHT) / 2);
    try {
        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
    } catch (PowerManagementEventException e) {
        e.printStackTrace();
    }
    Display.setTitle("Gears");
    Display.create(new PixelFormat());
    //glCoverageMaskNV(true);
    // setup ogl
    glViewport(0, 0, WIDTH, HEIGHT);
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    final Vector3f lp = new Vector3f(5.0f, 5.0f, 10.0f);
    lp.normalise();
    glLight(GL_LIGHT0, GL_POSITION, lp.getX(), lp.getY(), lp.getZ(), 0.0f);
    /* make the gears */
    gear1 = new Gear(gear(1.0f, 4.0f, 1.0f, 20, 0.7f), new float[] { 0.8f, 0.1f, 0.0f, 1.0f });
    gear2 = new Gear(gear(0.5f, 2.0f, 2.0f, 10, 0.7f), new float[] { 0.0f, 0.8f, 0.2f, 1.0f });
    gear3 = new Gear(gear(1.3f, 2.0f, 0.5f, 10, 0.7f), new float[] { 0.2f, 0.2f, 1.0f, 1.0f });
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    final float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -40.0f);
    vsh = new Shader(GL_VERTEX_SHADER, "uniform highp vec4 LIGHT_POS;\n" + "uniform highp mat4 MODEL_VIEW_PROJECTION_MATRIX;\n" + "uniform mediump mat3 NORMAL_MATRIX;\n" + "uniform lowp vec3 GEAR_COLOR;\n" + "attribute highp vec3 vPosition;\n" + "attribute mediump vec3 vNormal;\n" + "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_Position = MODEL_VIEW_PROJECTION_MATRIX * vec4(vPosition, 1.0);\n" + "\tvec3 normal = NORMAL_MATRIX * vNormal;\n" + "\tcolor = max(dot(normal, vec3(LIGHT_POS)), 0.0) * GEAR_COLOR + vec3(0.05);\n" + "}");
    fsh = new Shader(GL_FRAGMENT_SHADER, "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_FragColor = vec4(color, 1.0);\n" + "}");
    program = new ShaderProgram(vsh, fsh);
    program.enable();
    LIGHT_POS = program.getUniformLocation("LIGHT_POS");
    MVP = program.getUniformLocation("MODEL_VIEW_PROJECTION_MATRIX");
    NM = program.getUniformLocation("NORMAL_MATRIX");
    GEAR_COLOR = program.getUniformLocation("GEAR_COLOR");
    vPosition = program.getAttributeLocation("vPosition");
    vNormal = program.getAttributeLocation("vNormal");
    glEnableVertexAttribArray(vNormal);
    glEnableVertexAttribArray(vPosition);
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) ShaderProgram(org.lwjgl.test.opengles.util.ShaderProgram) Vector3f(org.lwjgl.util.vector.Vector3f) Shader(org.lwjgl.test.opengles.util.Shader)

Example 2 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method createBakedBox.

public static Set<BakedQuad> createBakedBox(Vector3f from, Vector3f to, Matrix4 matrix, EnumFacing facing, Function<Vector3f[], Vector3f[]> vertexTransformer, Function<EnumFacing, TextureAtlasSprite> textureGetter, float[] colour) {
    HashSet quads = new HashSet();
    if (vertexTransformer == null)
        vertexTransformer = v -> v;
    Vector3f[] vertices = { new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, from.y, to.z), new Vector3f(to.x, from.y, to.z), new Vector3f(to.x, from.y, from.z) };
    TextureAtlasSprite sprite = textureGetter.apply(EnumFacing.DOWN);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), sprite, new double[] { from.x * 16, 16 - from.z * 16, to.x * 16, 16 - to.z * 16 }, colour, true));
    for (Vector3f v : vertices) v.setY(to.y);
    sprite = textureGetter.apply(EnumFacing.UP);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), sprite, new double[] { from.x * 16, from.z * 16, to.x * 16, to.z * 16 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(to.x, to.y, from.z), new Vector3f(to.x, from.y, from.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
    sprite = textureGetter.apply(EnumFacing.NORTH);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), sprite, new double[] { from.x * 16, 16 - to.y * 16, to.x * 16, 16 - from.y * 16 }, colour, false));
    for (Vector3f v : vertices) v.setZ(to.z);
    sprite = textureGetter.apply(EnumFacing.SOUTH);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), sprite, new double[] { to.x * 16, 16 - to.y * 16, from.x * 16, 16 - from.y * 16 }, colour, true));
    vertices = new Vector3f[] { new Vector3f(from.x, to.y, to.z), new Vector3f(from.x, from.y, to.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
    sprite = textureGetter.apply(EnumFacing.WEST);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), sprite, new double[] { to.z * 16, 16 - to.y * 16, from.z * 16, 16 - from.y * 16 }, colour, true));
    for (Vector3f v : vertices) v.setX(to.x);
    sprite = textureGetter.apply(EnumFacing.EAST);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), sprite, new double[] { from.z * 16, 16 - to.y * 16, to.z * 16, 16 - from.y * 16 }, colour, false));
    return quads;
}
Also used : net.minecraft.util(net.minecraft.util) Normal(net.minecraftforge.client.model.obj.OBJModel.Normal) ModelBox(net.minecraft.client.model.ModelBox) AttenuationType(net.minecraft.client.audio.ISound.AttenuationType) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) ModelRenderer(net.minecraft.client.model.ModelRenderer) I18n(net.minecraft.client.resources.I18n) Vec3i(net.minecraft.util.math.Vec3i) Vec3d(net.minecraft.util.math.Vec3d) Lib(blusunrize.immersiveengineering.api.Lib) GL11(org.lwjgl.opengl.GL11) IEProperties(blusunrize.immersiveengineering.api.IEProperties) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Quat4d(javax.vecmath.Quat4d) Vector3f(org.lwjgl.util.vector.Vector3f) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) net.minecraft.client.renderer(net.minecraft.client.renderer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) java.util(java.util) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SmartLightingQuad(blusunrize.immersiveengineering.client.models.SmartLightingQuad) Function(java.util.function.Function) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) IEFluid(blusunrize.immersiveengineering.common.util.IEFluid) net.minecraft.block(net.minecraft.block) Minecraft(net.minecraft.client.Minecraft) Nonnull(javax.annotation.Nonnull) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Timer(net.minecraft.util.Timer) BlockPos(net.minecraft.util.math.BlockPos) TextureManager(net.minecraft.client.renderer.texture.TextureManager) ModelBase(net.minecraft.client.model.ModelBase) IETileSound(blusunrize.immersiveengineering.common.util.sound.IETileSound) IBlockState(net.minecraft.block.state.IBlockState) GuiScreen(net.minecraft.client.gui.GuiScreen) FontRenderer(net.minecraft.client.gui.FontRenderer) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Material(net.minecraft.block.material.Material) TileEntity(net.minecraft.tileentity.TileEntity) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 3 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project ImmersiveEngineering by BluSunrize.

the class ConveyorSplit method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    TextureAtlasSprite tex_casing0 = ClientUtils.getSprite(texture_casing);
    Matrix4 matrix = new Matrix4(facing);
    float[] colour = { 1, 1, 1, 1 };
    Vector3f[] vertices = { new Vector3f(.0625f, .1875f, 0), new Vector3f(.0625f, .1875f, 1), new Vector3f(.9375f, .1875f, 1), new Vector3f(.9375f, .1875f, 0) };
    baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), EnumFacing.UP, tex_casing0, new double[] { 1, 16, 15, 0 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(.0625f, 0, 0), new Vector3f(.0625f, .1875f, 0), new Vector3f(.9375f, .1875f, 0), new Vector3f(.9375f, 0, 0) };
    baseModel.set(15, ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, ClientUtils.getSprite(ModelConveyor.rl_casing[1]), new double[] { 1, 16, 15, 13 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(.0625f, .125f, 0), new Vector3f(.0625f, .1875f, 0), new Vector3f(.9375f, .1875f, 0), new Vector3f(.9375f, .125f, 0) };
    Vector3f[] vertices2 = new Vector3f[] { new Vector3f(.5f, .125f, 0), new Vector3f(.5f, .125f, .5f), new Vector3f(.5f, .1875f, .5f), new Vector3f(.5f, .1875f, 0) };
    Vector3f[] vertices3 = new Vector3f[] { new Vector3f(.5f, .125f, 0), new Vector3f(.5f, .125f, .5f), new Vector3f(.5f, .1875f, .5f), new Vector3f(.5f, .1875f, 0) };
    for (int i = 0; i < 8; i++) {
        for (int iv = 0; iv < vertices.length; iv++) {
            vertices[iv].setZ((i + 1) * .0625f);
            vertices2[iv].setX(vertices2[iv].getX() + .0625f);
            vertices3[iv].setX(vertices3[iv].getX() - .0625f);
        }
        double v = 16 - i;
        baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, tex_casing0, new double[] { 1, v - 1, 15, v }, colour, true));
        if (i < 7) {
            double u = 8 - i;
            baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices2), facing, tex_casing0, new double[] { u - 1, 16, u, 8 }, colour, true));
            baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices3), facing, tex_casing0, new double[] { u - 1, 16, u, 8 }, colour, false));
        }
    }
    return baseModel;
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project Voxel_Game by ASasseCreations.

the class Chunk method save.

public final boolean save() {
    if (operation == null || !operation.equals(ChunkOperation.SAVING)) {
        if (!generated)
            return true;
        System.out.println("CANT SAVE");
        return false;
    }
    if (modified.isEmpty())
        return true;
    final ADatabase database = new ADatabase("Chunk");
    final List<Block> list = new ArrayList<>(Block.BLOCKS.values());
    for (final Vector3f vector : modified.keySet()) {
        final int x = (int) vector.x;
        final int y = (int) vector.y;
        final int z = (int) vector.z;
        final BlockModeled block = blocks[x][y][z];
        final Block texture;
        int id;
        if (block == null || block.preset == null || block.preset.texture == null)
            id = -1;
        else {
            texture = block.preset;
            id = list.indexOf(texture);
        }
        final AObject object = new AObject(x + ":" + y + ":" + z);
        object.addField(AField.Integer("id", id));
        database.addObject(object);
    }
    database.serializeToFile(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat");
    System.out.println("Saved chunk at [" + x + ", " + z + "]");
    operation = null;
    return true;
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) Vector3f(org.lwjgl.util.vector.Vector3f) ArrayList(java.util.ArrayList) Block(org.asassecreations.voxelgame.world.block.Block) AObject(org.asassecreations.engine.serializer.AObject) ADatabase(org.asassecreations.engine.serializer.ADatabase)

Example 5 with Vector3f

use of org.lwjgl.util.vector.Vector3f in project Voxel_Game by ASasseCreations.

the class Chunk method load.

public final void load() {
    System.out.println("Loaded at [" + x + ", " + z + "]");
    final ADatabase database = ADatabase.DeserializeFromFile(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat");
    final List<AObject> modifications = database.objects;
    System.out.println(modifications.size());
    final List<Block> list = new ArrayList<>(Block.BLOCKS.values());
    for (final AObject object : modifications) {
        final String[] parsed = object.getName().split(":");
        final int x = Integer.parseInt(parsed[0]);
        final int y = Integer.parseInt(parsed[1]);
        final int z = Integer.parseInt(parsed[2]);
        final int id = object.findField("id").getInt();
        modified.put(new Vector3f(x, y, z), id);
        if (id == -1)
            blocks[x][y][z] = null;
        else
            blocks[x][y][z] = new BlockModeled(list.get(id));
    }
    System.out.println("Generated modifications chunk at [" + x + ", " + z + "]");
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) Vector3f(org.lwjgl.util.vector.Vector3f) ArrayList(java.util.ArrayList) Block(org.asassecreations.voxelgame.world.block.Block) AObject(org.asassecreations.engine.serializer.AObject) ADatabase(org.asassecreations.engine.serializer.ADatabase)

Aggregations

Vector3f (org.lwjgl.util.vector.Vector3f)15 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)5 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 ArrayList (java.util.ArrayList)4 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)3 IBlockState (net.minecraft.block.state.IBlockState)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 Utils (blusunrize.immersiveengineering.common.util.Utils)2 Function (java.util.function.Function)2 Block (net.minecraft.block.Block)2 Minecraft (net.minecraft.client.Minecraft)2 ADatabase (org.asassecreations.engine.serializer.ADatabase)2 AObject (org.asassecreations.engine.serializer.AObject)2 Block (org.asassecreations.voxelgame.world.block.Block)2 BlockModeled (org.asassecreations.voxelgame.world.block.BlockModeled)2 IEProperties (blusunrize.immersiveengineering.api.IEProperties)1 Lib (blusunrize.immersiveengineering.api.Lib)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1