12496

SKILLAPI里粒子动画效果(particle animation)中,有着角度angle的选项。
它可以让粒子在2D平面上生成,但是做不到在3D平面中做出立体的圆环形
另外skllapi作者写的代码计算机图形没学过的我也读不懂
只是知道球形生成是通过两个for循环套里面搞出来的
若能解决,必定重谢 我QQ1250447239
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //

  5. package com.sucy.skill.dynamic.mechanic;

  6. import com.sucy.skill.SkillAPI;
  7. import com.sucy.skill.api.util.ParticleHelper;
  8. import java.util.Iterator;
  9. import java.util.List;
  10. import org.bukkit.Location;
  11. import org.bukkit.entity.LivingEntity;
  12. import org.bukkit.scheduler.BukkitRunnable;
  13. import org.bukkit.util.Vector;

  14. public class ParticleAnimationMechanic extends MechanicComponent {
  15.     public ParticleAnimationMechanic() {
  16.     }

  17.     public String getKey() {
  18.         return "particle animation";
  19.     }

  20.     public boolean execute(LivingEntity caster, int level, List<LivingEntity> targets) {
  21.         if (targets.size() == 0) {
  22.             return false;
  23.         } else {
  24.             this.settings.set("level", level);
  25.             double ht = this.parseValues(caster, "h-translation", level, 0.0D);
  26.             double vt = this.parseValues(caster, "v-translation", level, 0.0D);
  27.             double dr = this.parseValues(caster, "duration", level, 3.0D);
  28.             double radius = this.parseValues(caster, "radius", level, 3.0D);
  29.             int particles = (int)this.parseValues(caster, "particles", level, 10.0D);
  30.             new ParticleAnimationMechanic.ParticleTask(caster, targets, level, ht, vt, dr, radius, particles);
  31.             return targets.size() > 0;
  32.         }
  33.     }

  34.     private class ParticleTask extends BukkitRunnable {
  35.         private List<LivingEntity> targets;
  36.         private double[] rots;
  37.         private Vector offset;
  38.         private Vector dir;
  39.         private double forward;
  40.         private double right;
  41.         private double upward;
  42.         private int steps;
  43.         private int freq;
  44.         private int angle;
  45.         private int startAngle;
  46.         private int duration;
  47.         private int life;
  48.         private int hc;
  49.         private int vc;
  50.         private int hl;
  51.         private int vl;
  52.         private double ht;
  53.         private double vt;
  54.         private double radius;
  55.         private double cos;
  56.         private double sin;
  57.         private int particles;
  58.         int step = 0;

  59.         public ParticleTask(LivingEntity caster, List<LivingEntity> targets, int level, double ht, double vt, double dr, double radius, int particles) {
  60.             this.targets = targets;
  61.             this.forward = ParticleAnimationMechanic.this.settings.getDouble("forward", 0.0D);
  62.             this.upward = ParticleAnimationMechanic.this.settings.getDouble("upward", 0.0D);
  63.             this.right = ParticleAnimationMechanic.this.settings.getDouble("right", 0.0D);
  64.             this.steps = ParticleAnimationMechanic.this.settings.getInt("steps", 1);
  65.             this.freq = (int)(ParticleAnimationMechanic.this.settings.getDouble("frequency", 1.0D) * 20.0D);
  66.             this.angle = ParticleAnimationMechanic.this.settings.getInt("angle", 0);
  67.             this.startAngle = ParticleAnimationMechanic.this.settings.getInt("start", 0);
  68.             this.duration = this.steps * (int)(20.0D * dr);
  69.             this.life = 0;
  70.             this.hc = ParticleAnimationMechanic.this.settings.getInt("h-cycles", 1);
  71.             this.vc = ParticleAnimationMechanic.this.settings.getInt("v-cycles", 1);
  72.             this.ht = ht;
  73.             this.vt = vt;
  74.             this.hl = this.duration / this.hc;
  75.             this.vl = this.duration / this.vc;
  76.             this.cos = Math.cos((double)this.angle * 3.141592653589793D / (double)(180 * this.duration));
  77.             this.sin = Math.sin((double)this.angle * 3.141592653589793D / (double)(180 * this.duration));
  78.             this.rots = new double[targets.size() * 2];
  79.             this.radius = radius;
  80.             this.particles = particles;

  81.             for(int i = 0; i < targets.size(); ++i) {
  82.                 Vector dir = ((LivingEntity)targets.get(i)).getLocation().getDirection().setY(0).normalize();
  83.                 this.rots[i * 2] = dir.getX();
  84.                 this.rots[i * 2 + 1] = dir.getZ();
  85.             }

  86.             this.dir = new Vector(1, 0, 0);
  87.             this.offset = new Vector(this.forward, this.upward, this.right);
  88.             double sc = Math.cos((double)this.startAngle * 3.141592653589793D / 180.0D);
  89.             double ss = Math.sin((double)this.startAngle * 3.141592653589793D / 180.0D);
  90.             this.rotate(this.offset, sc, ss);
  91.             this.rotate(this.dir, sc, ss);
  92.             SkillAPI.schedule(this, 0, 1);
  93.         }

  94.         public void run() {
  95.             ++this.step;
  96.             if (this.step >= this.freq) {
  97.                 this.step = 0;

  98.                 try {
  99.                     for(int i = 0; i < this.steps; ++i) {
  100.                         int j = 0;
  101.                         Iterator var3 = this.targets.iterator();

  102.                         while(var3.hasNext()) {
  103.                             LivingEntity target = (LivingEntity)var3.next();
  104.                             Location tlc = target.getLocation();
  105.                             this.rotate(this.offset, this.rots[j], this.rots[j + 1]);
  106.                             tlc.add(this.offset);


  107.                             ParticleHelper.play(tlc, ParticleAnimationMechanic.this.settings,target.getLocation());
  108.                             tlc.subtract(this.offset);
  109.                             this.rotate(this.offset, this.rots[j++], -this.rots[j++]);
  110.                         }

  111.                         ++this.life;
  112.                         this.rotate(this.offset, this.cos, this.sin);
  113.                         this.rotate(this.dir, this.cos, this.sin);
  114.                         double dx = this.radAt(this.life) - this.radAt(this.life - 1);
  115.                         this.offset.setX(this.offset.getX() + dx * this.dir.getX());
  116.                         this.offset.setZ(this.offset.getZ() + dx * this.dir.getZ());
  117.                         this.offset.setY(this.upward + this.heightAt(this.life));
  118.                     }
  119.                 } catch (Exception var6) {
  120.                     this.cancel();
  121.                 }

  122.                 if (this.life >= this.duration) {
  123.                     this.cancel();
  124.                 }

  125.             }
  126.         }

  127.         private double heightAt(int step) {
  128.             return this.vt * (double)(this.vl - Math.abs(this.vl - step % (2 * this.vl))) / (double)this.vl;
  129.         }

  130.         private double radAt(int step) {
  131.             return this.ht * (double)(this.hl - Math.abs(this.hl - step % (2 * this.hl))) / (double)this.hl;
  132.         }

  133.         private void rotate(Vector vec, double cos, double sin) {
  134.             double x = vec.getX() * cos - vec.getZ() * sin;
  135.             vec.setZ(vec.getX() * sin + vec.getZ() * cos);
  136.             vec.setX(x);
  137.         }
  138.     }
  139. }
复制代码



粘兽
你可以看看莫老的粒子教程
里面有说如何绘制一个3D的球
https://www.jianshu.com/p/d5af0392194c

William_Shi
粘兽 发表于 2020-10-29 01:34
你可以看看莫老的粒子教程
里面有说如何绘制一个3D的球
https://www.jianshu.com/p/d5af0392194c ...

我考虑的是先画一个xy平面的圆,再把这个圆上每一个点通过向量操作全部绕中心旋转一圈达到绘制xz平面的圆的效果,但是这样做我不会算怎么画一个与xz平面有夹角的圆,考虑了如何上下变化向量,但是绕垂直轴旋转后是不是还需要进行y轴上的移动确保起点在中心坐标?有点想不通了。

602723113
https://github.com/602723113/Par ... pobject/Sphere.java

可以来看看这个的代码,可以生成出一个致密的球

zwmsPVP
。。。。。。。

zwmsPVP
其实命令方块也能还原

zwmsPVP
。。。。。

npcman001
粒子,向量运算,角度运算。。。。