Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I'm having an issue drawing player render bounding boxes with my mod. It's drawing them in the top left corner, tiny, and it's causing issues with other UI element rendering

 

@SubscribeEvent
public void render(RenderGameOverlayEvent event)
{
  if (event.getType() != ElementType.TEXT) return;

  if (mc.player != null) render(event.getPartialTicks());
}

public void render(float partial_ticks)
{
  Entity viewing_from = mc.getRenderViewEntity();

  double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partial_ticks);
  double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partial_ticks);
  double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partial_ticks);

  GlStateManager.pushMatrix();
  GlStateManager.translate(-x_fix, -y_fix, -z_fix);

  GlStateManager.disableLighting();
  GlStateManager.enableBlend();
  GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  GlStateManager.disableTexture2D();

  for (EntityPlayer p : mc.world.playerEntities)
  {
    AxisAlignedBB pos = p.getRenderBoundingBox();
    GlStateManager.color(0.5F, 0F, 1F, 0.5F);
    box(pos);
  }

  GlStateManager.enableTexture2D();
  GlStateManager.disableBlend();
  GlStateManager.enableLighting();
  GlStateManager.popMatrix();
}
	
private void box(AxisAlignedBB aabb)
{
  Tessellator tessellator = Tessellator.getInstance();
  BufferBuilder worldrenderer = tessellator.getBuffer();

  worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

  // top
  worldrenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();

  // bottom
  worldrenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();

  // north
  worldrenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();

  // south
  worldrenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();

  // west
  worldrenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();

  // east
  worldrenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
  worldrenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();

  tessellator.draw();
}

 

2018-11-08_14.35.42.png

Edited by AntiRix
Posted
14 minutes ago, AntiRix said:

I want to draw the render bounding box, which encapsulates every part of the player. F3+B just displays the hitbox

But you are rendering exactly the same boundingbox F3+B would render

7 hours ago, AntiRix said:

p.getRenderBoundingBox();

This is equal to the collision BB for players. 

 

So define

15 minutes ago, AntiRix said:

encapsulates every part of the player

 

Posted (edited)

Encapsulating, to mean every part of the player's body, whether their arm is swinging, head rotated etc, is inside a tightly-bound box. Every pixel making up that player entity is inside that cube. At least if I can get some sort of box drawn for now, I can work on getting it the right size later.

Edited by AntiRix
Posted

And that's what I need help with - I don't understand how the whole translation system works and why, when telling the renderer to render a cube at a certain position, that it refuses to do so. I also find that I have to be close to the players for the boxes to render, and the direction I look in affects whether they render or not. The boxes also change colour so I have no clue what's going on.

 

https://youtu.be/1Uu1VcYNF-w

Posted

Well, I don't see any translation issues in the video, but I think I understand what you mean by it. It has to do with the interpolation of the entity's position. Basically each frame the entity's actual position is previousTickPosition + (currentTickPosition - previousTickPosition) * partialTicks. The BB is updated per tick, not per frame thus no interpolation is happening, so you need to do it yourself.

 

As for other issues in the video:

I don't really know why the box dissappears when you look away or move a bit away. It would dissappear if the player moves out of entity tracking distance, but that's not the case in the video so it has to be a rendering issue. There are a couple of rendering issues you have:

8 hours ago, AntiRix said:

worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

QUADS will draw, well, a quad, not an outline - it basically will enclose the player in a box. Is that the desired effect here?

I also think I see lightmap issues - so you need to specify the lightmap aswell either by having a vertex format that specifies it or by setting the coordinates manually with OpenGlHelper.

Apart from that I would blame shaders. Does the code work fine without shaders?

Posted

Amazingly, disabling shaders solves all of those issues:

 

1. The boxes render regardless of distance

2. The colour is as specified in the code and doesn't change

3. The boxes always render and don't randomly disappear

 

The intention was indeed to have boxes for the time being, and I'll likely change it to a wireframe later on.

 

So to interpolate the bounding box position, here's what I'm thinking:

 

• The bounding box location is updated every tick

• I'm rendering every frame, so it's rendering multiple times per tick, but is still laggy-looking because it's rendering multiple 'old' frames, ie. where it was last tick.

 

So surely there's no way to render the box in the correct position, because I can't predict where it's going to be next tick.

 

Also, I'm not sure what you mean by lightmap issues; what does it look like compared to how it should look?

 

This is the code:

 

@SubscribeEvent
public void onRenderWorldLast(RenderWorldLastEvent event)
{
	if (mc.player != null) ((ModuleSkullFind)main.get_module(EnumModModule.SKULLFIND)).render(event.getPartialTicks());
}

public void render(float partial_ticks)
{
  Entity viewing_from = mc.getRenderViewEntity();

  double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partial_ticks);
  double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partial_ticks);
  double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partial_ticks);

  GlStateManager.pushMatrix();
  GlStateManager.translate(-x_fix, -y_fix, -z_fix);

  GlStateManager.disableLighting();
  GlStateManager.enableBlend();
  GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  GlStateManager.disableTexture2D();

  for (EntityPlayer p : mc.world.playerEntities)
  {
    AxisAlignedBB pos = p.getRenderBoundingBox();
    GlStateManager.color(1F, 1F, 1F, 1F);
    box(pos);
  }

  GlStateManager.enableTexture2D();
  GlStateManager.disableBlend();
  GlStateManager.enableLighting();
  GlStateManager.popMatrix();
}

 

Posted
5 minutes ago, AntiRix said:

So surely there's no way to render the box in the correct position, because I can't predict where it's going to be next tick.

16 minutes ago, V0idWa1k3r said:

previousTickPosition + (currentTickPosition - previousTickPosition) * partialTicks

The interpolation doesn't happen between "future" position. It happens between position at previous tick and position this tick. So it is indeed quite possible.

6 minutes ago, AntiRix said:

Also, I'm not sure what you mean by lightmap issues; what does it look like compared to how it should look?

18 minutes ago, V0idWa1k3r said:

you need to specify the lightmap aswell either by having a vertex format that specifies it or by setting the coordinates manually with OpenGlHelper.

 

 

Posted

Chances are in a vanilla MC environment it does not change anything. However if there is another mod installed that leaks lightmap coordinates then you will certainly see the change if you are not changing the lightmap coordinates yourself. Your box might get darker, or brighter. Or it may even become very transparent and bright. Or might even not render at all, depends on what the other mod set the coordinates to.

Posted

I don't think so. Shaders might even disregard the lightmap completely seeing how the lightmap is minecraft's way of having, well, lighting. Shaders don't need it since they likely use the fragment shader to change the "brightness" aka color of the fragment based on the light sources of the scene.

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.