Java Code Examples for com.mojang.blaze3d.matrix.MatrixStack#translate()
The following examples show how to use
com.mojang.blaze3d.matrix.MatrixStack#translate() .
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: Render.java From XRay-Mod with GNU General Public License v3.0 | 7 votes |
static void renderBlocks(RenderWorldLastEvent event) { Vector3d view = XRay.mc.gameRenderer.getActiveRenderInfo().getProjectedView(); MatrixStack stack = event.getMatrixStack(); stack.translate(-view.x, -view.y, -view.z); // translate RenderSystem.pushMatrix(); RenderSystem.multMatrix(stack.getLast().getMatrix()); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); Profile.BLOCKS.apply(); // Sets GL state for block drawing syncRenderList.forEach(blockProps -> { buffer.begin( GL_LINES, DefaultVertexFormats.POSITION_COLOR ); renderBlockBounding(buffer, blockProps); tessellator.draw(); } ); Profile.BLOCKS.clean(); RenderSystem.popMatrix(); }
Example 2
Source File: BlockOverlayRender.java From MiningGadgets with MIT License | 5 votes |
public static void render(RenderWorldLastEvent event, ItemStack item) { final Minecraft mc = Minecraft.getInstance(); IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); int range = MiningProperties.getBeamRange(item); BlockRayTraceResult lookingAt = VectorHelper.getLookingAt(mc.player, RayTraceContext.FluidMode.NONE, range); if (mc.world.getBlockState(VectorHelper.getLookingAt(mc.player, item, range).getPos()) == Blocks.AIR.getDefaultState()) { return; } List<BlockPos> coords = MiningCollect.collect(mc.player, lookingAt, mc.world, MiningProperties.getRange(item)); Vec3d view = mc.gameRenderer.getActiveRenderInfo().getProjectedView(); MatrixStack matrix = event.getMatrixStack(); matrix.push(); matrix.translate(-view.getX(), -view.getY(), -view.getZ()); IVertexBuilder builder; builder = buffer.getBuffer(MyRenderType.BlockOverlay); coords.forEach(e -> { if (mc.world.getBlockState(e).getBlock() != ModBlocks.RENDER_BLOCK.get()) { matrix.push(); matrix.translate(e.getX(), e.getY(), e.getZ()); matrix.translate(-0.005f, -0.005f, -0.005f); matrix.scale(1.01f, 1.01f, 1.01f); matrix.rotate(Vector3f.YP.rotationDegrees(-90.0F)); Matrix4f positionMatrix = matrix.getLast().getMatrix(); BlockOverlayRender.render(positionMatrix, builder, e, Color.GREEN); matrix.pop(); } }); matrix.pop(); RenderSystem.disableDepthTest(); buffer.finish(MyRenderType.BlockOverlay); }
Example 3
Source File: RenderTileEnderChest.java From EnderStorage with MIT License | 5 votes |
public static void renderChest(CCRenderState ccrs, MatrixStack mStack, IRenderTypeBuffer getter, int rotation, double yToCamera, Frequency freq, float lidAngle, int pearlOffset) { Matrix4 mat = new Matrix4(mStack); if (lidAngle != 0) {//Micro optimization, lid closed, dont render starfield. renderEndPortal.render(mat, getter, yToCamera); } ccrs.reset(); mStack.push(); mStack.translate(0, 1.0, 1.0); mStack.scale(1.0F, -1.0F, -1.0F); mStack.translate(0.5, 0.5, 0.5); mStack.rotate(new Quaternion(0, rotation * 90, 0, true)); mStack.translate(-0.5, -0.5, -0.5); model.chestLid.rotateAngleX = lidAngle; model.render(mStack, getter.getBuffer(chestType), ccrs.brightness, ccrs.overlay, freq.hasOwner()); mStack.pop(); //Buttons ccrs.bind(buttonType, getter); EnumColour[] colours = freq.toArray(); for (int i = 0; i < 3; i++) { CCModel button = ButtonModelLibrary.button.copy(); button.apply(BlockEnderChest.buttonT[i]); button.apply(new Translation(0.5, 0, 0.5)); button.apply(new Rotation(lidAngle, 1, 0, 0).at(new Vector3(0, 9D / 16D, 1 / 16D))); button.apply(new Rotation((-90 * (rotation)) * MathHelper.torad, Vector3.Y_POS).at(new Vector3(0.5, 0, 0.5))); button.render(ccrs, mat, new UVTranslation(0.25 * (colours[i].getWoolMeta() % 4), 0.25 * (colours[i].getWoolMeta() / 4))); } mat.translate(0.5, 0, 0.5); //Pearl if (lidAngle != 0) {//Micro optimization, lid closed, dont render pearl. double time = ClientUtils.getRenderTime() + pearlOffset; Matrix4 pearlMat = RenderUtils.getMatrix(mat.copy(), new Vector3(0, 0.2 + lidAngle * -0.5 + RenderUtils.getPearlBob(time), 0), new Rotation(time / 3, new Vector3(0, 1, 0)), 0.04); ccrs.brightness = 15728880; ccrs.bind(pearlType, getter); CCModelLibrary.icosahedron4.render(ccrs, pearlMat); } ccrs.reset(); }
Example 4
Source File: CCRenderItem.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void renderItem(ItemStack stack, ItemCameraTransforms.TransformType transformType, boolean leftHand, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay, IBakedModel modelIn) { if (modelIn instanceof IItemRenderer) { mStack.push(); IBakedModel handled = ForgeHooksClient.handleCameraTransforms(mStack, modelIn, transformType, leftHand); mStack.translate(-0.5D, -0.5D, -0.5D); //If anyone doesnt return an IItemRenderer from here, your doing it wrong. ((IItemRenderer) handled).renderItem(stack, transformType, mStack, getter, packedLight, packedOverlay); mStack.pop(); } super.renderItem(stack, transformType, leftHand, mStack, getter, packedLight, packedOverlay, modelIn); }
Example 5
Source File: RenderMiningLaser.java From MiningGadgets with MIT License | 4 votes |
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) { Hand activeHand; if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) { activeHand = Hand.MAIN_HAND; } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) { activeHand = Hand.OFF_HAND; } else { return; } ItemStack stack = player.getHeldItem(activeHand); double distance = from.subtract(trace.getHitVec()).length(); long gameTime = player.world.getGameTime(); double v = gameTime * speedModifier; float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime); BufferBuilder wr = Tessellator.getInstance().getBuffer(); Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); MatrixStack matrix = event.getMatrixStack(); matrix.translate(view.getX(), view.getY(), view.getZ()); if( trace.getType() == RayTraceResult.Type.MISS ) matrix.translate(-from.x, -from.y, -from.z); RenderSystem.pushMatrix(); RenderSystem.multMatrix(matrix.getLast().getMatrix()); RenderSystem.enableColorMaterial(); // This makes it so we don't clip into the world, we're effectively drawing on it RenderSystem.disableDepthTest(); RenderSystem.enableBlend(); //This makes it so multiplayer doesn't matter which side the player is standing on to see someone elses laser RenderSystem.disableCull(); RenderSystem.enableTexture(); RenderSystem.rotatef(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw), 0, 1, 0); RenderSystem.rotatef(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch), 1, 0, 0); // additive laser beam RenderSystem.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RenderSystem.color4f(r, g, b, 0.7f); Minecraft.getInstance().getTextureManager().bindTexture(laserBeamGlow); drawBeam(xOffset, yOffset, zOffset, additiveThickness, activeHand, distance, wr, 0.5, 1, ticks); // main laser, colored part RenderSystem.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RenderSystem.color4f(r, g, b, 1.0f); Minecraft.getInstance().getTextureManager().bindTexture(laserBeam2); drawBeam(xOffset, yOffset, zOffset, thickness, activeHand, distance, wr, v, v + distance * 1.5, ticks); // white core RenderSystem.color4f(MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f, MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f, MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f, 1.0f); Minecraft.getInstance().getTextureManager().bindTexture(laserBeam); drawBeam(xOffset, yOffset, zOffset, thickness / 2, activeHand, distance, wr, v, v + distance * 1.5, ticks); RenderSystem.enableDepthTest(); RenderSystem.enableCull(); RenderSystem.popMatrix(); }
Example 6
Source File: RenderMiningLaser2.java From MiningGadgets with MIT License | 4 votes |
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) { Hand activeHand; if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) { activeHand = Hand.MAIN_HAND; } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) { activeHand = Hand.OFF_HAND; } else { return; } IVertexBuilder builder; ItemStack stack = player.getHeldItem(activeHand); double distance = from.subtract(trace.getHitVec()).length(); long gameTime = player.world.getGameTime(); double v = gameTime * speedModifier; float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime); float beam2r = MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f; float beam2g = MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f; float beam2b =MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f; Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); MatrixStack matrix = event.getMatrixStack(); matrix.push(); matrix.translate(-view.getX(), -view.getY(), -view.getZ()); matrix.translate(from.x, from.y, from.z); matrix.rotate(Vector3f.YP.rotationDegrees(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw))); matrix.rotate(Vector3f.XP.rotationDegrees(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch))); MatrixStack.Entry matrixstack$entry = matrix.getLast(); Matrix3f matrixNormal = matrixstack$entry.getNormal(); Matrix4f positionMatrix = matrixstack$entry.getMatrix(); //additive laser beam builder = buffer.getBuffer(MyRenderType.LASER_MAIN_ADDITIVE); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, additiveThickness, activeHand, distance, 0.5, 1, ticks, r,g,b,0.7f); //main laser, colored part builder = buffer.getBuffer(MyRenderType.LASER_MAIN_BEAM); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness, activeHand, distance, v, v + distance * 1.5, ticks, r,g,b,1f); //core builder = buffer.getBuffer(MyRenderType.LASER_MAIN_CORE); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness/2, activeHand, distance, v, v + distance * 1.5, ticks, beam2r,beam2g,beam2b,1f); matrix.pop(); RenderSystem.disableDepthTest(); buffer.finish(); }