mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed spheres
This commit is contained in:
parent
ee7c67afe4
commit
3789c31062
2 changed files with 52 additions and 24 deletions
|
@ -4,13 +4,14 @@ import net.minecraft.client.MinecraftClient;
|
|||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.particle.ParticleTextureSheet;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.minelittlepony.client.render.MagicGlow;
|
||||
import com.minelittlepony.unicopia.client.render.model.SphereModel;
|
||||
import com.minelittlepony.unicopia.magic.Caster;
|
||||
import com.minelittlepony.unicopia.particles.ParticleHandle.Attachment;
|
||||
|
@ -24,8 +25,13 @@ public class SphereParticle extends Particle implements Attachment {
|
|||
protected float blue;
|
||||
protected float alpha;
|
||||
|
||||
protected float prevRadius;
|
||||
protected float radius;
|
||||
|
||||
protected int steps;
|
||||
protected float lerpIncrement;
|
||||
protected float toRadius;
|
||||
|
||||
private Caster<?> caster;
|
||||
|
||||
private static final SphereModel model = new SphereModel();
|
||||
|
@ -64,7 +70,9 @@ public class SphereParticle extends Particle implements Attachment {
|
|||
@Override
|
||||
public void setAttribute(int key, Object value) {
|
||||
if (key == 0) {
|
||||
radius = (float)value;
|
||||
toRadius = (float)value;
|
||||
steps = 20;
|
||||
lerpIncrement = (toRadius - radius) / steps;
|
||||
}
|
||||
if (key == 1) {
|
||||
int tint = (int)value;
|
||||
|
@ -94,6 +102,14 @@ public class SphereParticle extends Particle implements Attachment {
|
|||
}
|
||||
|
||||
setPos(e.getX(), e.getY(), e.getZ());
|
||||
|
||||
prevPosX = e.lastRenderX;
|
||||
prevPosY = e.lastRenderY;
|
||||
prevPosZ = e.lastRenderZ;
|
||||
}
|
||||
|
||||
if (steps-- > 0) {
|
||||
radius += lerpIncrement;
|
||||
}
|
||||
} else {
|
||||
radius *= 0.9998281;
|
||||
|
@ -102,16 +118,29 @@ public class SphereParticle extends Particle implements Attachment {
|
|||
|
||||
@Override
|
||||
public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float tickDelta) {
|
||||
|
||||
if (alpha <= 0 || radius <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
MatrixStack matrices = new MatrixStack();
|
||||
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||
model.setPosition(x, y, z);
|
||||
model.setPosition(
|
||||
MathHelper.lerp(tickDelta, prevPosX, x) - camera.getPos().x,
|
||||
MathHelper.lerp(tickDelta, prevPosY, y) - camera.getPos().y,
|
||||
MathHelper.lerp(tickDelta, prevPosZ, z) - camera.getPos().z
|
||||
);
|
||||
model.setRotation(0, 0, 0);
|
||||
model.render(matrices, radius, immediate.getBuffer(RenderLayer.getTranslucent()), 1, 1, red, green, blue, alpha);
|
||||
|
||||
float lerpedRad = MathHelper.lerp(tickDelta, prevRadius, radius);
|
||||
|
||||
model.render(matrices, lerpedRad + 0.1F, immediate.getBuffer(MagicGlow.getRenderLayer()), 1, 1, red, green, blue, alpha);
|
||||
|
||||
model.render(matrices, lerpedRad - 0.1F, immediate.getBuffer(MagicGlow.getRenderLayer()), 1, 1, red * 0.9F, green * 0.9F, blue * 0.9F, Math.min(1, alpha + 0.2F));
|
||||
|
||||
immediate.draw();
|
||||
|
||||
prevRadius = radius;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.minelittlepony.unicopia.client.render.model;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.util.math.Matrix4f;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
|
@ -18,7 +17,7 @@ public class SphereModel {
|
|||
protected Quaternion rotZ = Quaternion.IDENTITY;
|
||||
|
||||
public void setPosition(double x, double y, double z) {
|
||||
pos = new Vec3d(x, y, z).subtract(BlockEntityRenderDispatcher.INSTANCE.camera.getPos());
|
||||
pos = new Vec3d(x, y, z);
|
||||
}
|
||||
|
||||
public void setRotation(float x, float y, float z) {
|
||||
|
@ -50,20 +49,18 @@ public class SphereModel {
|
|||
|
||||
Matrix4f model = matrices.getModel();
|
||||
|
||||
final double num_rings = 30;
|
||||
final double num_sectors = 30;
|
||||
final double two_pi = Math.PI * 2;
|
||||
final double num_rings = 40;
|
||||
final double num_sectors = 40;
|
||||
final double pi = Math.PI;
|
||||
final double two_pi = Math.PI * 2F;
|
||||
final double zenithIncrement = Math.PI / num_rings;
|
||||
final double azimuthIncrement = two_pi / num_sectors;
|
||||
|
||||
double radius = 1;
|
||||
|
||||
for(double zenith = 0; zenith < Math.PI; zenith += zenithIncrement) {
|
||||
for(double azimuth = 0; azimuth < two_pi; azimuth += azimuthIncrement) {
|
||||
drawVertex(model, vertexWriter, radius, zenith, azimuth, light, overlay, r, g, b, a); // top left
|
||||
drawVertex(model, vertexWriter, radius, zenith + zenithIncrement, azimuth, light, overlay, r, g, b, a); // top right
|
||||
drawVertex(model, vertexWriter, radius, zenith + zenithIncrement, azimuth + azimuthIncrement, light, overlay, r, g, b, a); // bottom right
|
||||
drawVertex(model, vertexWriter, radius, zenith, azimuth + azimuthIncrement, light, overlay, r, g, b, a); // bottom left
|
||||
for(double zenith = -pi; zenith < pi; zenith += zenithIncrement) {
|
||||
for(double azimuth = -two_pi; azimuth < two_pi; azimuth += azimuthIncrement) {
|
||||
drawQuad(model, vertexWriter, radius, zenith, azimuth, zenithIncrement, azimuthIncrement, light, overlay, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +70,13 @@ public class SphereModel {
|
|||
double zenithIncrement, double azimuthIncrement,
|
||||
int light, int overlay, float r, float g, float b, float a) {
|
||||
|
||||
drawVertex(model, vertexWriter, radius, zenith, azimuth, light, overlay, r, g, b, a);
|
||||
|
||||
drawVertex(model, vertexWriter, radius, zenith + zenithIncrement, azimuth, light, overlay, r, g, b, a);
|
||||
|
||||
drawVertex(model, vertexWriter, radius, zenith + zenithIncrement, azimuth + azimuthIncrement, light, overlay, r, g, b, a);
|
||||
|
||||
drawVertex(model, vertexWriter, radius, zenith, azimuth + azimuthIncrement, light, overlay, r, g, b, a);
|
||||
}
|
||||
|
||||
protected void drawVertex(Matrix4f model, VertexConsumer vertexWriter,
|
||||
|
@ -81,18 +84,14 @@ public class SphereModel {
|
|||
int light, int overlay, float r, float g, float b, float a) {
|
||||
Vector4f position = convertToCartesianCoord(radius, zenith, azimuth);
|
||||
position.transform(model);
|
||||
vertexWriter.vertex(position.getX(), position.getY(), position.getZ(),
|
||||
r, g, b, a,
|
||||
0, 0, overlay, light, 0, 0, 0);
|
||||
vertexWriter.vertex(position.getX(), position.getY(), position.getZ(), r, g, b, a, 0, 0, overlay, light, 0, 0, 0);
|
||||
}
|
||||
|
||||
protected Vector4f convertToCartesianCoord(double radius, double zenith, double azimuth) {
|
||||
protected Vector4f convertToCartesianCoord(double r, double theta, double phi) {
|
||||
|
||||
double tanq = Math.tan(zenith);
|
||||
|
||||
double x = Math.pow(radius, 2) / (2 * tanq) - (tanq / 2);
|
||||
double y = x * tanq;
|
||||
double z = radius / Math.tan(azimuth);
|
||||
double x = r * Math.sin(theta) * Math.cos(phi);
|
||||
double y = r * Math.sin(theta) * Math.sin(phi);
|
||||
double z = r * Math.cos(theta);
|
||||
|
||||
return new Vector4f((float)x, (float)y, (float)z, 1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue