Search in sources :

Example 11 with Vector3f

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

the class ConveyorCovered method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    ItemStack cover = this.cover != null ? this.cover : defaultCover;
    Block b = Block.getBlockFromItem(cover.getItem());
    IBlockState state = b != null ? b.getStateFromMeta(cover.getMetadata()) : Blocks.STONE.getDefaultState();
    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
    if (model != null) {
        TextureAtlasSprite sprite = model.getParticleTexture();
        HashMap<EnumFacing, TextureAtlasSprite> sprites = new HashMap<>();
        ConveyorDirection conDir = this.getConveyorDirection();
        for (EnumFacing f : EnumFacing.VALUES) for (BakedQuad q : model.getQuads(state, f, 0)) if (q != null && q.getSprite() != null)
            sprites.put(f, q.getSprite());
        for (BakedQuad q : model.getQuads(state, null, 0)) if (q != null && q.getSprite() != null && q.getFace() != null)
            sprites.put(q.getFace(), q.getSprite());
        Function<EnumFacing, TextureAtlasSprite> getSprite = f -> sprites.containsKey(f) ? sprites.get(f) : sprite;
        Function<EnumFacing, TextureAtlasSprite> getSpriteHorizontal = f -> f.getAxis() == Axis.Y ? null : sprites.containsKey(f) ? sprites.get(f) : sprite;
        float[] colour = { 1, 1, 1, 1 };
        Matrix4 matrix = new Matrix4(facing);
        boolean wallLeft = tile == null || this.renderWall(tile, facing, 0);
        boolean wallRight = tile == null || this.renderWall(tile, facing, 1);
        Function<Vector3f[], Vector3f[]> vertexTransformer = conDir == ConveyorDirection.HORIZONTAL ? vertices -> vertices : vertices -> {
            Vector3f[] ret = new Vector3f[vertices.length];
            for (int i = 0; i < ret.length; i++) ret[i] = new Vector3f(vertices[i].x, vertices[i].y + (vertices[i].z == (conDir == ConveyorDirection.UP ? 0 : 1) ? 1 : 0), vertices[i].z);
            return ret;
        };
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .75f, 0), new Vector3f(1, 1, 1), matrix, facing, vertexTransformer, getSprite, colour));
        if (wallLeft)
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
        else {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .9375f), new Vector3f(.0625f, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
        }
        if (wallRight)
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
        else {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, .9375f), new Vector3f(1, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
        }
    }
    return baseModel;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IEContent(blusunrize.immersiveengineering.common.IEContent) Blocks(net.minecraft.init.Blocks) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) HashMap(java.util.HashMap) Function(java.util.function.Function) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) OreDictionary(net.minecraftforge.oredict.OreDictionary) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) BlockTypes_WoodenDecoration(blusunrize.immersiveengineering.common.blocks.wooden.BlockTypes_WoodenDecoration) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) EnumFacing(net.minecraft.util.EnumFacing) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) BlockTypes_MetalDecoration1(blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration1) Axis(net.minecraft.util.EnumFacing.Axis) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Vector3f(org.lwjgl.util.vector.Vector3f) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 12 with Vector3f

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

the class ChunkSystem method checkRightClick.

public static final void checkRightClick() {
    final Vec3 block = BlockRaycast.placeCast();
    if (block != null) {
        final Chunk chunk = Chunk.getChunk((int) Math.floor(block.x / Chunk.H_SIZE), (int) Math.floor(block.z / Chunk.H_SIZE));
        if (chunk != null) {
            final Vector3f blockToSet = Chunk.getBlockCoordinates(block.x, block.y, block.z);
            chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] = new BlockModeled(BlockPlacement.getSelection());
            chunk.modified.put(new Vector3f((int) blockToSet.x, (int) blockToSet.y, (int) blockToSet.z), new ArrayList<>(Block.BLOCKS.values()).indexOf(BlockPlacement.getSelection()));
            {
                final int cx = chunk.x;
                final int cz = chunk.z;
                addToQueues(chunk);
                addToQueues(Chunk.getChunk(cx - 1, cz));
                addToQueues(Chunk.getChunk(cx + 1, cz));
                addToQueues(Chunk.getChunk(cx, cz - 1));
                addToQueues(Chunk.getChunk(cx, cz + 1));
            }
        }
    }
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) Vec3(org.asassecreations.engine.math.vector.Vec3) Vector3f(org.lwjgl.util.vector.Vector3f) ArrayList(java.util.ArrayList)

Example 13 with Vector3f

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

the class MovingSoundTest method execute.

/**
	 * Runs the actual test, using supplied arguments
	 */
protected void execute(String[] args) {
    if (args.length < 1) {
        System.out.println("no argument supplied, assuming Footsteps.wav");
        args = new String[] { "Footsteps.wav" };
    }
    try {
        setDisplayMode();
        Display.create();
    } catch (Exception e) {
        e.printStackTrace();
    }
    int lastError;
    Vector3f sourcePosition = new Vector3f();
    Vector3f listenerPosition = new Vector3f();
    //initialize keyboard
    try {
        Keyboard.create();
    } catch (Exception e) {
        e.printStackTrace();
        exit(-1);
    }
    //create 1 buffer and 1 source
    IntBuffer buffers = BufferUtils.createIntBuffer(1);
    IntBuffer sources = BufferUtils.createIntBuffer(1);
    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //load wave data
    WaveData wavefile = WaveData.create(args[0]);
    //copy to buffers
    AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //unload file again
    wavefile.dispose();
    //set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    AL10.alSourcef(sources.get(0), AL10.AL_REFERENCE_DISTANCE, 1024.0f);
    AL10.alSourcef(sources.get(0), AL10.AL_ROLLOFF_FACTOR, 0.5f);
    //lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    System.out.println("Move source with arrow keys\nMove listener with right shift and arrowkeys\nExit with ESC");
    while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Display.update();
        Keyboard.poll();
        if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
            if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
                listenerPosition.x -= MOVEMENT;
                AL10.alListener3f(AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
                System.out.println("listenerx: " + listenerPosition.x);
            } else {
                sourcePosition.x -= MOVEMENT;
                AL10.alSource3f(sources.get(0), AL10.AL_POSITION, sourcePosition.x, sourcePosition.y, sourcePosition.z);
                System.out.println("sourcex: " + sourcePosition.x);
            }
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
            if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
                listenerPosition.x += MOVEMENT;
                AL10.alListener3f(AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
                System.out.println("listenerx: " + listenerPosition.x);
            } else {
                sourcePosition.x += MOVEMENT;
                AL10.alSource3f(sources.get(0), AL10.AL_POSITION, sourcePosition.x, sourcePosition.y, sourcePosition.z);
                System.out.println("sourcex: " + sourcePosition.x);
            }
        }
        if (Display.isCloseRequested()) {
            break;
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException inte) {
        }
    }
    //stop source 0
    AL10.alSourceStop(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //delete buffers and sources
    sources.position(0).limit(1);
    AL10.alDeleteSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    buffers.position(0).limit(1);
    AL10.alDeleteBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //shutdown
    alExit();
}
Also used : Vector3f(org.lwjgl.util.vector.Vector3f) IntBuffer(java.nio.IntBuffer) WaveData(org.lwjgl.util.WaveData)

Example 14 with Vector3f

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

the class MouseTest method logic.

/**
   * Does the "model logic"
   */
private void logic() {
    // ===========================================
    for (Vector3f color : triangleColors) {
        color.x -= 0.01;
        color.y -= 0.01;
        color.z -= 0.01;
    }
    for (Vector3f color : quadColors) {
        color.x -= 0.01;
        color.y -= 0.01;
        color.z -= 0.01;
    }
// -------------------------------------------
}
Also used : Vector3f(org.lwjgl.util.vector.Vector3f)

Example 15 with Vector3f

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

the class ClientUtils method convertConnectionFromBlockstate.

public static List<BakedQuad>[] convertConnectionFromBlockstate(IExtendedBlockState s, TextureAtlasSprite t) {
    List<BakedQuad>[] ret = new List[2];
    ret[0] = new ArrayList<>();
    ret[1] = new ArrayList<>();
    Set<Connection> conns = s.getValue(IEProperties.CONNECTIONS);
    if (conns == null)
        return ret;
    Vector3f dir = new Vector3f();
    Vector3f cross = new Vector3f();
    Vector3f up = new Vector3f(0, 1, 0);
    BlockPos pos = null;
    for (Connection conn : conns) {
        if (pos == null)
            pos = conn.start;
        Vec3d[] f = conn.catenaryVertices;
        if (f == null || f.length < 1)
            continue;
        int color = conn.cableType.getColour(conn);
        float[] rgb = { (color >> 16 & 255) / 255f, (color >> 8 & 255) / 255f, (color & 255) / 255f, (color >> 24 & 255) / 255f };
        if (rgb[3] == 0)
            rgb[3] = 1;
        Vector3f start = new Vector3f(conn.start.getX(), conn.start.getY(), conn.start.getZ());
        float radius = (float) (conn.cableType.getRenderDiameter() / 2);
        List<Integer> crossings = new ArrayList<>();
        for (int i = 1; i < f.length; i++) if (crossesChunkBoundary(f[i], f[i - 1]))
            crossings.add(i);
        int index = crossings.size() / 2;
        boolean greater = conn.start.compareTo(conn.end) > 0;
        if (crossings.size() % 2 == 0 && greater)
            index--;
        int max = (crossings.size() > 0 ? (crossings.get(index) + (greater ? 1 : 2)) : (greater ? f.length + 1 : 0));
        for (int i = 1; i < max && i < f.length; i++) {
            boolean fading = i == max - 1;
            List<BakedQuad> curr = ret[fading ? 1 : 0];
            int j = i - 1;
            Vector3f here = new Vector3f((float) f[i].xCoord, (float) f[i].yCoord, (float) f[i].zCoord);
            Vector3f.sub(here, start, here);
            Vector3f there = new Vector3f((float) f[j].xCoord, (float) f[j].yCoord, (float) f[j].zCoord);
            Vector3f.sub(there, start, there);
            if (fading) {
                Vector3f.add(here, fadingOffset, here);
                Vector3f.add(there, fadingOffset, there);
            }
            boolean vertical = here.x == there.x && here.z == there.z;
            if (!vertical) {
                Vector3f.sub(here, there, dir);
                Vector3f.cross(up, dir, cross);
                cross.scale(radius / cross.length());
            } else
                cross.set(radius, 0, 0);
            Vector3f[] vertices = { Vector3f.add(here, cross, null), Vector3f.sub(here, cross, null), Vector3f.sub(there, cross, null), Vector3f.add(there, cross, null) };
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.DOWN, t, rgb, false, fading ? alphaFirst2Fading : alphaNoFading, pos));
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.UP, t, rgb, true, fading ? alphaFirst2Fading : alphaNoFading, pos));
            if (!vertical) {
                Vector3f.cross(cross, dir, cross);
                cross.scale(radius / cross.length());
            } else
                cross.set(0, 0, radius);
            vertices = new Vector3f[] { Vector3f.add(here, cross, null), Vector3f.sub(here, cross, null), Vector3f.sub(there, cross, null), Vector3f.add(there, cross, null) };
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.WEST, t, rgb, false, fading ? alphaFirst2Fading : alphaNoFading, pos));
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.EAST, t, rgb, true, fading ? alphaFirst2Fading : alphaNoFading, pos));
        }
    }
    return ret;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) Vec3d(net.minecraft.util.math.Vec3d) Vector3f(org.lwjgl.util.vector.Vector3f) BlockPos(net.minecraft.util.math.BlockPos)

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