Jump to content

[1.8] Drawing a line between two world co-ordinates


Lyinginbedmon

Recommended Posts

I'm currently endeavouring to add some visual reference to an already-functional mining laser tool. The player pushes a button, it triggers a boolean in extended data, which sets the mining process in motion where they're looking. What I'm currently struggling with is using the tessellator to draw the actual laser beam for everyone nearby.

 

This occurs in RenderPlayerEvent via my client event bus and I have verified that the following code is being run and returning the correct vector positions.

			if(data.getIsMining())
		{
			MovingObjectPosition rayTrace = RMHelper.getTargetPosition(thePlayer, theWorld, 16F);
			if(rayTrace != null && rayTrace.getBlockPos() != null)
			{
				/** Origin point of the laser beam */
				Vec3 posA = Vec3Helper.getLookVecPos(theEvent.entityPlayer);
				/** Position being struck by the laser beam */
				Vec3 posB = new Vec3(rayTrace.getBlockPos().getX(), rayTrace.getBlockPos().getY(), rayTrace.getBlockPos().getZ());

	            		Tessellator tessellator = Tessellator.getInstance();
	            		WorldRenderer world = tessellator.getWorldRenderer();
	            
	            		/** Code experimentally borrowed from RenderLightningBolt */
	            		GlStateManager.disableTexture2D();
	            		GlStateManager.disableLighting();
	            		GlStateManager.enableBlend();
	            		GlStateManager.blendFunc(770, 1);
	            
	            		world.startDrawing(7);
	            		world.setColorRGBA_F(1F, 0F, 0F, 1F);
	            
	            		Vec3 dirVec = posA.subtract(posB);
	            		Vec3 perpVec = (new Vec3(dirVec.zCoord, dirVec.yCoord, dirVec.xCoord)).normalize();
	            
	            		float width = 1F / 16F;
	            
	            		Vec3 R1 = new Vec3(posA.xCoord + perpVec.xCoord * width, posA.yCoord - 0.01, posA.zCoord + perpVec.zCoord * width);
	            		Vec3 R2 = new Vec3(posA.xCoord - perpVec.xCoord * width, posA.yCoord - 0.01, posA.zCoord + perpVec.zCoord * width);
	            		Vec3 R3 = new Vec3(posB.xCoord + perpVec.xCoord * width, posB.yCoord + 0.75, posB.zCoord + perpVec.zCoord * width);
	            		Vec3 R4 = new Vec3(posB.xCoord - perpVec.xCoord * width, posB.yCoord + 0.75, posB.zCoord + perpVec.zCoord * width);
	            
	            		world.addVertex(R1.xCoord + 0.5, R1.yCoord, R1.zCoord + 0.5);
	            		world.addVertex(R3.xCoord + 0.5, R3.yCoord, R3.zCoord + 0.5);
	            		world.addVertex(R4.xCoord + 0.5, R4.yCoord, R4.zCoord + 0.5);
	            		world.addVertex(R2.xCoord + 0.5, R2.yCoord, R2.zCoord + 0.5);
	            
	            		tessellator.draw();

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

Currently, nothing appears on screen at all. I've tried switching the direction (b -> a instead of a -> b) and changing the origin point of the vectors, but to no avail. Graphics programming is by far my least level of competence, can anyone help me work this out?

Link to comment
Share on other sites

You might find this post helpful. It explains how to render a beam from one point to another. You should be able to adapt this explanation to your needs.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Its just vector math.

This is the closest code I have that does what you need, but it is going to be in a different language.

http://answers.unity3d.com/answers/1065843/view.html

You'll want to look at the function starting on line 108, which takes in two Vec3 positions and calculates a camera facing quad.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.