Solved Particle rotation matrix

Discussion in 'Spigot Plugin Development' started by ollinator01, Jan 4, 2017.

  1. Hello,
    i tried to insert the rotation matrix into my code, but i'm failed. I spawn particles in a shape of a butterfly and want to spawn it in the direction of the yaw on the back of the player.
    This is my current code.:
    Code (Text):
    package fr;

    import java.util.ArrayList;

    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;


    public class Main extends JavaPlugin {
        public int shed;
       
        ArrayList<Player> part = new ArrayList<>();
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] agrs) {
            if(label.equalsIgnoreCase("fr")){
                if(sender instanceof Player){
                    Player p = (Player) sender;
                    if(!part.contains(p)){
                        part.add(p);
                        p.sendMessage(ChatColor.DARK_GREEN + "Aktiviert!");
                        display(p);                
                    } else if(part.contains(p)){
                        getServer().getScheduler().cancelTask(shed);
                        p.sendMessage(ChatColor.DARK_PURPLE + "Deaktiviert!");
                        part.remove(p);
                    }      
                   
                }
               
            }
           
            return false;
        }
       
        public void display(Player p){  
            shed = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){    
                public void run() {
                       
                    for (double theta = 0; theta < 2 * Math.PI; theta += Math.PI / 54) {
                        Location location = p.getLocation().subtract(0.0D, 0.3D, 0.0D);
                        location.setYaw(p.getEyeLocation().getYaw());
                        Vector v1 = location.getDirection().normalize().multiply(-0.3D);
                        v1.setY(0);
                        location.add(v1);
         
                        double bracket = (Math.exp(Math.cos(theta)) - 2 * Math.cos(4 * theta) - Math.pow(Math.sin(theta / 12), 5));
                        double x = Math.sin(theta) * bracket * 0.7;
                        double y = Math.cos(theta) * bracket * 0.7 + 1;
                       
                        location.add(x, y, 0);
             
                        ParticleEffect.CRIT_MAGIC.display(0.0F, 0.0F, 0.0F, 0.0F, 1, location, 100.0);
                    }
                }
               
            }, 4L, 4L);
               
        }
       
        public static Vector rotateAroundAxisY(Vector v, double angle)
        {
          double cos = Math.cos(angle);
          double sin = Math.sin(angle);
          double x = v.getX() * cos + v.getZ() * sin;
          double z = v.getX() * -sin + v.getZ() * cos;
          return v.setX(x).setZ(z);
        }
       
    }

    Thanks for your help! :)
     
  2. Where you familiar with rotation matrixes?
    You need to apply a yz'x'' intrinsic rotation to achieve minecrafts yaw, pitch, roll.
    If you don't need the roll angle, you can set it to zero, but maybe you'll need it later to do a rotation animation or something...

    https://en.wikipedia.org/wiki/Euler_angles:
    [​IMG]