Jump to content

[1.6.4]Face me particles!


skullywag

Recommended Posts

Hi all,

 

Title says it all, im having issues with my particles not facing me. Ive got custom ones ingame and all that jazz but they refuse to face me, heres my code can someone see what ive missed, im guessing I need some kind of rotation detection somewhere but cant picture where.

 

My renderParticle

 

public void renderParticle(Tessellator tess, float partialTicks, float par3, float par4, float par5, float par6, float par7)
{
	Minecraft.getMinecraft().renderEngine.bindTexture(texture);
	glDepthMask(false);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glAlphaFunc(GL_GREATER, 0.003921569F);
	tess.setBrightness(240);
	float scale = 0.1F *particleScale;
	float x = (float)(prevPosX + (posX - prevPosX) * partialTicks - interpPosX);
	float y = (float)(prevPosY + (posY - prevPosY) * partialTicks - interpPosY);
	float z = (float)(prevPosZ + (posZ - prevPosZ) * partialTicks - interpPosZ);
	tess.addVertexWithUV(x - par3 * scale - par6 * scale, y - par4 * scale, z - par5 * scale - par7 * scale, 0, 0);
	tess.addVertexWithUV(x - par3 * scale + par6 * scale, y + par4 * scale, z - par5 * scale + par7 * scale, 1, 0);
	tess.addVertexWithUV(x + par3 * scale + par6 * scale, y + par4 * scale, z - par5 * scale + par7 * scale, 1, 1);
	tess.addVertexWithUV(x + par3 * scale - par6 * scale, y - par4 * scale, z - par5 * scale - par7 * scale, 0, 1);
	tess.draw();
	glDisable(GL_BLEND);
	glDepthMask(true);
	glAlphaFunc(GL_GREATER, 0.1F);	
	tess.startDrawingQuads();
}

 

My block display ticking randomly

public void randomDisplayTick(World par1World, int x, int y, int z, Random random) 
{
	float x1 = (float)x + 0.5F;
	float y1 = (float)y + random.nextFloat();
	float z1 = (float)z + 0.5F;
	float f4 = random.nextFloat() * 0.6F - 0.3F;
	float f5 = random.nextFloat() * -0.6F - -0.3F;

	float f = 0.52F;
	float f1 = random.nextFloat() * 0.6F - 0.3F;

	Minecraft.getMinecraft().effectRenderer.addEffect(new EffectSparkleFX(par1World, (double)(x1 + f4), (double)(y1), (double)(z1 + f5)));
}

 

and while were on this subject, anyone know how to slow down the random display tick, seems a little quick, or shall I just stick a random in the random...O.o

Link to comment
Share on other sites

I believe the tessellator has to be set to a certain mode, or not used at all even, as it does its own translation from world coordinates to screen coordinates, of which you would have noticed means they will never face you unless you did some kooky translation math to counter-act the translation...

 

calling startDrawing(int) instead of startDrawingQuads() could give this option, 7 is the quads mode, but I am unsure what the other modes are and if it changes the translation at all, unfortunately I'm only relatively new to how minecraft does things so there isn't much I can help you with...

Link to comment
Share on other sites

It's called the Magic of glRotate~

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

Hi

 

A bit of googling on glRotatef will show you how to use it.  You're right that you will need to know something about the player, what you actually need is the relative positions of the particle and the player's eyes in order to rotate them correctly. 

 

You want the particle to rotate around the vertical axis so the basic concepts are:

 

glRotatef(angle, 0, 1, 0);

 

where

deltax = particle midpoint x - player eye x

deltaz = particle midpoint z - player eye z

and

angle = atan2(deltax, deltaz) * 180 / Math.PI;

 

That's the general idea.  But it will need a bit of playing to get it right - I'm pretty sure that render particle passes in the deltax and deltaz you need because the player's eyes are at 0,0 - but I'm not 100% sure, I suggest having a look at the vanilla to see if you can figure it out, alternatively add some logging code to print out what the values are when you render your test particle.

 

Also, angle might rotate the wrong way or it might be out by 90, 180, or 270 degrees, i.e you may need to do eg

angle = -angle

and/or

angle += 90 // or 180 or 270

 

With a bit of trial & error you should manage it...

 

-TGG

 

 

Link to comment
Share on other sites

Thanks guys I took a break from modding yesterday and came back to it today and it made sense, have now got it working to my satisfaction, however I am getting a strange problem, I havent specified colour or anything in my particle code yet the particle randomly ingame switches to a blue colour. Can rendering on the block/te affect particle rendering? it seems they switch from blue (wrong) to white (correct) at random intervals for a few seconds, ive hunted through my code but cant see why this is happening. Anyone come across a similar issue before?

Link to comment
Share on other sites

Sounds like a color is not getting cleared from somewhere.

 

(Personally I have alpha transparency issues: that is, I cannot make my particles fully solid without revoking transparency entirely, where I'd like to have a gradient)

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

haha I just read through your threads about this, ive got a feeling i might hit the same problem soon enough, im doing a sparkle effect on a crystal....

 

Cant work out where, granted im doing some fidly stuff with colours but not in anything to do with particles. Do I have to clear colours in the render engine to stop them being used in another area, like if made a te model pink and then rendered a particle white without clearing would I get pink particles? or are the renders seperate?

 

edit - just put this in, problem went away.

 

float colorIntensity = 1.0F;
tess.setColorOpaque_F(this.particleRed * colorIntensity, this.particleGreen * colorIntensity, this.particleBlue * colorIntensity);//, 1.0F);

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.