Jump to content

Lasers? Lasers.


weckar

Recommended Posts

Hi!

This is honestly more of a personal interest topic than a 'help' topic, although that makes me no less interested in the opinions and answers.

 

To me, one of the most graphically entertaining features of any mod ever are the lasers sent out by Botania's mana spreaders. And lately, now that I've dipped my toe into coding for this game myself, I've found myself wondering how it's done...

 

My immediate assumption would be particles of somekind, but I have never known particles behave so well, or be lag free in such large numbers. I've been playing with particles a bit myself, but for me they actually seem to completely ignore any directional vector I give them...

 

Another way, I suppose, would be tapping directly into the drawing engine. But I also imagine this would be cumbersome, difficult, and not very efficient.

 

So, how would it be (/is it) done? This question just has been tickling my brain for a while now! :)

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

If it looks like solid beams, then it is most likely done using direct GL calls.  Which aren't that difficult, really.  Its just a matter of knowing the two end points and drawing a line.

 

You'll have to escuse this lump of code, its stolen from my own purposes and some of it is useless to you.  I trimmed what I know is, but there are likely lingering references.

I call this function from a DrawBlockHighlightEvent event, but I am specifically interested in the block the player is looking at.

 

//draw a line between two blocks
private void drawLine(Vec3 blockA, Vec3 blockB) {
	Tessellator tess = Tessellator.instance;
	tess.startDrawing(7);//quads
	tess.setBrightness(15728880);
	tess.setColorOpaque_F(1F, 0F, 0F);//red

	Vec3 recLong = blockA.subtract(blockB);
	Vec3 perpendicular = Vec3.createVectorHelper(recLong.zCoord, recLong.yCoord, -recLong.xCoord);
	perpendicular = perpendicular.normalize();

	float Width = 1f/16f;

	Vec3 R1 = blockA.subtract(blockB);
	Vec3 R2 = blockA.subtract(blockB);
	Vec3 R3 = blockA.subtract(blockB);
	Vec3 R4 = blockA.subtract(blockB);

	R1.xCoord = blockA.xCoord + perpendicular.xCoord * Width;
	R1.zCoord = blockA.zCoord + perpendicular.zCoord * Width;
	R2.xCoord = blockA.xCoord - perpendicular.xCoord * Width;
	R2.zCoord = blockA.zCoord - perpendicular.zCoord * Width;
	R1.yCoord = blockA.yCoord - 0.01;
	R2.yCoord = blockA.yCoord - 0.01;

	R3.xCoord = blockB.xCoord + perpendicular.xCoord * Width;
	R3.zCoord = blockB.zCoord + perpendicular.zCoord * Width;
	R4.xCoord = blockB.xCoord - perpendicular.xCoord * Width;
	R4.zCoord = blockB.zCoord - perpendicular.zCoord * Width;
	R3.yCoord = blockB.yCoord + 0.75;
	R4.yCoord = blockB.yCoord + 0.75;
	tess.addVertex(R1.xCoord + 0.5, R1.yCoord, R1.zCoord + 0.5);
	tess.addVertex(R3.xCoord + 0.5, R3.yCoord, R3.zCoord + 0.5);
	tess.addVertex(R4.xCoord + 0.5, R4.yCoord, R4.zCoord + 0.5);
	tess.addVertex(R2.xCoord + 0.5, R2.yCoord, R2.zCoord + 0.5);

	tess.draw();
}

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

I have to say I am not familiar with the Vec3 data type, but it looks reasonably straightforward as a coordinate storage.

It does strike me that you are creating 4 vertexes to draw a line, and yet nowhere do you tell the tesselator that is is a line you want to draw. Seems to me that it would prefer to draw a plane somehow?

 

I could definitely see this being a very good first solution, so Kudos (I honestly don't see what your signature talks about!). The laser I'm referring to does seem to be made of... pellets, if there'd be no other word to describe it. As said, it LOOKS like particles, but it seems much to controlled to actually be so - while there are too many of them for them to reasonably be actual entities...

 

Still, this gives me some grounds for trying things out :)

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

I have to say I am not familiar with the Vec3 data type, but it looks reasonably straightforward as a coordinate storage.

It does strike me that you are creating 4 vertexes to draw a line, and yet nowhere do you tell the tesselator that is is a line you want to draw. Seems to me that it would prefer to draw a plane somehow?

 

tess.addVertex(...);

 

The tessellator (and thereby GL) is in quad drawing mode.  So it expects a multiple of four vertices arranged clockwise around the surface normal.

I chose quads because while there is a line mode (two verts) you don't have control over the thickness of that line.  It would be 1 pixel thick, always.

 

 

 

Probably particles then.  And particles are like ultra-cheap entities.

See this class[/i].

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

Hmmmm going back to the script you posted above, I realize I have no idea where to actually CALL that from!

 

My first instinct was to use a Block's custom rendering class, but within the method renderWorldBlock I get the exception that it's already Tesselating. Haven't found a way around that, so I continued trying.

 

I figured, maybe on the clientside tick of a BlockEntity. No Exceptions - but no line either...

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

If its already tessellating, then drop the "start" and "end" bits. Magic.

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

Magic it would be... if not that when I drop those it suddenly says it ISN'T tesselating! What do you want from me, Tesselator!?

If anyone has a comprehensive, visual guide to GUIs - don't hesitate to message me. They make my head spin.

Link to comment
Share on other sites

Show your code.

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.