PARTICLE ROTATION

This commit is contained in:
luisc committed 2022-03-02 18:18:03 -06:00
1 parent 65ab37158f
commit 7f8246e04e
6 files changed
+318 -181

No files matched your search

@@ -7,7 +7,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ClientProxy;
import org.lwjgl.Sys;
import org.lwjgl.opengl.GL11;
public class EntityCustomFX extends EntityFX {
@@ -27,10 +26,38 @@ public class EntityCustomFX extends EntityFX {
public float alphaRate = 0.0F;
public int alphaRateStart = 0;
public float rotation = 0;
public float rotation1 = 0;
public float rotation2 = 0;
public float rotationRate = 0.0F;
public int rotationRateStart = 0;
public float rotationX = 0;
public float rotationX1 = 0;
public float rotationX2 = 0;
public float rotationXRate = 0.0F;
public int rotationXRateStart = 0;
public float rotationY = 0;
public float rotationY1 = 0;
public float rotationY2 = 0;
public float rotationYRate = 0.0F;
public int rotationYRateStart = 0;
public float rotationZ = 0;
public float rotationZ1 = 0;
public float rotationZ2 = 0;
public float rotationZRate = 0.0F;
public int rotationZRateStart = 0;
public EntityCustomFX(Entity entity, String directory, int HEXColor, double x, double y, double z,
double motionX, double motionY, double motionZ, float gravity,
float scale1, float scale2, float scaleRate, int scaleRateStart,
float alpha1, float alpha2, float alphaRate, int alphaRateStart,
float rotation1, float rotation2, float rotationRate, int rotationRateStart,
float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart,
float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart,
float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart,
int age) {
super(entity.worldObj, x, y, z, motionX, motionY, motionZ);
@@ -50,6 +77,38 @@ public class EntityCustomFX extends EntityFX {
if(alpha1 > alpha2)
this.alphaRate *= -1;
this.rotation1 = rotation1;
this.rotation2 = rotation2;
this.rotationRate = Math.abs(rotationRate);
this.rotationRateStart = rotationRateStart;
rotation = rotation1;
if(rotation1 > rotation2)
this.rotationRate *= -1;
this.rotationX1 = rotationX1;
this.rotationX2 = rotationX2;
this.rotationXRate = Math.abs(rotationXRate);
this.rotationXRateStart = rotationXRateStart;
rotationX = rotationX1;
if(rotationX1 > rotationX2)
this.rotationXRate *= -1;
this.rotationY1 = rotationY1;
this.rotationY2 = rotationY2;
this.rotationYRate = Math.abs(rotationYRate);
this.rotationYRateStart = rotationYRateStart;
rotationY = rotationY1;
if(rotationY1 > rotationY2)
this.rotationYRate *= -1;
this.rotationZ1 = rotationZ1;
this.rotationZ2 = rotationZ2;
this.rotationZRate = Math.abs(rotationZRate);
this.rotationZRateStart = rotationZRateStart;
rotationZ = rotationZ1;
if(rotationZ1 > rotationZ2)
this.rotationZRate *= -1;
particleGravity = gravity/0.04F;
particleMaxAge = age;
@@ -74,148 +133,96 @@ public class EntityCustomFX extends EntityFX {
location = new ResourceLocation(directory);
}
/*
par2 = partial tick time
par3 = ActiveRenderInfo.rotationX;
par4 = ActiveRenderInfo.rotationZ;
par5 = ActiveRenderInfo.rotationYZ;
par6 = ActiveRenderInfo.rotationXY;
par7 = ActiveRenderInfo.rotationXZ;
*/
@Override
public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
public void renderParticle(Tessellator tessellator, float partialTick, float cosYaw, float cosPitch, float sinYaw, float sinSinPitch, float cosSinPitch)
{
if(move){
startX = (float)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)par2);
startY = (float)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)par2);
startZ = (float)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)par2);
}
Tessellator tessellator = Tessellator.instance;
tessellator.draw();
float scale = this.scaleRate / (float)particleMaxAge;
if((this.scaleRate < 0 && particleScale+scale < this.scale2) || (this.scaleRate > 0 && particleScale+scale > this.scale2))
particleScale = this.scale2;
else if(particleAge >= this.scaleRateStart)
particleScale += scale;
float alpha = this.alphaRate / (float)particleMaxAge;
if((this.alphaRate < 0 && particleAlpha+alpha < this.alpha2) || (this.alphaRate > 0 && particleAlpha+alpha > this.alpha2))
particleAlpha = this.alpha2;
else if(particleAge >= this.alphaRateStart)
particleAlpha += alpha;
ClientProxy.bindTexture(location);
float f = 0.0f;
float f1 = 1.0f;
float f2 = 0.0f;
float f3 = 1.0f;
float f4 = 0.1F * particleScale;
float f5 = (float)(((prevPosX + (posX - prevPosX) * (double)par2) - interpPosX) + startX);
float f6 = (float)(((prevPosY + (posY - prevPosY) * (double)par2) - interpPosY) + startY);
float f7 = (float)(((prevPosZ + (posZ - prevPosZ) * (double)par2) - interpPosZ) + startZ);
tessellator.startDrawingQuads();
tessellator.setBrightness(240);
par1Tessellator.setColorOpaque_F(1, 1, 1);
par1Tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha);
par1Tessellator.addVertexWithUV(f5 - par3 * f4 - par6 * f4, f6 - par4 * f4, f7 - par5 * f4 - par7 * f4, f1, f3);
par1Tessellator.addVertexWithUV((f5 - par3 * f4) + par6 * f4, f6 + par4 * f4, (f7 - par5 * f4) + par7 * f4, f1, f2);
par1Tessellator.addVertexWithUV(f5 + par3 * f4 + par6 * f4, f6 + par4 * f4, f7 + par5 * f4 + par7 * f4, f, f2);
par1Tessellator.addVertexWithUV((f5 + par3 * f4) - par6 * f4, f6 - par4 * f4, (f7 + par5 * f4) - par7 * f4, f, f3);
/*
Minecraft minecraft = Minecraft.getMinecraft();
EntityPlayer player = minecraft.thePlayer;
double angle = Minecraft.getMinecraft().theWorld.getWorldTime()%360;
double angleRad = (angle/180)*Math.PI;
double diffX = player.posX - this.startX;
double diffY = player.posY - player.getYOffset() - this.startY;
double diffZ = player.posZ - this.startZ;
double yaw = (player.rotationYaw/180)*Math.PI;
double pitch = (player.rotationPitch/180)*Math.PI;
double angleX = Math.sin(yaw)*Math.cos(pitch);
if(Math.abs(angleX) < 0.0001){
angleX = 0.0D;
}
double angleY = Math.sin(pitch);
if(Math.abs(angleY) < 0.0001){
angleY = 0.0D;
}
double angleZ = -Math.cos(yaw)*Math.cos(pitch);
if(Math.abs(angleZ) < 0.0001){
angleZ = 0.0D;
}
double angleXtranslateX = 0.0D;
double angleXtranslateY = 0.0D;//(-diffY + Math.cos(angleRad)*diffY) + (-Math.sin(angleRad)*diffZ);
double angleXtranslateZ = 0.0D;//(Math.sin(angleRad)*diffY) + (-diffZ + Math.cos(angleRad)*diffZ);
double angleYtranslateX = 0.0D;//(-diffX + Math.cos(angleRad)*diffX) + (Math.sin(angleRad)*diffZ);
double angleYtranslateY = 0.0D;
double angleYtranslateZ = 0.0D;//(-Math.sin(angleRad)*diffX) + (-diffZ + Math.cos(angleRad)*diffZ);
double angleZtranslateX = 0.0D;//(-diffX + Math.cos(angleRad)*diffX) + (-Math.sin(angleRad)*diffY);
double angleZtranslateY = 0.0D;//(Math.sin(angleRad)*diffX) + (-diffY + Math.cos(angleRad)*diffY);
double angleZtranslateZ = 0.0D;
double translateX = angleXtranslateX + angleYtranslateX + angleZtranslateX;
double translateY = angleXtranslateY + angleYtranslateY + angleZtranslateY;
double translateZ = angleXtranslateZ + angleYtranslateZ + angleZtranslateZ;
//distance in the X & Z plane
double distXZ = Math.sqrt(Math.pow(diffX,2) + Math.pow(diffZ,2));
//distance in the X & Y plane
double distXY = Math.sqrt(Math.pow(diffX,2) + Math.pow(diffY,2));
//distance in the Y & Z plane
double distYZ = Math.sqrt(Math.pow(diffY,2) + Math.pow(diffZ,2));
double signDiffX = Math.signum(diffX);
double signDiffY = Math.signum(diffY);
double signDiffZ = Math.signum(diffZ);
double angleXtoNorm = Math.sin(Math.acos(diffX/distXZ));
double angleZtoNorm = Math.sin(Math.acos(diffZ/distXZ));
double angleDiffX = (Math.abs(Math.cos(yaw))-angleXtoNorm);
double angleDiffZ = (Math.abs(Math.cos(yaw))-angleZtoNorm);
double translateX = -Math.abs(angleDiffX*angleZ*distXZ)*signDiffX;
double translateY = 0;
double translateZ = -Math.abs(angleDiffX*angleX*distXZ)*signDiffZ + Math.cos(angleRad)*Math.abs(angleDiffX*angleX*distXZ)*signDiffZ;
if(minecraft.currentScreen == null) {
System.out.println();
//System.out.printf("diffX: %f, diffY: %f, diffZ: %f\n", diffX, diffY, diffZ);
//System.out.printf("angleX: %f, angleY: %f, angleZ: %f\n", angleX, angleY, angleZ);
//System.out.printf("angleXtoNorm: %f, angleZtoNorm: %f\n", angleXtoNorm, angleZtoNorm);
System.out.printf("Math.sin(yaw): %f\n", Math.sin(yaw));
System.out.printf("Math.cos(yaw): %f\n", Math.cos(yaw));
//System.out.printf("Math.sin(pitch): %f\n", Math.sin(pitch));
//System.out.printf("Math.cos(pitch): %f\n", Math.cos(pitch));
System.out.printf("angleDiffX: %f\n", angleDiffX);
System.out.printf("angleDiffZ: %f\n", angleDiffZ);
System.out.printf("translateX: %f\n", Math.cos(angleRad)*Math.abs(angleDiffX*angleZ*distXZ)*signDiffX);
System.out.printf("translateZ: %f\n", Math.cos(angleRad)*Math.abs(angleDiffX*angleX*distXZ)*signDiffZ);
}
*/
GL11.glPushMatrix();
GL11.glColor4f(1, 1, 1, 1.0F);
ClientProxy.bindTexture(location);
GL11.glTexParameterf(3553, 10242, 10497.0F);
GL11.glTexParameterf(3553, 10243, 10497.0F);
GL11.glDisable(2884);
GL11.glEnable(3042);
//GL11.glTranslated(translateX,translateY,translateZ);
//GL11.glRotated(angle, angleX, angleY, angleZ);
if(move){
startX = (float)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)partialTick);
startY = (float)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)partialTick);
startZ = (float)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)partialTick);
}
float scaleChange = this.scaleRate / (float)particleMaxAge;
if((this.scaleRate < 0 && particleScale+scaleChange < this.scale2) || (this.scaleRate > 0 && particleScale+scaleChange > this.scale2))
particleScale = this.scale2;
else if(particleAge >= this.scaleRateStart)
particleScale += scaleChange;
float alphaChange = this.alphaRate / (float)particleMaxAge;
if((this.alphaRate < 0 && particleAlpha+alphaChange < this.alpha2) || (this.alphaRate > 0 && particleAlpha+alphaChange > this.alpha2))
particleAlpha = this.alpha2;
else if(particleAge >= this.alphaRateStart)
particleAlpha += alphaChange;
float rotationChange = this.rotationRate / (float)particleMaxAge;
if((this.rotationRate < 0 && rotation+rotationChange < this.rotation2) || (this.rotationRate > 0 && rotation+rotationChange > this.rotation2))
rotation = this.rotation2;
else if(particleAge >= this.rotationRateStart)
rotation += rotationChange;
float rotationXChange = this.rotationXRate / (float)particleMaxAge;
if((this.rotationXRate < 0 && rotationX+rotationXChange < this.rotationX2) || (this.rotationXRate > 0 && rotationX+rotationXChange > this.rotationX2))
rotationX = this.rotationX2;
else if(particleAge >= this.rotationXRateStart)
rotationX += rotationXChange;
float rotationYChange = this.rotationYRate / (float)particleMaxAge;
if((this.rotationYRate < 0 && rotationY+rotationYChange < this.rotationY2) || (this.rotationYRate > 0 && rotationY+rotationYChange > this.rotationY2))
rotationY = this.rotationY2;
else if(particleAge >= this.rotationYRateStart)
rotationY += rotationYChange;
float rotationZChange = this.rotationZRate / (float)particleMaxAge;
if((this.rotationZRate < 0 && rotationZ+rotationZChange < this.rotationZ2) || (this.rotationZRate > 0 && rotationZ+rotationZChange > this.rotationZ2))
rotationZ = this.rotationZ2;
else if(particleAge >= this.rotationZRateStart)
rotationZ += rotationZChange;
float u1 = 0.0f;
float u2 = 1.0f;
float v1 = 0.0f;
float v2 = 1.0f;
float renderScale = 0.1F * particleScale;
float posX = (float)(((prevPosX + (this.posX - prevPosX) * (double)partialTick) - interpPosX) + startX);
float posY = (float)(((prevPosY + (this.posY - prevPosY) * (double)partialTick) - interpPosY) + startY);
float posZ = (float)(((prevPosZ + (this.posZ - prevPosZ) * (double)partialTick) - interpPosZ) + startZ);
GL11.glTranslated((double)posX, (double)posY, (double)posZ);
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
double yaw = (player.rotationYaw/180)*Math.PI;
double pitch = (player.rotationPitch/180)*Math.PI;
GL11.glRotated(rotation, Math.sin(yaw)*Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw)*Math.cos(pitch));
GL11.glRotated(rotationX, 1.0,0.0,0.0);
GL11.glRotated(rotationY, 0.0,1.0,0.0);
GL11.glRotated(rotationZ, 0.0,0.0,1.0);
tessellator.startDrawingQuads();
tessellator.setBrightness(240);
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.setColorRGBA_F(particleRed, particleGreen, particleBlue, particleAlpha);
tessellator.addVertexWithUV( - cosYaw * renderScale - sinSinPitch * renderScale, - cosPitch * renderScale, - sinYaw * renderScale - cosSinPitch * renderScale, u2, v2);
tessellator.addVertexWithUV(( - cosYaw * renderScale) + sinSinPitch * renderScale, + cosPitch * renderScale, ( - sinYaw * renderScale) + cosSinPitch * renderScale, u2, v1);
tessellator.addVertexWithUV( + cosYaw * renderScale + sinSinPitch * renderScale, + cosPitch * renderScale, + sinYaw * renderScale + cosSinPitch * renderScale, u1, v1);
tessellator.addVertexWithUV(( + cosYaw * renderScale) - sinSinPitch * renderScale, - cosPitch * renderScale, ( + sinYaw * renderScale) - cosSinPitch * renderScale, u1, v2);
tessellator.draw();
ClientProxy.bindTexture(resource);
tessellator.startDrawingQuads();
GL11.glPopMatrix();
GL11.glColor4f(1, 1, 1, 1.0F);
ClientProxy.bindTexture(resource);
tessellator.startDrawingQuads();
}
public int getFXLayer(){