mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2024-12-31 20:02:12 +00:00
Now using a lookup table for sin/cos operations for styles
This commit is contained in:
parent
99b2e3796a
commit
5a808dbc61
20 changed files with 133 additions and 80 deletions
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -25,9 +26,9 @@ public class ParticleStyleBeam extends DefaultParticleStyle {
|
|||
List<PParticle> particles = new ArrayList<>();
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = slice * i;
|
||||
double newX = location.getX() + radius * Math.cos(angle);
|
||||
double newX = location.getX() + radius * MathL.cos(angle);
|
||||
double newY = location.getY() + (this.step / 10D) - 1;
|
||||
double newZ = location.getZ() + radius * Math.sin(angle);
|
||||
double newZ = location.getZ() + radius * MathL.sin(angle);
|
||||
particles.add(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
|
||||
}
|
||||
return particles;
|
||||
|
|
|
@ -9,6 +9,7 @@ import dev.esophose.playerparticles.particles.PParticle;
|
|||
import dev.esophose.playerparticles.particles.PPlayer;
|
||||
import dev.esophose.playerparticles.particles.ParticleEffect;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -73,8 +74,8 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
|
|||
private void spawnFirework(final Location location, final PPlayer pplayer, final ParticlePair particle, final Random random) {
|
||||
double angle = random.nextDouble() * Math.PI * 2;
|
||||
double distanceFrom = 1.25 + random.nextDouble() * 1.5;
|
||||
double dx = Math.sin(angle) * distanceFrom;
|
||||
double dz = Math.cos(angle) * distanceFrom;
|
||||
double dx = MathL.sin(angle) * distanceFrom;
|
||||
double dz = MathL.cos(angle) * distanceFrom;
|
||||
final Location loc = location.clone().add(dx, 1, dz);
|
||||
final int fuse = 3 + random.nextInt(3);
|
||||
Player player = pplayer.getPlayer();
|
||||
|
@ -102,9 +103,9 @@ public class ParticleStyleCelebration extends DefaultParticleStyle {
|
|||
double v = random.nextDouble();
|
||||
double theta = 2 * Math.PI * u;
|
||||
double phi = Math.acos(2 * v - 1);
|
||||
double dx = radius * Math.sin(phi) * Math.cos(theta);
|
||||
double dy = radius * Math.sin(phi) * Math.sin(theta);
|
||||
double dz = radius * Math.cos(phi);
|
||||
double dx = radius * MathL.sin(phi) * MathL.cos(theta);
|
||||
double dy = radius * MathL.sin(phi) * MathL.sin(theta);
|
||||
double dz = radius * MathL.cos(phi);
|
||||
|
||||
particles.add(new PParticle(this.location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -51,12 +52,12 @@ public class ParticleStyleCompanion extends DefaultParticleStyle {
|
|||
Vector vector = new Vector();
|
||||
|
||||
double t = (Math.PI / this.numParticles) * this.step;
|
||||
double r = Math.sin(t) * this.size;
|
||||
double r = MathL.sin(t) * this.size;
|
||||
double s = 2 * Math.PI * t;
|
||||
|
||||
vector.setX(this.xFactor * r * Math.cos(s) + this.xOffset);
|
||||
vector.setZ(this.zFactor * r * Math.sin(s) + this.zOffset);
|
||||
vector.setY(this.yFactor * this.size * Math.cos(t) + this.yOffset);
|
||||
vector.setX(this.xFactor * r * MathL.cos(s) + this.xOffset);
|
||||
vector.setZ(this.zFactor * r * MathL.sin(s) + this.zOffset);
|
||||
vector.setY(this.yFactor * this.size * MathL.cos(t) + this.yOffset);
|
||||
|
||||
for (int i = 0; i < this.particlesPerIteration; i++) {
|
||||
particles.add(new PParticle(location.clone().subtract(vector)));
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -27,9 +28,9 @@ public class ParticleStyleHalo extends DefaultParticleStyle {
|
|||
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = slice * i;
|
||||
double dx = radius * Math.cos(angle);
|
||||
double dx = radius * MathL.cos(angle);
|
||||
double dy = 1.5;
|
||||
double dz = radius * Math.sin(angle);
|
||||
double dz = radius * MathL.sin(angle);
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
return particles;
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
|||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticleEffect;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -27,32 +28,32 @@ public class ParticleStyleInvocation extends DefaultParticleStyle {
|
|||
// Circle around everything, spawn less often
|
||||
if (this.circleStep % 5 == 0) {
|
||||
for (int i = 0; i < this.numSteps; i++) {
|
||||
double dx = Math.cos(Math.PI * 2 * ((double) i / this.numSteps)) * this.radius;
|
||||
double dx = MathL.cos(Math.PI * 2 * ((double) i / this.numSteps)) * this.radius;
|
||||
double dy = -0.9;
|
||||
double dz = Math.sin(Math.PI * 2 * ((double) i / this.numSteps)) * this.radius;
|
||||
double dz = MathL.sin(Math.PI * 2 * ((double) i / this.numSteps)) * this.radius;
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
}
|
||||
|
||||
// Orbit going clockwise
|
||||
for (int i = 0; i < this.points; i++) {
|
||||
double dx = Math.cos(this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double dx = MathL.cos(this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double dy = -0.9;
|
||||
double dz = Math.sin(this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double dz = MathL.sin(this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double angle = Math.atan2(dz, dx);
|
||||
double xAng = -Math.cos(angle);
|
||||
double zAng = -Math.sin(angle);
|
||||
double xAng = -MathL.cos(angle);
|
||||
double zAng = -MathL.sin(angle);
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz), xAng, 0, zAng, speed, true));
|
||||
}
|
||||
|
||||
// Orbit going counter-clockwise
|
||||
for (int i = 0; i > -this.points; i--) {
|
||||
double dx = Math.cos(-this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double dx = MathL.cos(-this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double dy = -0.9;
|
||||
double dz = Math.sin(-this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double dz = MathL.sin(-this.step + (Math.PI * 2 * ((double) i / this.points))) * this.radius;
|
||||
double angle = Math.atan2(dz, dx);
|
||||
double xAng = -Math.cos(angle);
|
||||
double zAng = -Math.sin(angle);
|
||||
double xAng = -MathL.cos(angle);
|
||||
double zAng = -MathL.sin(angle);
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz), xAng, 0, zAng, speed, true));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -21,8 +22,8 @@ public class ParticleStyleOrbit extends DefaultParticleStyle {
|
|||
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
||||
List<PParticle> particles = new ArrayList<>();
|
||||
for (int i = 0; i < orbs; i++) {
|
||||
double dx = -(Math.cos((this.step / (double) numSteps) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
|
||||
double dz = -(Math.sin((this.step / (double) numSteps) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
|
||||
double dx = -(MathL.cos((this.step / (double) numSteps) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
|
||||
double dz = -(MathL.sin((this.step / (double) numSteps) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
|
||||
particles.add(new PParticle(location.clone().add(dx, 0, dz)));
|
||||
}
|
||||
return particles;
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -27,7 +28,7 @@ public class ParticleStylePopper extends DefaultParticleStyle {
|
|||
double radius = (1 - (double) this.step / this.maxStep);
|
||||
for (int i = 0; i < this.helices; i++) {
|
||||
double angle = this.step * this.radials + (2 * Math.PI * i / this.helices);
|
||||
Vector v = new Vector(Math.cos(angle) * radius, this.step * this.grow - 1, Math.sin(angle) * radius);
|
||||
Vector v = new Vector(MathL.cos(angle) * radius, this.step * this.grow - 1, MathL.sin(angle) * radius);
|
||||
|
||||
particles.add(new PParticle(location.clone().add(v)));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
|||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticleEffect;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -26,12 +27,12 @@ public class ParticleStylePulse extends DefaultParticleStyle {
|
|||
|
||||
if (this.step == 0) {
|
||||
for (int i = 0; i < this.points; i++) {
|
||||
double dx = Math.cos(Math.PI * 2 * ((double) i / this.points)) * this.radius;
|
||||
double dx = MathL.cos(Math.PI * 2 * ((double) i / this.points)) * this.radius;
|
||||
double dy = -0.9;
|
||||
double dz = Math.sin(Math.PI * 2 * ((double) i / this.points)) * this.radius;
|
||||
double dz = MathL.sin(Math.PI * 2 * ((double) i / this.points)) * this.radius;
|
||||
double angle = Math.atan2(dz, dx);
|
||||
double xAng = Math.cos(angle);
|
||||
double zAng = Math.sin(angle);
|
||||
double xAng = MathL.cos(angle);
|
||||
double zAng = MathL.sin(angle);
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz), xAng, 0, zAng, speed, true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -24,9 +25,9 @@ public class ParticleStyleQuadhelix extends DefaultParticleStyle {
|
|||
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
||||
List<PParticle> particles = new ArrayList<>();
|
||||
for (int i = 0; i < orbs; i++) {
|
||||
double dx = -(Math.cos((this.stepX / (double) maxStepX) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))) * ((maxStepY - Math.abs(this.stepY)) / (double) maxStepY);
|
||||
double dx = -(MathL.cos((this.stepX / (double) maxStepX) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))) * ((maxStepY - Math.abs(this.stepY)) / (double) maxStepY);
|
||||
double dy = (this.stepY / (double) maxStepY) * 1.5;
|
||||
double dz = -(Math.sin((this.stepX / (double) maxStepX) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))) * ((maxStepY - Math.abs(this.stepY)) / (double) maxStepY);
|
||||
double dz = -(MathL.sin((this.stepX / (double) maxStepX) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))) * ((maxStepY - Math.abs(this.stepY)) / (double) maxStepY);
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
return particles;
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -23,10 +24,10 @@ public class ParticleStyleRings extends DefaultParticleStyle {
|
|||
double ring1 = Math.PI / (maxStep / 2D) * this.step;
|
||||
double ring2 = Math.PI / (maxStep / 2D) * (((this.step + maxStep / 2D) % maxStep));
|
||||
|
||||
particles.add(new PParticle(location.clone().add(Math.cos(ring1), Math.sin(ring1), Math.sin(ring1))));
|
||||
particles.add(new PParticle(location.clone().add(Math.cos(ring1 + Math.PI), Math.sin(ring1), Math.sin(ring1 + Math.PI))));
|
||||
particles.add(new PParticle(location.clone().add(Math.cos(ring2), Math.sin(ring2), Math.sin(ring2))));
|
||||
particles.add(new PParticle(location.clone().add(Math.cos(ring2 + Math.PI), Math.sin(ring2), Math.sin(ring2 + Math.PI))));
|
||||
particles.add(new PParticle(location.clone().add(MathL.cos(ring1), MathL.sin(ring1), MathL.sin(ring1))));
|
||||
particles.add(new PParticle(location.clone().add(MathL.cos(ring1 + Math.PI), MathL.sin(ring1), MathL.sin(ring1 + Math.PI))));
|
||||
particles.add(new PParticle(location.clone().add(MathL.cos(ring2), MathL.sin(ring2), MathL.sin(ring2))));
|
||||
particles.add(new PParticle(location.clone().add(MathL.cos(ring2 + Math.PI), MathL.sin(ring2), MathL.sin(ring2 + Math.PI))));
|
||||
|
||||
return particles;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -24,9 +25,9 @@ public class ParticleStyleSphere extends DefaultParticleStyle {
|
|||
double v = Math.random();
|
||||
double theta = 2 * Math.PI * u;
|
||||
double phi = Math.acos(2 * v - 1);
|
||||
double dx = radius * Math.sin(phi) * Math.cos(theta);
|
||||
double dy = radius * Math.sin(phi) * Math.sin(theta);
|
||||
double dz = radius * Math.cos(phi);
|
||||
double dx = radius * MathL.sin(phi) * MathL.cos(theta);
|
||||
double dy = radius * MathL.sin(phi) * MathL.sin(theta);
|
||||
double dz = radius * MathL.cos(phi);
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,27 +3,15 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ParticleStyleSpin extends DefaultParticleStyle {
|
||||
|
||||
private static double[] cos, sin;
|
||||
private static final int maxSteps = 30;
|
||||
private int step = 0;
|
||||
|
||||
static {
|
||||
cos = new double[maxSteps];
|
||||
sin = new double[maxSteps];
|
||||
|
||||
int i = 0;
|
||||
for (double n = 0; n < Math.PI * 2; n += Math.PI * 2 / maxSteps) {
|
||||
cos[i] = Math.cos(n);
|
||||
sin[i] = Math.sin(n);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleStyleSpin() {
|
||||
super("spin", true, true, -0.5);
|
||||
|
@ -31,10 +19,12 @@ public class ParticleStyleSpin extends DefaultParticleStyle {
|
|||
|
||||
@Override
|
||||
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
||||
double slice = (Math.PI * 2 / maxSteps) * this.step;
|
||||
|
||||
double radius = .5;
|
||||
double newX = location.getX() + radius * cos[this.step];
|
||||
double newX = location.getX() + radius * MathL.cos(slice);
|
||||
double newY = location.getY() + 1.5;
|
||||
double newZ = location.getZ() + radius * sin[this.step];
|
||||
double newZ = location.getZ() + radius * MathL.sin(slice);
|
||||
return Collections.singletonList(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -19,9 +20,9 @@ public class ParticleStyleSpiral extends DefaultParticleStyle {
|
|||
public List<PParticle> getParticles(ParticlePair particle, Location location) {
|
||||
List<PParticle> particles = new ArrayList<>();
|
||||
for (int stepY = -60; stepY < 60; stepY += 10) {
|
||||
double dx = -(Math.cos(((this.stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
|
||||
double dx = -(MathL.cos(((this.stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
|
||||
double dy = stepY / 45D;
|
||||
double dz = -(Math.sin(((this.stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
|
||||
double dz = -(MathL.sin(((this.stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
|
||||
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
|
||||
}
|
||||
return particles;
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -23,8 +24,8 @@ public class ParticleStyleTwins extends DefaultParticleStyle {
|
|||
|
||||
int i = 0;
|
||||
for (double n = 0; n < numSteps; n++) {
|
||||
cos[i] = -Math.cos(n / numSteps * Math.PI * 2);
|
||||
sin[i] = -Math.sin(n / numSteps * Math.PI * 2);
|
||||
cos[i] = -MathL.cos(n / numSteps * Math.PI * 2);
|
||||
sin[i] = -MathL.sin(n / numSteps * Math.PI * 2);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -50,7 +51,7 @@ public class ParticleStyleVortex extends DefaultParticleStyle {
|
|||
double radius = 2 * (1 - (double) this.step / this.maxStep);
|
||||
for (int i = 0; i < this.helices; i++) {
|
||||
double angle = this.step * this.radials + (2 * Math.PI * i / this.helices);
|
||||
Vector v = new Vector(Math.cos(angle) * radius, this.step * this.grow - 1, Math.sin(angle) * radius);
|
||||
Vector v = new Vector(MathL.cos(angle) * radius, this.step * this.grow - 1, MathL.sin(angle) * radius);
|
||||
|
||||
particles.add(new PParticle(location.clone().add(v)));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
|||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticleEffect;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -24,12 +25,12 @@ public class ParticleStyleWhirl extends DefaultParticleStyle {
|
|||
double speed = this.getSpeedByEffect(particle.getEffect());
|
||||
|
||||
for (int i = 0; i < this.points; i++) {
|
||||
double dx = Math.cos(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double dx = MathL.cos(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double dy = -0.9;
|
||||
double dz = Math.sin(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double dz = MathL.sin(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double angle = Math.atan2(dz, dx);
|
||||
double xAng = Math.cos(angle);
|
||||
double zAng = Math.sin(angle);
|
||||
double xAng = MathL.cos(angle);
|
||||
double zAng = MathL.sin(angle);
|
||||
particles.add(new PParticle(location.clone().add(0, dy, 0), xAng, 0, zAng, speed, true));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
|||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticleEffect;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
|
@ -25,12 +26,12 @@ public class ParticleStyleWhirlwind extends DefaultParticleStyle {
|
|||
|
||||
// Orbit going clockwise
|
||||
for (int i = 0; i < this.points; i++) {
|
||||
double dx = Math.cos(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double dx = MathL.cos(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double dy = -0.9;
|
||||
double dz = Math.sin(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double dz = MathL.sin(this.step + (Math.PI * 2 * ((double) i / this.points)));
|
||||
double angle = Math.atan2(dz, dx);
|
||||
double xAng = Math.cos(angle);
|
||||
double zAng = Math.sin(angle);
|
||||
double xAng = MathL.cos(angle);
|
||||
double zAng = MathL.sin(angle);
|
||||
particles.add(new PParticle(location.clone().add(0, dy, 0), xAng, 0, zAng, speed, true));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.esophose.playerparticles.styles;
|
|||
import dev.esophose.playerparticles.config.CommentedFileConfiguration;
|
||||
import dev.esophose.playerparticles.particles.PParticle;
|
||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||
import dev.esophose.playerparticles.util.MathL;
|
||||
import dev.esophose.playerparticles.util.VectorUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -22,9 +23,9 @@ public class ParticleStyleWings extends DefaultParticleStyle {
|
|||
List<PParticle> particles = new ArrayList<>();
|
||||
if (this.spawnTimer == 0) {
|
||||
for (double t = 0; t < Math.PI * 2; t += Math.PI / 48) {
|
||||
double offset = (Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(t * 4) - Math.pow(Math.sin(t / 12), 5)) / 2;
|
||||
double x = Math.sin(t) * offset;
|
||||
double y = Math.cos(t) * offset;
|
||||
double offset = (Math.pow(Math.E, MathL.cos(t)) - 2 * MathL.cos(t * 4) - Math.pow(MathL.sin(t / 12), 5)) / 2;
|
||||
double x = MathL.sin(t) * offset;
|
||||
double y = MathL.cos(t) * offset;
|
||||
Vector v = VectorUtils.rotateAroundAxisY(new Vector(x, y, -0.3), -Math.toRadians(location.getYaw()));
|
||||
particles.add(new PParticle(location.clone().add(v.getX(), v.getY(), v.getZ())));
|
||||
}
|
||||
|
|
46
src/main/java/dev/esophose/playerparticles/util/MathL.java
Normal file
46
src/main/java/dev/esophose/playerparticles/util/MathL.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package dev.esophose.playerparticles.util;
|
||||
|
||||
/**
|
||||
* Credit goes to Riven from this thread:
|
||||
* http://www.java-gaming.org/topics/extremely-fast-sine-cosine/36469/view.html
|
||||
*/
|
||||
public final class MathL {
|
||||
|
||||
private static final int SIN_BITS, SIN_MASK, SIN_COUNT;
|
||||
private static final float radFull, radToIndex;
|
||||
private static final float degFull, degToIndex;
|
||||
private static final float[] sin, cos;
|
||||
|
||||
static {
|
||||
SIN_BITS = 12;
|
||||
SIN_MASK = ~(-1 << SIN_BITS);
|
||||
SIN_COUNT = SIN_MASK + 1;
|
||||
|
||||
radFull = (float) (Math.PI * 2.0);
|
||||
degFull = (float) (360.0);
|
||||
radToIndex = SIN_COUNT / radFull;
|
||||
degToIndex = SIN_COUNT / degFull;
|
||||
|
||||
sin = new float[SIN_COUNT];
|
||||
cos = new float[SIN_COUNT];
|
||||
|
||||
for (int i = 0; i < SIN_COUNT; i++) {
|
||||
sin[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull);
|
||||
cos[i] = (float) Math.cos((i + 0.5f) / SIN_COUNT * radFull);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 360; i += 90) {
|
||||
sin[(int) (i * degToIndex) & SIN_MASK] = (float) Math.sin(i * Math.PI / 180.0);
|
||||
cos[(int) (i * degToIndex) & SIN_MASK] = (float) Math.cos(i * Math.PI / 180.0);
|
||||
}
|
||||
}
|
||||
|
||||
public static float sin(double rad) {
|
||||
return sin[(int) (rad * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static float cos(double rad) {
|
||||
return cos[(int) (rad * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
}
|
|
@ -44,8 +44,8 @@ public final class VectorUtils {
|
|||
*/
|
||||
public static Vector rotateAroundAxisX(Vector v, double angle) {
|
||||
double y, z, cos, sin;
|
||||
cos = Math.cos(angle);
|
||||
sin = Math.sin(angle);
|
||||
cos = MathL.cos(angle);
|
||||
sin = MathL.sin(angle);
|
||||
y = v.getY() * cos - v.getZ() * sin;
|
||||
z = v.getY() * sin + v.getZ() * cos;
|
||||
return v.setY(y).setZ(z);
|
||||
|
@ -60,8 +60,8 @@ public final class VectorUtils {
|
|||
*/
|
||||
public static Vector rotateAroundAxisY(Vector v, double angle) {
|
||||
double x, z, cos, sin;
|
||||
cos = Math.cos(angle);
|
||||
sin = Math.sin(angle);
|
||||
cos = MathL.cos(angle);
|
||||
sin = MathL.sin(angle);
|
||||
x = v.getX() * cos + v.getZ() * sin;
|
||||
z = v.getX() * -sin + v.getZ() * cos;
|
||||
return v.setX(x).setZ(z);
|
||||
|
@ -76,8 +76,8 @@ public final class VectorUtils {
|
|||
*/
|
||||
public static Vector rotateAroundAxisZ(Vector v, double angle) {
|
||||
double x, y, cos, sin;
|
||||
cos = Math.cos(angle);
|
||||
sin = Math.sin(angle);
|
||||
cos = MathL.cos(angle);
|
||||
sin = MathL.sin(angle);
|
||||
x = v.getX() * cos - v.getY() * sin;
|
||||
y = v.getX() * sin + v.getY() * cos;
|
||||
return v.setX(x).setY(y);
|
||||
|
@ -124,10 +124,10 @@ public final class VectorUtils {
|
|||
double yaw = Math.toRadians(-1 * (yawDegrees + 90));
|
||||
double pitch = Math.toRadians(-pitchDegrees);
|
||||
|
||||
double cosYaw = Math.cos(yaw);
|
||||
double cosPitch = Math.cos(pitch);
|
||||
double sinYaw = Math.sin(yaw);
|
||||
double sinPitch = Math.sin(pitch);
|
||||
double cosYaw = MathL.cos(yaw);
|
||||
double cosPitch = MathL.cos(pitch);
|
||||
double sinYaw = MathL.sin(yaw);
|
||||
double sinPitch = MathL.sin(pitch);
|
||||
|
||||
double initialX, initialY, initialZ;
|
||||
double x, y, z;
|
||||
|
|
Loading…
Reference in a new issue