Mooore smoooooth animations

This commit is contained in:
Electroblob77
2020-06-12 23:12:37 +01:00
parent 00f958a71e
commit a65c56eb41
8 changed files with 143 additions and 141 deletions
@@ -3,6 +3,7 @@ package electroblob.wizardry.client.renderer.entity;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.client.renderer.RayHelper;
import electroblob.wizardry.entity.construct.EntityBlackHole;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.entity.Render;
@@ -49,11 +50,7 @@ public class RenderBlackHole extends Render<EntityBlackHole> {
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int animationTicks = 10;
float age = entity.ticksExisted + partialTicks;
float s = age < animationTicks ? age/animationTicks : MathHelper.clamp((entity.lifetime - age) / animationTicks, 0, 1);
s = (float)Math.pow(s, 0.4); // Smooths the animation
float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10);
GlStateManager.scale(s, s, s);
this.bindTexture(RAY_TEXTURE);
@@ -25,7 +25,7 @@ public class RenderBubble extends Render<EntityBubble> {
}
@Override
public void doRender(EntityBubble entity, double par2, double par4, double par6, float par8, float par9){
public void doRender(EntityBubble entity, double x, double y, double z, float entityYaw, float partialTicks){
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
@@ -39,7 +39,7 @@ public class RenderBubble extends Render<EntityBubble> {
yOffset = rider.height / 2;
}
GlStateManager.translate((float)par2, (float)par4 + yOffset, (float)par6);
GlStateManager.translate((float)x, (float)y + yOffset, (float)z);
this.bindTexture(entity.isDarkOrb ? ENTRAPMENT_TEXTURE : PARTICLE_TEXTURES);
float f6 = 1.0F;
@@ -65,16 +65,15 @@ public class RenderBubble extends Render<EntityBubble> {
GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(yaw, 1.0F, 0.0F, 0.0F);
float f11 = 3.0F;
GlStateManager.scale(f11, f11, f11);
// Bubble 'bursts' so doesn't shrink when is disappears
float s = 3 * WizardryUtilities.smoothScaleFactor(entity.isDarkOrb ? entity.lifetime : -1, entity.ticksExisted, partialTicks, 10, 10);
GlStateManager.scale(s, s, s);
double pixelwidth = (1.0d / 128);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
// tessellator.setColorRGBA_I(k1, 128);
// buffer.normal(0.0F, 1.0F, 0.0F);
if(entity.isDarkOrb){
buffer.pos(0.0F - f7, 0.0F - f8, 0.0D).tex(0, 1).endVertex();
@@ -2,6 +2,7 @@ package electroblob.wizardry.client.renderer.entity;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.entity.construct.EntityDecay;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
@@ -24,7 +25,7 @@ public class RenderDecay extends Render<EntityDecay> {
}
@Override
public void doRender(EntityDecay entity, double par2, double par4, double par6, float par8, float par9){
public void doRender(EntityDecay entity, double x, double y, double z, float entityYaw, float partialTicks){
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
@@ -34,28 +35,26 @@ public class RenderDecay extends Render<EntityDecay> {
float yOffset = 0;
GlStateManager.translate((float)par2, (float)par4 + yOffset, (float)par6);
GlStateManager.translate((float)x, (float)y + yOffset, (float)z);
this.bindTexture(TEXTURES[((EntityDecay)entity).textureIndex]);
this.bindTexture(TEXTURES[entity.textureIndex]);
float f6 = 1.0F;
float f7 = 0.5F;
float f8 = 0.5F;
GlStateManager.rotate(-90, 1, 0, 0);
float scale = 2 * Math.min(1, (float)(entity.lifetime - entity.ticksExisted) / 50f);
GlStateManager.scale(scale, scale, scale);
float s = 2 * WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 50);
GlStateManager.scale(s, s, s);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
// tessellator.setColorRGBA_I(k1, 128);
// buffer.normal(0.0F, 1.0F, 0.0F);
buffer.pos((double)(0.0F - f7), (double)(0.0F - f8), 0.01).tex(0, 1).endVertex();
buffer.pos((double)(f6 - f7), (double)(0.0F - f8), 0.01).tex(1, 1).endVertex();
buffer.pos((double)(f6 - f7), (double)(1.0F - f8), 0.01).tex(1, 0).endVertex();
buffer.pos((double)(0.0F - f7), (double)(1.0F - f8), 0.01).tex(0, 0).endVertex();
buffer.pos(0.0F - f7, 0.0F - f8, 0.01).tex(0, 1).endVertex();
buffer.pos(f6 - f7, 0.0F - f8, 0.01).tex(1, 1).endVertex();
buffer.pos(f6 - f7, 1.0F - f8, 0.01).tex(1, 0).endVertex();
buffer.pos(0.0F - f7, 1.0F - f8, 0.01).tex(0, 0).endVertex();
tessellator.draw();
@@ -1,6 +1,7 @@
package electroblob.wizardry.client.renderer.entity;
import electroblob.wizardry.entity.construct.EntityFireRing;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
@@ -18,7 +19,7 @@ import org.lwjgl.opengl.GL11;
public class RenderFireRing extends Render<EntityFireRing> {
private final ResourceLocation texture;
private float scale = 1.0f;
private float scale;
public RenderFireRing(RenderManager renderManager, ResourceLocation texture, float scale){
super(renderManager);
@@ -27,7 +28,7 @@ public class RenderFireRing extends Render<EntityFireRing> {
}
@Override
public void doRender(EntityFireRing entity, double par2, double par4, double par6, float par8, float par9){
public void doRender(EntityFireRing entity, double x, double y, double z, float entityYaw, float partialTicks){
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
@@ -37,7 +38,7 @@ public class RenderFireRing extends Render<EntityFireRing> {
float yOffset = 0;
GlStateManager.translate((float)par2, (float)par4 + yOffset, (float)par6);
GlStateManager.translate(x, y + yOffset, z);
this.bindTexture(texture);
float f6 = 1.0F;
@@ -46,15 +47,16 @@ public class RenderFireRing extends Render<EntityFireRing> {
GlStateManager.rotate(-90, 1, 0, 0);
GlStateManager.scale(scale, scale, scale);
float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10);
GlStateManager.scale(scale * s, scale * s, scale * s);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
buffer.pos((double)(0.0F - f7), (double)(0.0F - f8), 0.01).tex(0, 1).endVertex();
buffer.pos((double)(f6 - f7), (double)(0.0F - f8), 0.01).tex(1, 1).endVertex();
buffer.pos((double)(f6 - f7), (double)(1.0F - f8), 0.01).tex(1, 0).endVertex();
buffer.pos((double)(0.0F - f7), (double)(1.0F - f8), 0.01).tex(0, 0).endVertex();
buffer.pos(0.0F - f7, 0.0F - f8, 0.01).tex(0, 1).endVertex();
buffer.pos(f6 - f7, 0.0F - f8, 0.01).tex(1, 1).endVertex();
buffer.pos(f6 - f7, 1.0F - f8, 0.01).tex(1, 0).endVertex();
buffer.pos(0.0F - f7, 1.0F - f8, 0.01).tex(0, 0).endVertex();
tessellator.draw();
@@ -65,114 +67,108 @@ public class RenderFireRing extends Render<EntityFireRing> {
// Fire
GlStateManager.disableLighting();
TextureAtlasSprite icon = Minecraft.getMinecraft().getBlockRendererDispatcher()
.getModelForState(Blocks.FIRE.getDefaultState()).getParticleTexture();
int sides = 16;
float height = 1.0f;
if(s >= 1){
GlStateManager.disableLighting();
TextureAtlasSprite icon = Minecraft.getMinecraft().getBlockRendererDispatcher()
.getModelForState(Blocks.FIRE.getDefaultState()).getParticleTexture();
int sides = 16;
float height = 1.0f;
for(int k = 0; k < sides; k++){
for(int k = 0; k < sides; k++){
GlStateManager.pushMatrix();
GlStateManager.translate((float)par2, (float)par4 + 0.05f, (float)par6);
float f1 = 1.0f;
GlStateManager.scale(f1, f1, f1);
float f2 = 0.5F;
float f3 = 0.0F;
float f4 = 0.2f;
float f5 = (float)(entity.posY - entity.getEntityBoundingBox().minY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f61 = 0.0F;
int i = 0;
GlStateManager.pushMatrix();
GlStateManager.translate((float)x, (float)y + 0.05f, (float)z);
float f1 = 1.0f;
GlStateManager.scale(f1, f1, f1);
float f2 = 0.5F;
float f3 = 0.0F;
float f4 = 0.2f;
float f5 = (float)(entity.posY - entity.getEntityBoundingBox().minY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f61 = 0.0F;
int i = 0;
GlStateManager.rotate((360f / (float)sides) * k, 0, 1, 0);
GlStateManager.translate(0, 0, -2.3f);
GlStateManager.rotate((360f / (float)sides) * k, 0, 1, 0);
GlStateManager.translate(0, 0, -2.3f);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
while(f4 > 0.0F){
while(f4 > 0.0F){
this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
float f71 = icon.getMinU();
float f81 = icon.getMinV();
float f9 = icon.getMaxU();
float f10 = icon.getMaxV();
this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
float f71 = icon.getMinU();
float f81 = icon.getMinV();
float f9 = icon.getMaxU();
float f10 = icon.getMaxV();
if(i / 2 % 2 == 0){
float f11 = f9;
f9 = f71;
f71 = f11;
if(i / 2 % 2 == 0){
float f11 = f9;
f9 = f71;
f71 = f11;
}
buffer.pos((f2 - f3), (0.0F - f5), f61).tex(f9, f10).endVertex();
buffer.pos((-f2 - f3), (0.0F - f5), f61).tex(f71, f10).endVertex();
buffer.pos((-f2 - f3), (height - f5), f61).tex(f71, f81).endVertex();
buffer.pos((f2 - f3), (height - f5), f61).tex(f9, f81).endVertex();
f4 -= 0.45F;
f5 -= 0.45F;
f2 *= 0.9F;
f61 += 0.03F;
++i;
}
buffer.pos((double)(f2 - f3), (double)(0.0F - f5), (double)f61).tex((double)f9, (double)f10)
.endVertex();
buffer.pos((double)(-f2 - f3), (double)(0.0F - f5), (double)f61).tex((double)f71, (double)f10)
.endVertex();
buffer.pos((double)(-f2 - f3), (double)(height - f5), (double)f61).tex((double)f71, (double)f81)
.endVertex();
buffer.pos((double)(f2 - f3), (double)(height - f5), (double)f61).tex((double)f9, (double)f81)
.endVertex();
f4 -= 0.45F;
f5 -= 0.45F;
f2 *= 0.9F;
f61 += 0.03F;
++i;
tessellator.draw();
GlStateManager.popMatrix();
}
tessellator.draw();
GlStateManager.popMatrix();
}
for(int k = 0; k < sides; k++){
for(int k = 0; k < sides; k++){
GlStateManager.pushMatrix();
GlStateManager.translate((float)x, (float)y + 0.05f, (float)z);
float f1 = 1.0f;
GlStateManager.scale(f1, f1, f1);
float f2 = 0.5F;
float f3 = 0.0F;
float f4 = 0.2f;
float f5 = (float)(entity.posY - entity.getEntityBoundingBox().minY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f61 = 0.0F;
int i = 0;
GlStateManager.pushMatrix();
GlStateManager.translate((float)par2, (float)par4 + 0.05f, (float)par6);
float f1 = 1.0f;
GlStateManager.scale(f1, f1, f1);
float f2 = 0.5F;
float f3 = 0.0F;
float f4 = 0.2f;
float f5 = (float)(entity.posY - entity.getEntityBoundingBox().minY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f61 = 0.0F;
int i = 0;
GlStateManager.rotate((360f / (float)sides) * k, 0, 1, 0);
GlStateManager.translate(0, 0, 2.3f);
GlStateManager.rotate((360f / (float)sides) * k, 0, 1, 0);
GlStateManager.translate(0, 0, 2.3f);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
while(f4 > 0.0F){
while(f4 > 0.0F){
this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
float f71 = icon.getMinU();
float f81 = icon.getMinV();
float f9 = icon.getMaxU();
float f10 = icon.getMaxV();
this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
float f71 = icon.getMinU();
float f81 = icon.getMinV();
float f9 = icon.getMaxU();
float f10 = icon.getMaxV();
if(i / 2 % 2 == 0){
float f11 = f9;
f9 = f71;
f71 = f11;
}
if(i / 2 % 2 == 0){
float f11 = f9;
f9 = f71;
f71 = f11;
buffer.pos((f2 - f3), (0.0F - f5), f61).tex(f9, f10).endVertex();
buffer.pos((-f2 - f3), (0.0F - f5), f61).tex(f71, f10).endVertex();
buffer.pos((-f2 - f3), (height - f5), f61).tex(f71, f81).endVertex();
buffer.pos((f2 - f3), (height - f5), f61).tex(f9, f81).endVertex();
f4 -= 0.45F;
f5 -= 0.45F;
f2 *= 0.9F;
f61 += 0.03F;
++i;
}
buffer.pos((double)(f2 - f3), (double)(0.0F - f5), (double)f61).tex((double)f9, (double)f10)
.endVertex();
buffer.pos((double)(-f2 - f3), (double)(0.0F - f5), (double)f61).tex((double)f71, (double)f10)
.endVertex();
buffer.pos((double)(-f2 - f3), (double)(height - f5), (double)f61).tex((double)f71, (double)f81)
.endVertex();
buffer.pos((double)(f2 - f3), (double)(height - f5), (double)f61).tex((double)f9, (double)f81)
.endVertex();
f4 -= 0.45F;
f5 -= 0.45F;
f2 *= 0.9F;
f61 += 0.03F;
++i;
tessellator.draw();
GlStateManager.popMatrix();
}
tessellator.draw();
GlStateManager.popMatrix();
}
GlStateManager.enableLighting();
@@ -3,6 +3,7 @@ package electroblob.wizardry.client.renderer.entity;
import electroblob.wizardry.entity.construct.EntityHealAura;
import electroblob.wizardry.entity.construct.EntityMagicConstruct;
import electroblob.wizardry.util.AllyDesignationSystem;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
@@ -18,7 +19,7 @@ import org.lwjgl.opengl.GL11;
public class RenderSigil extends Render<EntityMagicConstruct> {
private final ResourceLocation texture;
private float scale = 1.0f;
private float scale;
private boolean invisibleToEnemies;
public RenderSigil(RenderManager renderManager, ResourceLocation texture, float scale, boolean invisibleToEnemies){
@@ -29,7 +30,7 @@ public class RenderSigil extends Render<EntityMagicConstruct> {
}
@Override
public void doRender(EntityMagicConstruct entity, double par2, double par4, double par6, float par8, float par9){
public void doRender(EntityMagicConstruct entity, double x, double y, double z, float entityYaw, float partialTicks){
// Makes the sigil invisible to enemies of the player that created it
if(this.invisibleToEnemies){
@@ -48,7 +49,7 @@ public class RenderSigil extends Render<EntityMagicConstruct> {
float yOffset = 0;
GlStateManager.translate((float)par2, (float)par4 + yOffset, (float)par6);
GlStateManager.translate((float)x, (float)y + yOffset, (float)z);
this.bindTexture(texture);
float f6 = 1.0F;
@@ -60,17 +61,17 @@ public class RenderSigil extends Render<EntityMagicConstruct> {
// Healing aura rotates slowly
if(entity instanceof EntityHealAura) GlStateManager.rotate(entity.ticksExisted / 3.0f, 0, 0, 1);
GlStateManager.scale(scale, scale, scale);
float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10);
GlStateManager.scale(scale * s, scale * s, scale * s);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
// tessellator.setColorRGBA_I(k1, 128);
// buffer.normal(0.0F, 1.0F, 0.0F);
buffer.pos((double)(0.0F - f7), (double)(0.0F - f8), 0.01).tex(0, 1).endVertex();
buffer.pos((double)(f6 - f7), (double)(0.0F - f8), 0.01).tex(1, 1).endVertex();
buffer.pos((double)(f6 - f7), (double)(1.0F - f8), 0.01).tex(1, 0).endVertex();
buffer.pos((double)(0.0F - f7), (double)(1.0F - f8), 0.01).tex(0, 0).endVertex();
buffer.pos(0.0F - f7, 0.0F - f8, 0.01).tex(0, 1).endVertex();
buffer.pos(f6 - f7, 0.0F - f8, 0.01).tex(1, 1).endVertex();
buffer.pos(f6 - f7, 1.0F - f8, 0.01).tex(1, 0).endVertex();
buffer.pos(0.0F - f7, 1.0F - f8, 0.01).tex(0, 0).endVertex();
tessellator.draw();
@@ -12,7 +12,6 @@ import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;
@@ -43,13 +42,10 @@ public class RenderZombieSpawner extends Render<EntityZombieSpawner> {
// The visible bit
GlStateManager.pushMatrix();
int animationTicks = 10;
float age = entity.ticksExisted + partialTicks;
float s = age < animationTicks ? age/animationTicks : MathHelper.clamp((entity.lifetime - age) / animationTicks, 0, 1);
s = (float)Math.pow(s, 0.4); // Smooths the animation
float s = WizardryUtilities.smoothScaleFactor(entity.lifetime, entity.ticksExisted, partialTicks, 10, 10);
GlStateManager.scale(s, s, s);
GlStateManager.rotate(age * 2, 0, 1, 0);
GlStateManager.rotate((entity.ticksExisted + partialTicks) * 2, 0, 1, 0);
this.bindTexture(TEXTURE);
@@ -6,6 +6,7 @@ import electroblob.wizardry.item.ISpellCastingItem;
import electroblob.wizardry.item.ItemArtefact;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.tileentity.TileEntityMagicLight;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@@ -42,12 +43,7 @@ public class RenderMagicLight extends TileEntitySpecialRenderer<TileEntityMagicL
GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5);
int animationTicks = 10;
float age = tileentity.timer + partialTicks;
float s = tileentity.getLifetime() < 0 ? 1 : MathHelper.clamp((tileentity.getLifetime() - age) / animationTicks, 0, 1);
if(age < animationTicks) s = age/animationTicks;
s = (float)Math.pow(s, 0.4); // Smooths the animation
float s = WizardryUtilities.smoothScaleFactor(tileentity.getLifetime(), tileentity.timer, partialTicks, 10, 10);
GlStateManager.scale(s, s, s);
// Renders the aura effect
@@ -1000,4 +1000,22 @@ public final class WizardryUtilities {
return fields;
}
/**
* Calculates a factor between 0 and 1 that results in a smooth, aesthetically-pleasing animation when used to scale
* things. Mainly for rendering, but can be used anywhere since it's just a mathematical formula.
* @param lifetime The lifetime of the thing being animated, in ticks (if this is negative, disappearing is ignored)
* @param ticksExisted The current age of the thing being animated, in ticks
* @param partialTicks The current partial tick time
* @param startLength The length of the appearing animation, in ticks
* @param endLength The length of the disappearing animation, in ticks
* @return A fraction between 0 and 1, with the value at the very start and end being 0 and the constant middle
* section having a value of 1.
*/
public static float smoothScaleFactor(int lifetime, int ticksExisted, float partialTicks, int startLength, int endLength){
float age = ticksExisted + partialTicks;
float s = MathHelper.clamp(age < startLength || lifetime < 0 ? age/startLength : (lifetime - age) / endLength, 0, 1);
s = (float)Math.pow(s, 0.4); // Smooths the animation
return s;
}
}