package projectzombie.entity.particle; import static org.lwjgl.opengl.GL15.glBindBuffer; import static org.lwjgl.opengl.GL15.glBufferData; import static org.lwjgl.opengl.GL15.glGenBuffers; import java.util.Random; import org.lwjgl.opengl.GL33; import gl_engine.MathHelpers; import gl_engine.matrix.Matrix4; import gl_engine.texture.TextureRef3D; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.entity.EntityParticle; import projectzombie.init.Models; import projectzombie.model.IModel; import projectzombie.model.Model; import projectzombie.model.ModelVertical; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; public class ParticleBreak extends EntityParticle implements IModel { protected static final Random rand = new Random(); protected class Break { TextureRef3D ref; Vec3d velocity; Vec3d pos; boolean moving; int time, flags; } protected Break[] particles; private int ibo, vbo, vao; private boolean generated; protected int dead, still, time; protected double still_ypos; protected boolean do_gravity; public Vec2d getParticleSize() { return new Vec2d(0.1, 0.1); } public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model) { this(pos, velocity, model, 200, 0.05); } public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count) { this(pos, velocity, model, count, 0.05); } protected Break createParticle( IModel model, TextureRef3D ref, int tex_id, Vec3d pos, Vec3d velocity, float[] verticies, double velocity_up_multiplier, double model_height, int i) { Break particle = new Break(); particle.pos = pos.add(new Vec3d(0, rand.nextDouble() * model_height, 0)); particle.velocity = velocity.multiply(rand.nextDouble()).add( MathHelpers.moveTowards2(0.01, rand.nextDouble() * MathHelpers.TWO_PI).xny().add( new Vec3d(0, rand.nextDouble() * velocity_up_multiplier, 0))); particle.ref = ref; particle.moving = true; particle.flags = ((int)verticies[tex_id * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000; return particle; } protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) { super(new Vec3d(pos.x, 0, pos.z), new Vec3d(0, 0, 0)); if(pos.squareDistance(Main.player.getPos()) > 32) { count = 0; } this.hasGravity = false; double model_height = model.getHeight(); TextureRef3D[] textures = model.getTextures(); float[] verticies = model.getVerticies(); count *= model_height; particles = new Break[count]; for(int i=0;i 0.75) { dead += 1; } } protected void onAllDead() { if(getPos().squareDistance(Main.player.getPos()) > 32) { kill(); } } protected boolean isStill(Break particle) { return particle.pos.y < 0; } protected void onStill(Break particle) { particle.moving = false; particle.pos.y = still_ypos; still += 1; } @Override public void tick(Chunk chunk, Layer layer) { super.tick(chunk, layer); if(isDead()) { return; } time -= 1; if(dead == particles.length - 1) { onAllDead(); return; } if(still == particles.length) { onAllStill(); return; } for(int i=0;i<(particles.length - dead);i++) { Break particle = particles[i]; if(!particle.moving) { continue; } if(isStill(particle)) { onStill(particle); continue; } if(do_gravity) { particle.velocity.y -= MathHelpers.FallSpeed; } particle.pos = particle.pos.add(particle.velocity); } } @Override public void kill() { this.free(); super.kill(); } @Override public IModel getModel() { if(isDead()) { return Models.EMPTY; } return this; } @Override public int[] getIndicies() { int[] indicies = new int[getIndexSize()]; int upto = 0; for(int i=0;i