codechicken.lib.vec.Transformation Java Examples

The following examples show how to use codechicken.lib.vec.Transformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextureArea.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Transformation createOrientation(Size areaSize, int orientation) {
    Transformation transformation = new Rotation(Math.toRadians(orientation * 90.0), 0.0, 0.0, 1.0)
        .at(new Vector3(areaSize.width / 2.0, areaSize.height / 2.0, 0.0));
    Size orientedSize = transformSize(transformation, areaSize);
    double offsetX = (areaSize.width - orientedSize.width) / 2.0;
    double offsetY = (areaSize.height - orientedSize.height) / 2.0;
    return transformation.with(new Translation(-offsetX, -offsetY, 0.0));
}
 
Example #2
Source File: TextureArea.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Size transformSize(Transformation transformation, Size position) {
    Vector3 sizeVector = new Vector3(position.width, position.height, 0.0);
    Vector3 zeroVector = new Vector3(0.0, 0.0, 0.0);
    transformation.apply(zeroVector);
    transformation.apply(sizeVector);
    sizeVector.subtract(zeroVector);
    return new Size((int) Math.abs(sizeVector.x), (int) Math.abs(sizeVector.y));
}
 
Example #3
Source File: TextureArea.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public void drawRotated(int x, int y, Size areaSize, PositionedRect positionedRect, int orientation) {
    Transformation transformation = createOrientation(areaSize, orientation);
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, 0.0f);
    transformation.glApply();
    draw(positionedRect.position.x, positionedRect.position.y, positionedRect.size.width, positionedRect.size.height);
    GlStateManager.popMatrix();
}
 
Example #4
Source File: CCRenderState.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean load() {
    lcRef = model.getAttributes(this);
    if(model.hasAttribute(this))
        return lcRef != null;

    pos.set(lightMatrix.pos.x, lightMatrix.pos.y, lightMatrix.pos.z);
    pipeline.addDependency(sideAttrib);
    pipeline.addRequirement(Transformation.operationIndex);
    return true;
}
 
Example #5
Source File: GridConnection.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Position computePosition() {
    Transformation orientation = TextureArea.createOrientation(parentElementSize, parentOrientation.rotationValue);
    PositionedRect parentRect = TextureArea.transformRect(orientation, parentElementRect);
    switch (getOrientation()) {
        case LEFT: return new Position(0, connectionOffset);
        case RIGHT: return new Position(parentRect.position.x + parentRect.size.width, connectionOffset);
        case TOP: return new Position(connectionOffset, 0);
        case BOTTOM: return new Position(connectionOffset, parentRect.position.y + parentRect.size.height);
        default: return Position.ORIGIN;
    }
}
 
Example #6
Source File: LightCoordAttribute.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean load(CCRenderState ccrs) {
    lcRef = ccrs.model.getAttributes(attributeKey);
    if (ccrs.model.hasAttribute(attributeKey)) {
        return lcRef != null;
    }

    pos.set(ccrs.lightMatrix.pos);
    ccrs.pipeline.addDependency(ccrs.sideAttrib);
    ccrs.pipeline.addRequirement(Transformation.operationIndex);
    return true;
}
 
Example #7
Source File: RenderWireless.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void renderWorld(WirelessPart p) {
    CCRenderState.setBrightness(p.world(), p.x(), p.y(), p.z());

    Transformation t = new Translation(p.x(), p.y(), p.z());
    CCRenderState.setPipeline(p.rotationT().at(center).with(t), base_icont[p.textureSet()], rlm);
    BlockRenderer.renderCuboid(p.baseRenderBounds, p.baseRenderMask);
    models[p.modelId()][p.side() << 2 | p.rotation()].render(t, model_icont);
}
 
Example #8
Source File: Vertex5.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Vertex5 apply(Transformation t) {
    vec.apply(t);
    return this;
}
 
Example #9
Source File: WirelessPart.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public Transformation getPearlRotation() {
    return new RedundantTransformation();
}
 
Example #10
Source File: WirelessPart.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public Transformation rotationT() {
    return sideOrientation(side(), rotation());
}
 
Example #11
Source File: ReceiverPart.java    From WirelessRedstone with MIT License 4 votes vote down vote up
@Override
public Transformation getPearlRotation()
{
    return new Rotation(0.7854, 1, 0, 0);
}
 
Example #12
Source File: TileCraftingGridRenderer.java    From Translocators with MIT License 4 votes vote down vote up
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f)
{
    TileCraftingGrid tcraft = (TileCraftingGrid)tile;
    
    TextureUtils.bindAtlas(0);
    IIcon icon = Translocator.blockCraftingGrid.gridIcon;
    Tessellator t = Tessellator.instance;
    t.setTranslation(x, y+0.001, z);
    t.startDrawingQuads();
    t.setNormal(0, 1, 0);
    t.addVertexWithUV(1, 0, 0, icon.getMinU(), icon.getMinV());
    t.addVertexWithUV(0, 0, 0, icon.getMinU(), icon.getMaxV());
    t.addVertexWithUV(0, 0, 1, icon.getMaxU(), icon.getMaxV());
    t.addVertexWithUV(1, 0, 1, icon.getMaxU(), icon.getMinV());
    t.draw();
    t.setTranslation(0, 0, 0);

    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glPushMatrix();
    GL11.glTranslated(x+0.5, y, z+0.5);
    Transformation orient = Rotation.quarterRotations[tcraft.rotation];

    for(int i = 0; i < 9; i++)
    {
        ItemStack item = tcraft.items[i];
        if(item == null)
            continue;
        
        int row = i/3;
        int col = i%3;

        Vector3 pos = new Vector3((col-1)*5/16D, 0.1+0.01*Math.sin(i*1.7+ClientUtils.getRenderTime()/5), (row-1)*5/16D).apply(orient);
        GL11.glPushMatrix();
        GL11.glTranslated(pos.x, pos.y, pos.z);
        GL11.glScaled(0.5, 0.5, 0.5);

        RenderUtils.renderItemUniform(item);

        GL11.glPopMatrix();
    }
    
    if(tcraft.result != null)
    {
        GL11.glPushMatrix();
        GL11.glTranslated(0, 0.6 + 0.02 * Math.sin(ClientUtils.getRenderTime() / 10), 0);
        GL11.glScaled(0.8, 0.8, 0.8);

        RenderUtils.renderItemUniform(tcraft.result, ClientUtils.getRenderTime());
        
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
 
Example #13
Source File: TransformingVertexBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public TransformingVertexBuilder(IVertexBuilder delegate, Transformation transform) {
    this.delegate = delegate;
    this.transform = transform;
}
 
Example #14
Source File: TextureArea.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Position transformPos(Transformation transformation, Position position) {
    Vector3 vector = new Vector3(position.x, position.y, 0.0);
    transformation.apply(vector);
    return new Position((int) vector.x, (int) vector.y);
}
 
Example #15
Source File: TextureArea.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static PositionedRect transformRect(Transformation transformation, PositionedRect positionedRect) {
    Position pos1 = transformPos(transformation, positionedRect.position);
    Position pos2 = transformPos(transformation, positionedRect.position.add(positionedRect.size));
    return new PositionedRect(pos1, pos2);
}
 
Example #16
Source File: OBJParser.java    From CodeChickenLib with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Parses vertices, texture coords, normals and polygons from a WaveFront Obj file
 *
 * @param res         The resource for the obj file
 * @param vertexMode  The vertex mode to create the model for (GL_TRIANGLES or GL_QUADS)
 * @param coordSystem The cooridnate system transformation to apply
 * @return A map of group names to models
 */
public static Map<String, CCModel> parseModels(ResourceLocation res, int vertexMode, Transformation coordSystem) {
    try (IResource resource = Minecraft.getInstance().getResourceManager().getResource(res)) {
        return parseModels(resource.getInputStream(), vertexMode, coordSystem);
    } catch (Exception e) {
        throw new RuntimeException("failed to load model: " + res, e);
    }
}
 
Example #17
Source File: OBJParser.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Parses vertices, texture coords, normals and polygons from a WaveFront Obj file
 *
 * @param res         The resource for the obj file
 * @param coordSystem The cooridnate system transformation to apply
 * @return A map of group names to models
 */
public static Map<String, CCModel> parseModels(ResourceLocation res, Transformation coordSystem) {
    return parseModels(res, 4, coordSystem);
}