Melonslise Posted August 19, 2018 Posted August 19, 2018 (edited) I'm trying to render a quad that always faces the player in the RenderWorldLastEvent. The code either fails to render completely or sometimes flickers in and out of view whenever the player moves. Can someone help? Edited August 20, 2018 by Melonslise Quote
Cadiboo Posted August 20, 2018 Posted August 20, 2018 7 hours ago, Melonslise said: I'm trying to render a quad that always faces the player in the RenderWorldLastEvent. The code either fails to render completely or sometimes flickers in and out of view whenever the player moves. Can someone help? Look at render snowball Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Melonslise Posted August 20, 2018 Author Posted August 20, 2018 (edited) 8 hours ago, Cadiboo said: Look at render snowball I tried adding and playing around with the code from RenderSnowball, but it gave really weird results. I also feel like the rotation code from RenderSnowball won't work with a long beam of sorts that I'm trying to make. Here's my code: public static void drawLine(double startX, double startY, double startZ, double endX, double endY, double endZ, int red, int green, int blue, int alpha, double width, float partialTick) { Minecraft mc = Minecraft.getMinecraft(); // TODO RenderPos from RenderManager double originX = mc.player.lastTickPosX + (mc.player.posX - mc.player.lastTickPosX) * (double) partialTick, originY = mc.player.lastTickPosY + (mc.player.posY - mc.player.lastTickPosY) * (double) partialTick, originZ = mc.player.lastTickPosZ + (mc.player.posZ - mc.player.lastTickPosZ) * (double) partialTick; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); GlStateManager.pushMatrix(); GlStateManager.disableCull(); GlStateManager.disableTexture2D(); GlStateManager.rotate(-mc.getRenderManager().playerViewY, 0F, 1F, 0F); GlStateManager.rotate(mc.getRenderManager().options.thirdPersonView == 2 ? -1F : 1F * mc.getRenderManager().playerViewX, 1F, 0F, 0F); GlStateManager.rotate(180F, 0F, 1F, 0F); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); buffer.pos(startX - originX, startY - originY - width / 2D, startZ - originZ).color(red, green, blue, alpha).endVertex(); buffer.pos(endX - originX, endY - originY - width / 2D, endZ - originZ).color(red, green, blue, alpha).endVertex(); buffer.pos(endX- originX, endY - originY + width / 2D, endZ - originZ).color(red, green, blue, alpha).endVertex(); buffer.pos(startX - originX, startY - originY + width / 2D, startZ - originZ).color(red, green, blue, alpha).endVertex(); tessellator.draw(); GlStateManager.enableTexture2D(); GlStateManager.enableCull(); GlStateManager.popMatrix(); } Edited August 20, 2018 by Melonslise Quote
Cadiboo Posted August 20, 2018 Posted August 20, 2018 What exactly are you trying to do? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Melonslise Posted August 20, 2018 Author Posted August 20, 2018 6 minutes ago, Cadiboo said: What exactly are you trying to do? I'm trying to render beam with a start and end point that faces the player's look vector. Quote
Melonslise Posted August 20, 2018 Author Posted August 20, 2018 I got it! Here's the code if anyone is interested: public static void drawLine(Vec3d start, Vec3d end, int red, int green, int blue, int alpha, double width, float partialTick) { Minecraft mc = Minecraft.getMinecraft(); // TODO RenderPos from RenderManager? Vec3d origin = new Vec3d(mc.player.lastTickPosX + (mc.player.posX - mc.player.lastTickPosX) * (double) partialTick, mc.player.lastTickPosY + (mc.player.posY - mc.player.lastTickPosY) * (double) partialTick, mc.player.lastTickPosZ + (mc.player.posZ - mc.player.lastTickPosZ) * (double) partialTick); Vec3d camera = mc.player.getPositionEyes(partialTick); Vec3d direction = end.subtract(start).normalize(); Vec3d startUp = direction.crossProduct(start.subtract(camera)).normalize().scale(width); Vec3d endUp = direction.crossProduct(end.subtract(camera)).normalize().scale(width); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); GlStateManager.pushMatrix(); GlStateManager.disableCull(); GlStateManager.disableTexture2D(); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); buffer.pos(start.x + startUp.x - origin.x, start.y + startUp.y - origin.y, start.z + startUp.z - origin.z).color(red, green, blue, alpha).endVertex(); buffer.pos(start.x - startUp.x - origin.x, start.y - startUp.y - origin.y, start.z - startUp.z - origin.z).color(red, green, blue, alpha).endVertex(); buffer.pos(end.x - endUp.x - origin.x, end.y - endUp.y - origin.y, end.z - endUp.z - origin.z).color(red, green, blue, alpha).endVertex(); buffer.pos(end.x + endUp.x - origin.x, end.y + endUp.y - origin.y, end.z + endUp.z - origin.z).color(red, green, blue, alpha).endVertex(); tessellator.draw(); GlStateManager.enableTexture2D(); GlStateManager.enableCull(); GlStateManager.popMatrix(); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.