Jump to content

Recommended Posts

Posted

While creating a mod I've tried to create a costum particle effect. The particle currently is just a texture that has movement and lifespan.

 

The problem I've came up to is:  I one is looking at the particle from the North/South (z axis) then it renders correctly.

If one looks at the particle from the West/East (x axis) you can barely see anything. as if it's rendering only to the z axis. Vanilla particles don't do that, as they face the player at all times.

 

A visual representation of the problem:

 

North/South: http://pasteboard.co/1L2QwVO.png    - You can see the "Pie" Fine...

 

West/East: http://pasteboard.co/1L6DRE9.png    - You can barely see anything, since this is not perfectly West/East view.

 

Something in between: http://pasteboard.co/1L3VPES.png    - You can clearly see that the particle is flat and only renders on one axis.

 

Is there any way of rendering the particle on more than one axis? Here's my code: http://pastebin.com/p2CYGMKH

 

Thank you in advance!

yolp900

 

 

Posted

You aren't rotating the 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.

Posted

Hi

 

Vanilla particles always rotate the quad to directly face the player.  An excerpt from a custom EntityFX I wrote (see below) might help make it clearer what's happening.

 

Also this link to information about the tessellator.

http://greyminecraftcoder.blogspot.co.at/2014/12/the-tessellator-and-worldrenderer-18.html

 

-TGG

 

  /**
   * Render the EntityFX onto the screen.
   * The EntityFX is rendered as a two-dimensional object (Quad) in the world (three-dimensional coordinates).
   *   The corners of the quad are chosen so that the EntityFX is drawn directly facing the viewer (or in other words,
   *   so that the quad is always directly face-on to the screen.)
   * In order to manage this, it needs to know two direction vectors:
   * 1) the 3D vector direction corresponding to left-right on the viewer's screen (edgeLRdirection)
   * 2) the 3D vector direction corresponding to up-down on the viewer's screen (edgeURdirection)
   * These two vectors are calculated by the caller.
   * For example, the top right corner of the quad on the viewer's screen is equal to the centre point of the quad (x,y,z)
   *   plus the edgeLRdirection vector multiplied by half the quad's width, plus the edgeURdirection vector multiplied
   *   by half the quad's height.
   * NB edgeLRdirectionY is not provided because it's always 0, i.e. the top of the viewer's screen is always directly
   *    up so moving left-right on the viewer's screen doesn't affect the y coordinate position in the world
   * @param worldRenderer
   * @param entity
   * @param partialTick
   * @param edgeLRdirectionX edgeLRdirection[XYZ] is the vector direction pointing left-right on the player's screen
   * @param edgeUDdirectionY edgeUDdirection[XYZ] is the vector direction pointing up-down on the player's screen
   * @param edgeLRdirectionZ edgeLRdirection[XYZ] is the vector direction pointing left-right on the player's screen
   * @param edgeUDdirectionX edgeUDdirection[XYZ] is the vector direction pointing up-down on the player's screen
   * @param edgeUDdirectionZ edgeUDdirection[XYZ] is the vector direction pointing up-down on the player's screen
   */
  @Override
  public void func_180434_a(WorldRenderer worldRenderer, Entity entity, float partialTick,
                            float edgeLRdirectionX, float edgeUDdirectionY, float edgeLRdirectionZ,
                            float edgeUDdirectionX, float edgeUDdirectionZ)
  {
    double minU = this.particleIcon.getMinU();
    double maxU = this.particleIcon.getMaxU();
    double minV = this.particleIcon.getMinV();
    double maxV = this.particleIcon.getMaxV();
    RotatingQuad tex = new RotatingQuad(minU, minV, maxU, maxV);
    // RotatingQuad is just a helper that swaps the four texture corner points around, so the quad face can be rotated or flipped easily.  You can ignore it.
    Random random = new Random();
    if (random.nextBoolean()) {
      tex.mirrorLR();
    }
    tex.rotate90(random.nextInt(4));

    double scale = 0.1F * this.particleScale;
    final double scaleLR = scale;
    final double scaleUD = scale;
    double x = this.prevPosX + (this.posX - this.prevPosX) * partialTick - interpPosX;
    double y = this.prevPosY + (this.posY - this.prevPosY) * partialTick - interpPosY + this.height / 2.0F;
    // centre of rendering is now y midpt not ymin
    double z = this.prevPosZ + (this.posZ - this.prevPosZ) * partialTick - interpPosZ;

    worldRenderer.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);
    worldRenderer.addVertexWithUV(x - edgeLRdirectionX * scaleLR - edgeUDdirectionX * scaleUD,
            y - edgeUDdirectionY * scaleUD,
            z - edgeLRdirectionZ * scaleLR - edgeUDdirectionZ * scaleUD,
            tex.getU(0),  tex.getV(0));
    worldRenderer.addVertexWithUV(x - edgeLRdirectionX * scaleLR + edgeUDdirectionX * scaleUD,
            y + edgeUDdirectionY * scaleUD,
            z - edgeLRdirectionZ * scaleLR + edgeUDdirectionZ * scaleUD,
            tex.getU(1),  tex.getV(1));
    worldRenderer.addVertexWithUV(x + edgeLRdirectionX * scaleLR + edgeUDdirectionX * scaleUD,
            y + edgeUDdirectionY * scaleUD,
            z + edgeLRdirectionZ * scaleLR + edgeUDdirectionZ * scaleUD,
            tex.getU(2),  tex.getV(2));
    worldRenderer.addVertexWithUV(x + edgeLRdirectionX * scaleLR - edgeUDdirectionX * scaleUD,
            y - edgeUDdirectionY * scaleUD,
            z + edgeLRdirectionZ * scaleLR - edgeUDdirectionZ * scaleUD,
            tex.getU(3),  tex.getV(3));
  }

Posted

Thank you! I didn't think it has to do with rotating the quads since I thought that all particles do it automaticly... My bad... Thanks again! I'll definitely look at your code, it seems very useful!

 

(I'm new to minecraft modding, and sort-of new to java, so every help I get means a lot :) )

Posted

Is there a demonstration in vanilla or forge code for rotating the quads? I've tried to implement my own way to move the tesselator and it just stays on its axis... I don't think I'm the only one who got this problem, am I?

Posted

Do it like this:

WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer();

GLStateManager.glPushAttrib();

GLStateManager.glPushMatrix();

GL11.glRotated(angle, valueX, valueY, valueZ);

//Rendering code here;

GLStateManager.glPopMatrix();

GLStateManager.glPopAttrib();

Posted

So my friend and I figured this out, we changed the UV code itself since we couldn't find any documentation of a simpler way.

 

float f6 = 0;

float f7 = 1;

float f8 = 0;

float f9 = 1;

float f10 = 0.1F * this.particleScale;

 

if (this.particleIcon != null)

{

    f6 = this.particleIcon.getMinU();

    f7 = this.particleIcon.getMaxU();

    f8 = this.particleIcon.getMinV();

    f9 = this.particleIcon.getMaxV();

}

 

float f11 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)particleTicks - interpPosX);

float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)particleTicks - interpPosY);

float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)particleTicks - interpPosZ);

tess.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);

tess.addVertexWithUV((double) (f11 - par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 - par5 * f10 - par7 * f10), (double) f7, (double) f9);

tess.addVertexWithUV((double) (f11 - par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 - par5 * f10 + par7 * f10), (double) f7, (double) f8);

tess.addVertexWithUV((double) (f11 + par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 + par5 * f10 + par7 * f10), (double) f6, (double) f8);

tess.addVertexWithUV((double) (f11 + par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 + par5 * f10 - par7 * f10), (double) f6, (double) f9);

tess.draw();

 

Hope this code helps anyone who gets this problem in the future...

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.