Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello all,

I wanted to render a line going from a point to another. The problem of GL_LINES is that the texture is rendered 1 pixel wide. The solution that i found is render a quad going from a point to another, but i'm having issues when rendering the quad that needs to face the player

 

I took this code from "renderParticle", and it works perfectly if you want to draw a textured square.

private double prevFromX, prevFromY, prevFromZ;
private double prevToX, prevToY, prevToZ;
public void render(float partialTicks, double fromX, double fromY, double fromZ, double toX, double toY, double toZ) {
        float rX = ActiveRenderInfo.rotationX;
        float rZ = ActiveRenderInfo.rotationZ;
        float rYZ = ActiveRenderInfo.rotationYZ;
        float rXY = ActiveRenderInfo.rotationXY;
        float rXZ = ActiveRenderInfo.rotationXZ;

        float startX = (float)(prevFromX + (fromX - prevFromX) * partialTicks);
        float startY = (float)(prevFromY + (fromY - prevFromY) * partialTicks);
        float startZ = (float)(prevFromZ + (fromZ - prevFromZ) * partialTicks);

        float endX = (float)(prevToX + (fromX - prevToX) * partialTicks);
        float endY = (float)(prevToY + (fromY - prevToY) * partialTicks);
        float endZ = (float)(prevToZ + (fromZ - prevToZ) * partialTicks);

        t.startDrawingQuads();

        t.addVertexWithUV(startX - rX - rYZ, startY - rXZ, startZ - rZ - rXY, 0, 1);
        t.addVertexWithUV(startX - rX + rYZ, startY + rXZ, startZ - rZ + rXY, 1, 1);
        t.addVertexWithUV(startX + rX + rYZ, startY + rXZ, startZ + rZ + rXY, 1, 0);
        t.addVertexWithUV(startX + rX - rYZ, startY - rXZ, startZ + rZ - rXY, 0, 0);

        t.draw();

        this.prevFromX = fromX;
        this.prevFromY = fromY;
        this.prevFromZ = fromZ;

        this.prevToX = toX;
        this.prevToY = toY;
        this.prevToZ = toZ;
}

I'm using this method in RenderWorldLastEvent

 

What should I change in the vertexes to work with endX, endY and endZ?

 

Thanks for any help and sorry for my bad english :(

Hi

 

This page talks a bit about the Tessellator and quads

http://greyminecraftcoder.blogspot.com.au/2013/08/the-tessellator.html

 

A couple of comments

1) If  you're drawing a quad instead of a line, you don't need addVertexWithUV, use addVertex instead

2) If you want your line to be roughly the same thickness regardless of where the player is looking from, I think you'll need to choose one of two tricks

either

a) use some vector maths to draw the quad in a plane perpendicular to the viewer's eyes and figure out the width based on the distance to the player (this is not easy to do from scratch but  ActiveRenderInfo.updateRenderInfo() has the necessary calculations and method calls to do the first one for you, you just need to figure out how to use it..), or

b) draw a tube (rectangular prism) with four sides (figure out deltaX = endX - startX, deltaY = endY - startY, deltaZ = endZ - startZ, choose the biggest one (eg deltaY if the line is most vertical), then the four quads:

south side [startX - half_line_width, startY, startZ+half_line_width] to [endX + half_line_width, endY, endZ + half_line_width]

north side [startX - half_line_width, startY, startZ-half_line_width] to [endX + half_line_width, endY, endZ - half_line_width]

west side [startX - half_line_width, startY, startZ - half_line_width] to [endX - half_line_width, endY, endZ + half_line_width]

east side [startX + half_line_width, startY, startZ - half_line_width] to [endX + half_line_width, endY, endZ + half_line_width]

This is a lot easier, but the line will change thickness a bit as you move around, and might look more like a square tube than a line, depending on how big it is.  The width of the line will also vary depending how close the player is; you would need to change the line width proportional to the player's distance from the line.

 

Depends what effect you're looking for really.

 

-TGG

 

 

 

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.