Search in sources :

Example 1 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityFluidPipe method getOBJState.

@Override
public OBJState getOBJState() {
    byte connections = getConnectionByte();
    String key = getRenderCacheKey();
    if (!cachedOBJStates.containsKey(key)) {
        ArrayList<String> parts = new ArrayList();
        //new Matrix4();
        Matrix4 rotationMatrix = new Matrix4(TRSRTransformation.identity().getMatrix());
        //			if(pipeCover!=null)
        //				parts.add("cover");
        int totalConnections = Integer.bitCount(connections);
        boolean straightY = (connections & 3) == 3;
        boolean straightZ = (connections & 12) == 12;
        boolean straightX = (connections & 48) == 48;
        switch(totalConnections) {
            case //stub
            0:
                parts.add("center");
                break;
            case //stopper
            1:
                parts.add("stopper");
                //default: y-
                if (//y+
                (connections & 2) != 0)
                    rotationMatrix.rotate(Math.PI, 0, 0, 1);
                else if (//z-
                (connections & 4) != 0)
                    rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                else if (//z+
                (connections & 8) != 0)
                    rotationMatrix.rotate(-Math.PI / 2, 1, 0, 0);
                else if (//x-
                (connections & 16) != 0)
                    rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                else if (//x+
                (connections & 32) != 0)
                    rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                parts.add("con_yMin");
                break;
            case //straight or curve
            2:
                if (straightY) {
                    parts.add("pipe_y");
                    if (getConnectionStyle(0) == 1)
                        parts.add("con_yMin");
                    if (getConnectionStyle(1) == 1)
                        parts.add("con_yMax");
                } else if (straightZ) {
                    parts.add("pipe_z");
                    if (getConnectionStyle(2) == 1)
                        parts.add("con_zMin");
                    if (getConnectionStyle(3) == 1)
                        parts.add("con_zMax");
                } else if (straightX) {
                    parts.add("pipe_x");
                    if (getConnectionStyle(4) == 1)
                        parts.add("con_xMin");
                    if (getConnectionStyle(5) == 1)
                        parts.add("con_xMax");
                } else {
                    parts.add("curve");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    byte connectTo = (byte) (connections & 60);
                    if (//curve to top or bottom
                    (connections & 3) != 0) {
                        if (//x-
                        connectTo == 16)
                            rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                        else if (//x+
                        connectTo == 32)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 1, 0);
                        else if (//z+
                        connectTo == 8)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        if (//flip to top
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to z-
                    } else //curve to horizontal
                    {
                        rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        if (//z+ to x+
                        connectTo == 40)
                            rotationMatrix.rotate(Math.PI, 1, 0, 0);
                        else if (//z+ to x-
                        connectTo == 24)
                            rotationMatrix.rotate(-Math.PI / 2, 1, 0, 0);
                        else if (//z- to x+
                        connectTo == 36)
                            rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                    //default: z- to x-
                    }
                }
                break;
            case //tcross or tcurve
            3:
                if (//has straight connect
                straightX || straightZ || straightY) {
                    parts.add("tcross");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    parts.add("con_zMax");
                    if (straightX) {
                        rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                        if (//z-
                        (connections & 4) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        else if (//z+
                        (connections & 8) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        else if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to y-
                    } else if (straightY) {
                        rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        else if (//x+
                        (connections & 32) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        else if (//z+
                        (connections & 8) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to z-
                    } else //default:z straight
                    {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                        else if (//x+
                        (connections & 32) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        else if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 0, 1);
                    //default: Curve to y-
                    }
                } else //tcurve
                {
                    parts.add("tcurve");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    parts.add("con_xMax");
                    //default y-, z-, x+
                    if (//z+
                    (connections & 8) != 0) {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        else
                            rotationMatrix.rotate(-Math.PI / 2, 0, 1, 0);
                    } else //z-
                    {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                    }
                    if (//y+
                    (connections & 2) != 0)
                        rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                }
                break;
            case //cross or complex tcross
            4:
                boolean cross = (straightX && straightZ) || (straightX && straightY) || (straightZ && straightY);
                if (cross) {
                    parts.add("cross");
                    parts.add("con_yMin");
                    parts.add("con_yMax");
                    parts.add("con_zMin");
                    parts.add("con_zMax");
                    if (//x and z
                    !straightY)
                        rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                    else if (//x and y
                    straightX)
                        rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                } else {
                    parts.add("tcross2");
                    parts.add("con_yMin");
                    parts.add("con_zMin");
                    parts.add("con_zMax");
                    parts.add("con_xMax");
                    if (straightZ) {
                        //default y- z+- x+
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                    } else if (straightY) {
                        rotationMatrix.rotate(Math.PI / 2, 1, 0, 0);
                        //default y+- z- x+
                        if (//z+
                        (connections & 8) != 0) {
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                            if (//x-
                            (connections & 16) != 0)
                                rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                        } else if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(-Math.PI / 2, 0, 0, 1);
                    } else {
                        rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                        //default y- z- x+-
                        if (//z+
                        (connections & 8) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                        if (//y+
                        (connections & 2) != 0)
                            rotationMatrix.rotate(Math.PI / 2, 0, 0, 1);
                    }
                }
                break;
            case //complete tcross
            5:
                parts.add("tcross3");
                parts.add("con_yMin");
                parts.add("con_yMax");
                parts.add("con_zMin");
                parts.add("con_zMax");
                parts.add("con_xMax");
                //default y+- z+- x+
                if (straightZ) {
                    if (straightY) {
                        if (//x-
                        (connections & 16) != 0)
                            rotationMatrix.rotate(Math.PI, 0, 1, 0);
                    } else if (straightX)
                        rotationMatrix.rotate(((connections & 2) != 0) ? (Math.PI / 2) : (-Math.PI / 2), 0, 0, 1);
                } else if (straightX) {
                    rotationMatrix.rotate(Math.PI / 2, 0, 1, 0);
                    if (//z+
                    (connections & 8) != 0)
                        rotationMatrix.rotate(Math.PI, 0, 1, 0);
                }
                break;
            case //Full Crossing
            6:
                parts.add("con_yMin");
                parts.add("con_yMax");
                parts.add("con_zMin");
                parts.add("con_zMax");
                parts.add("con_xMin");
                parts.add("con_xMax");
                break;
        }
        //			connetionParts
        //			for(int i=0; i<6; i++)
        //				if(((TileEntityFluidPipe)tile).getConnectionStyle(i)==1)
        //					connectionCaps.add(CONNECTIONS[i]);
        Matrix4 tempMatr = new Matrix4();
        tempMatr.m03 = tempMatr.m13 = tempMatr.m23 = .5f;
        rotationMatrix.leftMultiply(tempMatr);
        tempMatr.invert();
        rotationMatrix = rotationMatrix.multiply(tempMatr);
        cachedOBJStates.put(key, new OBJState(parts, true, new TRSRTransformation(rotationMatrix.toMatrix4f())));
    }
    return cachedOBJStates.get(key);
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 2 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class ClientEventHandler method drawBlockOverlayArrow.

public static void drawBlockOverlayArrow(Tessellator tessellator, VertexBuffer vertexbuffer, Vec3d directionVec, EnumFacing side, AxisAlignedBB targetedBB) {
    Vec3d[] translatedPositions = new Vec3d[arrowCoords.length];
    Matrix4 mat = new Matrix4();
    Vec3d defaultDir = side.getAxis() == Axis.Y ? new Vec3d(0, 0, 1) : new Vec3d(0, 1, 0);
    directionVec = directionVec.normalize();
    double angle = Math.acos(defaultDir.dotProduct(directionVec));
    Vec3d axis = defaultDir.crossProduct(directionVec);
    mat.rotate(angle, axis.xCoord, axis.yCoord, axis.zCoord);
    if (side != null) {
        if (side.getAxis() == Axis.Z)
            mat.rotate(Math.PI / 2, 1, 0, 0).rotate(Math.PI, 0, 1, 0);
        else if (side.getAxis() == Axis.X)
            mat.rotate(Math.PI / 2, 0, 0, 1).rotate(Math.PI / 2, 0, 1, 0);
    }
    for (int i = 0; i < translatedPositions.length; i++) {
        Vec3d vec = mat.apply(new Vec3d(arrowCoords[i][0], 0, arrowCoords[i][1])).addVector(.5, .5, .5);
        if (side != null && targetedBB != null)
            vec = new Vec3d(side == EnumFacing.WEST ? targetedBB.minX - .002 : side == EnumFacing.EAST ? targetedBB.maxX + .002 : vec.xCoord, side == EnumFacing.DOWN ? targetedBB.minY - .002 : side == EnumFacing.UP ? targetedBB.maxY + .002 : vec.yCoord, side == EnumFacing.NORTH ? targetedBB.minZ - .002 : side == EnumFacing.SOUTH ? targetedBB.maxZ + .002 : vec.zCoord);
        translatedPositions[i] = vec;
    }
    vertexbuffer.begin(6, DefaultVertexFormats.POSITION_COLOR);
    for (Vec3d point : translatedPositions) vertexbuffer.pos(point.xCoord, point.yCoord, point.zCoord).color(Lib.COLOUR_F_ImmersiveOrange[0], Lib.COLOUR_F_ImmersiveOrange[1], Lib.COLOUR_F_ImmersiveOrange[2], 0.4F).endVertex();
    tessellator.draw();
    vertexbuffer.begin(2, DefaultVertexFormats.POSITION_COLOR);
    for (Vec3d point : translatedPositions) vertexbuffer.pos(point.xCoord, point.yCoord, point.zCoord).color(0, 0, 0, 0.4F).endVertex();
    tessellator.draw();
}
Also used : Vec3d(net.minecraft.util.math.Vec3d) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 3 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityFloodlight method updateFakeLights.

public void updateFakeLights(boolean deleteOld, boolean genNew) {
    Iterator<BlockPos> it = this.fakeLights.iterator();
    ArrayList<BlockPos> tempRemove = new ArrayList<BlockPos>();
    while (it.hasNext()) {
        BlockPos cc = it.next();
        TileEntity te = world.getTileEntity(cc);
        if (te instanceof TileEntityFakeLight) {
            if (deleteOld)
                tempRemove.add(cc);
        } else
            it.remove();
    }
    if (genNew) {
        float angle = (float) (facing == EnumFacing.NORTH ? 180 : facing == EnumFacing.EAST ? 90 : facing == EnumFacing.WEST ? -90 : 0);
        float yRotation = rotY;
        double angleX = Math.toRadians(rotX);
        Vec3d[] rays = { /*Straight*/
        new Vec3d(0, 0, 1), /*U,D,L,R*/
        new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), /*Intermediate*/
        new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), /*Diagonal*/
        new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1) };
        Matrix4 mat = new Matrix4();
        if (side == EnumFacing.DOWN)
            mat.scale(1, -1, 1);
        else if (side != EnumFacing.UP) {
            angle = facing == EnumFacing.DOWN ? 180 : facing == EnumFacing.NORTH ? -90 : facing == EnumFacing.SOUTH ? 90 : angle;
            if (side.getAxis() == Axis.X) {
                mat.rotate(Math.PI / 2, -1, 0, 0);
                mat.rotate(Math.PI / 2, 0, 0, -side.getAxisDirection().getOffset());
            } else {
                mat.rotate(Math.PI / 2, -1, 0, 0);
                if (// I dunno why south is giving me so much trouble, but this works, so who cares
                side == EnumFacing.SOUTH) {
                    mat.rotate(Math.PI, 0, 0, 1);
                    if (facing.getAxis() == Axis.X)
                        angle = -angle;
                }
            }
        }
        double angleY = Math.toRadians(angle + yRotation);
        mat.rotate(angleY, 0, 1, 0);
        mat.rotate(-angleX, 1, 0, 0);
        rays[0] = mat.apply(rays[0]);
        mat.rotate(Math.PI / 8, 0, 1, 0);
        rays[1] = mat.apply(rays[1]);
        mat.rotate(-Math.PI / 16, 0, 1, 0);
        rays[5] = mat.apply(rays[5]);
        mat.rotate(-Math.PI / 8, 0, 1, 0);
        rays[6] = mat.apply(rays[6]);
        mat.rotate(-Math.PI / 16, 0, 1, 0);
        rays[2] = mat.apply(rays[2]);
        mat.rotate(Math.PI / 8, 0, 1, 0);
        mat.rotate(Math.PI / 8, 1, 0, 0);
        rays[3] = mat.apply(rays[3]);
        mat.rotate(-Math.PI / 16, 1, 0, 0);
        rays[7] = mat.apply(rays[7]);
        mat.rotate(-Math.PI / 8, 1, 0, 0);
        rays[8] = mat.apply(rays[8]);
        mat.rotate(-Math.PI / 16, 1, 0, 0);
        rays[4] = mat.apply(rays[4]);
        mat.rotate(Math.PI / 8, 1, 0, 0);
        mat.rotate(Math.PI / 16, 1, 0, 0);
        mat.rotate(Math.PI / 16, 0, 1, 0);
        rays[9] = mat.apply(rays[9]);
        mat.rotate(-Math.PI / 8, 0, 1, 0);
        rays[10] = mat.apply(rays[10]);
        mat.rotate(-Math.PI / 8, 1, 0, 0);
        rays[11] = mat.apply(rays[11]);
        mat.rotate(Math.PI / 8, 0, 1, 0);
        rays[12] = mat.apply(rays[12]);
        for (int ray = 0; ray < rays.length; ray++) {
            int offset = ray == 0 ? 0 : ray < 4 ? 3 : 1;
            placeLightAlongVector(rays[ray], offset, tempRemove);
        }
    }
    this.lightsToBeRemoved.addAll(tempRemove);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFakeLight(blusunrize.immersiveengineering.common.blocks.BlockFakeLight.TileEntityFakeLight) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 4 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityBreakerSwitch method applyTransformations.

@Override
public Optional<TRSRTransformation> applyTransformations(IBlockState object, String group, Optional<TRSRTransformation> transform) {
    Matrix4 mat = transform.isPresent() ? new Matrix4(transform.get().getMatrix()) : new Matrix4();
    mat = mat.translate(.5, 0, .5).rotate(Math.PI / 2 * rotation, 0, 1, 0).translate(-.5, 0, -.5);
    transform = Optional.of(new TRSRTransformation(mat.toMatrix4f()));
    return transform;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 5 with Matrix4

use of blusunrize.immersiveengineering.common.util.chickenbones.Matrix4 in project ImmersiveEngineering by BluSunrize.

the class TileEntityBreakerSwitch method getConnectionOffset.

@Override
public Vec3d getConnectionOffset(Connection con) {
    Matrix4 mat = new Matrix4(facing);
    mat.translate(.5, .5, 0).rotate(Math.PI / 2 * rotation, 0, 0, 1).translate(-.5, -.5, 0);
    if (endOfLeftConnection == null)
        calculateLeftConn(mat);
    boolean isLeft = con.end.equals(endOfLeftConnection) || con.start.equals(endOfLeftConnection);
    Vec3d ret = mat.apply(new Vec3d(isLeft ? .25 : .75, .5, .125));
    return ret;
}
Also used : Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)10 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)9 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)8 TileEntity (net.minecraft.tileentity.TileEntity)8 Vec3d (net.minecraft.util.math.Vec3d)8 Vector3f (org.lwjgl.util.vector.Vector3f)8 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)7 ItemStack (net.minecraft.item.ItemStack)7 Function (java.util.function.Function)6 IBlockState (net.minecraft.block.state.IBlockState)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 EnumFacing (net.minecraft.util.EnumFacing)6 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)5 ClientUtils (blusunrize.immersiveengineering.client.ClientUtils)5 Utils (blusunrize.immersiveengineering.common.util.Utils)5 List (java.util.List)5 Nullable (javax.annotation.Nullable)5 Minecraft (net.minecraft.client.Minecraft)5