Jump to content

Recommended Posts

Posted

So, I'm trying to render a series of lines to represent lasers. I am sending a packet from server to client that will add a series of coords into a list on my tile-entity. I am then picking this list up from my Tile-Entity renderer and trying to display lines from point to point; please see the code below.

 

List<Position> laserToList = ent.laserToList;
	if (laserToList != null && laserToList.size() > 1) {
		// System.out.println("LOL");
		for (int i = 0; i < laserToList.size() - 1; i++) {
			System.out.println(laserToList.get(i).toString());
			System.out.println(laserToList.get(i + 1).toString());

			double doubleX = Minecraft.getMinecraft().thePlayer.posX - 0.5;
			double doubleY = Minecraft.getMinecraft().thePlayer.posY + 0.1;
			double doubleZ = Minecraft.getMinecraft().thePlayer.posZ - 0.5;

			GL11.glPushMatrix();
			GL11.glTranslated(-doubleX, -doubleY, -doubleZ);
			GL11.glColor3ub((byte)255,(byte)0,(byte)0);

			float mx1 = (float) laserToList.get(i + 1).x;
			float my1 = (float) laserToList.get(i + 1).y;
			float mz1 = (float) laserToList.get(i + 1).z;

			float mx2 = (float) laserToList.get(i + 1).x;
			float my2 = (float) laserToList.get(i + 1).y;
			float mz2 = (float) laserToList.get(i + 1).z;

			GL11.glBegin(GL11.GL_LINES);
			GL11.glVertex3f(mx1, my1, mz1);
			GL11.glVertex3f(mx2, my2, mz2);
			GL11.glEnd();
			GL11.glPopMatrix();
		}
	} else {
		// System.out.println(laserToList.size());
	}

 

This code is definitely getting hit, as you can see in my client console output:

 

2014-01-16 19:15:41 [iNFO] [sTDOUT] {150.0, 64.0, 273.0}
2014-01-16 19:15:41 [iNFO] [sTDOUT] {150.0, 64.0, 270.0}

 

The issue is, i am not seeing my lines at all! What am i doing wrong!

Posted

Hi

 

two guesses:

(1) perhaps you're not setting up everything you need for the lines to be visible

eg the vanilla uses this before drawing the selection box around blocks (see RenderGlobal.drawSelectionBox):

    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
    GL11.glLineWidth(2.0F);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(false);

(2) perhaps the origin of the rendering coordinates is not what you think it is.  The TE renderer is called with an origin corresponding to the location of the block, so translating by the player position might not put the lines in the right place, so you can't see them.

 

-TGG

 

Posted

Thanks for the link to the minecraft code, i was looking for that!

 

I now have a line!

 

 

Although it appears to render relative to the player now.. here is my amended code.

List<Position> laserToList = ent.laserToList;
	if (laserToList != null && laserToList.size() > 1) {
		// System.out.println("LOL");
		for (int i = 0; i < laserToList.size() - 1; i++) {
//				System.out.println(laserToList.get(i).toString());
//				System.out.println(laserToList.get(i + 1).toString());

			double doubleX = ent.xCoord;
			double doubleY = ent.yCoord;
			double doubleZ = ent.zCoord;

			GL11.glPushMatrix();

			GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);       

			GL11.glTranslated(0, 0, 0);
			GL11.glColor3ub((byte)255,(byte)0,(byte)0);
			GL11.glLineWidth(10.0F);

			float mx1 = ent.xCoord - (float) laserToList.get(i + 1).x;
			float my1 = ent.yCoord - (float) laserToList.get(i + 1).y;
			float mz1 = ent.zCoord - (float) laserToList.get(i + 1).z;

			float mx2 = ent.xCoord - (float) laserToList.get(i + 1).x;
			float my2 = ent.yCoord - (float) laserToList.get(i + 1).y;
			float mz2 = ent.xCoord - (float) laserToList.get(i + 1).z;

			Tessellator tessellator = Tessellator.instance;
	        tessellator.startDrawing(3);
	        tessellator.addVertex(mx1, my1, mz1);
	        tessellator.addVertex(mx2,my2, mz2);
	        tessellator.draw();
	        
	        GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_BLEND);
			GL11.glPopMatrix();
		}
	} else {
		// System.out.println(laserToList.size());
	}

 

I am now changing the coordinates for the laser origin and end points so that they are relative to the TE as you suggested: TE position - laser origin position

Posted

Hi

 

After looking at your youtube and checking out a couple of the vanilla TESR and one I wrote a while back, I'm now a bit confused.  It does look in your video like there is some sort of translation happening relative to the player.

 

I'll have a play around myself to try and get it straight in my head, might take a while, in the meantime you could try a couple of different combinations yourself.  I suspect you need to add an extra translate by the renderTileEntityAt x,y,z parameters (par2, par4, par6 I mean),  I think the par2, par4 and par6 are the displacement of the TileEntity world coordinates relative to the current player position, but I'm not certain any more.

 

-TGG

Posted

ThaT  helped! I set the translation to the par 2 4 6 and it is now in the right place relative to the world.  Only issue now,  is that it will start at the right place.  But the line will continue on forever. Do I need to do anything more with the tessalator?

Posted

Hi

 

So does the line start at the right spot but never end, or is it infinite in both directions?  If so, perhaps your end coordinate is wrong.

 

Alternatively, it might be because you're using

 

    tessellator.startDrawing(GL11.GL_LINE_STRIP);

 

I think you actually need

 

    tessellator.startDrawing(GL11.GL_LINES);

 

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

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