SKILLAPI里粒子动画效果(particle animation)中,有着角度angle的选项。
它可以让粒子在2D平面上生成,但是做不到在3D平面中做出立体的圆环形
另外skllapi作者写的代码计算机图形没学过的我也读不懂
只是知道球形生成是通过两个for循环套里面搞出来的
若能解决,必定重谢 我QQ1250447239
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package com.sucy.skill.dynamic.mechanic;
- import com.sucy.skill.SkillAPI;
- import com.sucy.skill.api.util.ParticleHelper;
- import java.util.Iterator;
- import java.util.List;
- import org.bukkit.Location;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- public class ParticleAnimationMechanic extends MechanicComponent {
- public ParticleAnimationMechanic() {
- }
- public String getKey() {
- return "particle animation";
- }
- public boolean execute(LivingEntity caster, int level, List<LivingEntity> targets) {
- if (targets.size() == 0) {
- return false;
- } else {
- this.settings.set("level", level);
- double ht = this.parseValues(caster, "h-translation", level, 0.0D);
- double vt = this.parseValues(caster, "v-translation", level, 0.0D);
- double dr = this.parseValues(caster, "duration", level, 3.0D);
- double radius = this.parseValues(caster, "radius", level, 3.0D);
- int particles = (int)this.parseValues(caster, "particles", level, 10.0D);
- new ParticleAnimationMechanic.ParticleTask(caster, targets, level, ht, vt, dr, radius, particles);
- return targets.size() > 0;
- }
- }
- private class ParticleTask extends BukkitRunnable {
- private List<LivingEntity> targets;
- private double[] rots;
- private Vector offset;
- private Vector dir;
- private double forward;
- private double right;
- private double upward;
- private int steps;
- private int freq;
- private int angle;
- private int startAngle;
- private int duration;
- private int life;
- private int hc;
- private int vc;
- private int hl;
- private int vl;
- private double ht;
- private double vt;
- private double radius;
- private double cos;
- private double sin;
- private int particles;
- int step = 0;
- public ParticleTask(LivingEntity caster, List<LivingEntity> targets, int level, double ht, double vt, double dr, double radius, int particles) {
- this.targets = targets;
- this.forward = ParticleAnimationMechanic.this.settings.getDouble("forward", 0.0D);
- this.upward = ParticleAnimationMechanic.this.settings.getDouble("upward", 0.0D);
- this.right = ParticleAnimationMechanic.this.settings.getDouble("right", 0.0D);
- this.steps = ParticleAnimationMechanic.this.settings.getInt("steps", 1);
- this.freq = (int)(ParticleAnimationMechanic.this.settings.getDouble("frequency", 1.0D) * 20.0D);
- this.angle = ParticleAnimationMechanic.this.settings.getInt("angle", 0);
- this.startAngle = ParticleAnimationMechanic.this.settings.getInt("start", 0);
- this.duration = this.steps * (int)(20.0D * dr);
- this.life = 0;
- this.hc = ParticleAnimationMechanic.this.settings.getInt("h-cycles", 1);
- this.vc = ParticleAnimationMechanic.this.settings.getInt("v-cycles", 1);
- this.ht = ht;
- this.vt = vt;
- this.hl = this.duration / this.hc;
- this.vl = this.duration / this.vc;
- this.cos = Math.cos((double)this.angle * 3.141592653589793D / (double)(180 * this.duration));
- this.sin = Math.sin((double)this.angle * 3.141592653589793D / (double)(180 * this.duration));
- this.rots = new double[targets.size() * 2];
- this.radius = radius;
- this.particles = particles;
- for(int i = 0; i < targets.size(); ++i) {
- Vector dir = ((LivingEntity)targets.get(i)).getLocation().getDirection().setY(0).normalize();
- this.rots[i * 2] = dir.getX();
- this.rots[i * 2 + 1] = dir.getZ();
- }
- this.dir = new Vector(1, 0, 0);
- this.offset = new Vector(this.forward, this.upward, this.right);
- double sc = Math.cos((double)this.startAngle * 3.141592653589793D / 180.0D);
- double ss = Math.sin((double)this.startAngle * 3.141592653589793D / 180.0D);
- this.rotate(this.offset, sc, ss);
- this.rotate(this.dir, sc, ss);
- SkillAPI.schedule(this, 0, 1);
- }
- public void run() {
- ++this.step;
- if (this.step >= this.freq) {
- this.step = 0;
- try {
- for(int i = 0; i < this.steps; ++i) {
- int j = 0;
- Iterator var3 = this.targets.iterator();
- while(var3.hasNext()) {
- LivingEntity target = (LivingEntity)var3.next();
- Location tlc = target.getLocation();
- this.rotate(this.offset, this.rots[j], this.rots[j + 1]);
- tlc.add(this.offset);
- ParticleHelper.play(tlc, ParticleAnimationMechanic.this.settings,target.getLocation());
- tlc.subtract(this.offset);
- this.rotate(this.offset, this.rots[j++], -this.rots[j++]);
- }
- ++this.life;
- this.rotate(this.offset, this.cos, this.sin);
- this.rotate(this.dir, this.cos, this.sin);
- double dx = this.radAt(this.life) - this.radAt(this.life - 1);
- this.offset.setX(this.offset.getX() + dx * this.dir.getX());
- this.offset.setZ(this.offset.getZ() + dx * this.dir.getZ());
- this.offset.setY(this.upward + this.heightAt(this.life));
- }
- } catch (Exception var6) {
- this.cancel();
- }
- if (this.life >= this.duration) {
- this.cancel();
- }
- }
- }
- private double heightAt(int step) {
- return this.vt * (double)(this.vl - Math.abs(this.vl - step % (2 * this.vl))) / (double)this.vl;
- }
- private double radAt(int step) {
- return this.ht * (double)(this.hl - Math.abs(this.hl - step % (2 * this.hl))) / (double)this.hl;
- }
- private void rotate(Vector vec, double cos, double sin) {
- double x = vec.getX() * cos - vec.getZ() * sin;
- vec.setZ(vec.getX() * sin + vec.getZ() * cos);
- vec.setX(x);
- }
- }
- }
粘兽 发表于 2020-10-29 01:34
你可以看看莫老的粒子教程
里面有说如何绘制一个3D的球
https://www.jianshu.com/p/d5af0392194c ...
我考虑的是先画一个xy平面的圆,再把这个圆上每一个点通过向量操作全部绕中心旋转一圈达到绘制xz平面的圆的效果,但是这样做我不会算怎么画一个与xz平面有夹角的圆,考虑了如何上下变化向量,但是绕垂直轴旋转后是不是还需要进行y轴上的移动确保起点在中心坐标?有点想不通了。
。。。。。。。
其实命令方块也能还原
。。。。。
粒子,向量运算,角度运算。。。。