Jump to content

Recommended Posts

Posted

Hello! I recently tried to render an AxisAlignedBoundingBox, did a bit of research on rendering, and coded a bit, only to find out

that the code I ended up with doesn't work. I get less FPS, but not a single AABB is rendered.

@EventBusSubscriber(bus = Bus.FORGE, modid = References.MODID, value = Dist.CLIENT)
public class AABBDebug
{
	@SubscribeEvent
	public static void onRender(RenderWorldLastEvent event)
	{
		if(Minecraft.getInstance().world != null)
		{
			ArrayList<StructureData> structures = StructureDataHandler.getStructures(Minecraft.getInstance().world);
			if(structures == null)
				return;
			for(StructureData data : structures)
			{
		        IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
		        IVertexBuilder builder = buffer.getBuffer(RenderType.LINES);
		        MatrixStack matrixStack = event.getMatrixStack();

		        PlayerEntity player = Minecraft.getInstance().player;
		        double x = player.lastTickPosX + (player.getPosX() - player.lastTickPosX) * event.getPartialTicks();
		        double y = player.lastTickPosY + (player.getPosY() - player.lastTickPosY) * event.getPartialTicks();
		        double z = player.lastTickPosZ + (player.getPosZ() - player.lastTickPosZ) * event.getPartialTicks();

		        matrixStack.push();
		        matrixStack.translate(-x, -y, -z);
		        WorldRenderer.drawBoundingBox(matrixStack, builder, data.aabb.minX, data.aabb.minY, data.aabb.minZ, data.aabb.maxX, data.aabb.maxY, data.aabb.maxZ, 1.0f, 1.0f, 1, 1);
		        matrixStack.pop();
		        RenderSystem.disableDepthTest();
		        buffer.finish(RenderType.LINES);
			}
		}
	}
}

Thanks for any help

  • Budschie changed the title to [1.15.2] How can I render an Bounding Box?
Posted

Ah, I see where my problem was. I used the wrong AxisAlignedBoundingBox. I should have offset it by it's position.

@EventBusSubscriber(bus = Bus.FORGE, modid = References.MODID, value = Dist.CLIENT)
public class AABBDebug
{
	@SubscribeEvent
	public static void onRender(RenderWorldLastEvent event)
	{
		if(Minecraft.getInstance().world != null)
		{
			System.out.println("Rendering...");
			ArrayList<StructureData> structures = StructureDataHandler.getStructures(Minecraft.getInstance().world);
			if(structures == null)
				return;
			for(StructureData data : structures)
			{
				AxisAlignedBB aabb = data.getTranslatedAABB();
				RenderSystem.lineWidth(10.0f);
		        IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
		        if(buffer == null)
		        	return;
		        IVertexBuilder builder = buffer.getBuffer(RenderType.LINES);
		        MatrixStack matrixStack = event.getMatrixStack();
		        PlayerEntity player = Minecraft.getInstance().player;
		        double x = player.lastTickPosX + (player.getPosX() - player.lastTickPosX) * event.getPartialTicks();
		        double y = player.lastTickPosY + (player.getPosY() - player.lastTickPosY) * event.getPartialTicks();
		        double z = player.lastTickPosZ + (player.getPosZ() - player.lastTickPosZ) * event.getPartialTicks();

		        matrixStack.push();
		        matrixStack.translate(-x, -y, -z);
		        WorldRenderer.drawBoundingBox(matrixStack, builder, aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ, 1.0f, 1.0f, 1.0f, 1.0f);
		        matrixStack.pop();
		        RenderSystem.disableDepthTest();
		        buffer.finish(RenderType.LINES);
			}
		}
	}
}

 

  • Budschie changed the title to [1.15.2] [Solved] How can I render an Bounding Box?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.