Drawing a disk shape

Discussion in 'Plugin Development' started by Noobidoo, Feb 12, 2011.

Thread Status:
Not open for further replies.
  1. This has per say nothing to do whit bukkitplugins but related never the less.
    I have tryed to to generate circles out wards but the results in holes, so i thought i look at the //cyl from world edit(fantastic plugin [​IMG]) but got some interesting results to say the least http://imgur.com/um7mZ.
    Code:
     public int makeCylinder(Vector pos, int radius,int height,Player player)
      {
      int x = 0;
      int z = radius;
      int d = (5 - radius * 4) / 4;
      int affected = 0;
    
      if (height == 0)
        return 0;
      if (height < 0) {
        height = -height;
        pos = pos.subtract(new Vector(0, height, 0));
      }
    
      if (pos.getBlockY() - height - 1 < 0)
        height = pos.getBlockY() + 1;
      else if (pos.getBlockY() + height - 1 > 127) {
        height = 127 - pos.getBlockY() + 1;
      }
    
      affected += makeCylinderPoints(pos, x, z, height,player);
    
      while (x < z) {
        x++;
    
        if (d >= 0) {
          z--;
          d += 2 * (x - z) + 1;
        } else {
          d += 2 * x + 1;
        }
    
        affected += makeCylinderPoints(pos, x, z, height,player);
      }
    
      return affected;
      }
        private int makeCylinderPoints(Vector center, int x, int z,int height,Player player)
      {
        int affected = 0;
        Vector pos;
        if (x == z) {
            for (int y = 0; y < height; y++)
            {
                for (int z2 = -z; z2 <= z; z2++) {
                    pos=center.add(new Vector(x,y,z2));
                    player.getWorld().getBlockAt(pos.getBlockX(),pos.getBlockY(),pos.getBlockZ()).getFace(BlockFace.DOWN, 1).setType(Material.CLAY);
                    pos=center.add(new Vector(-x,y,z2));
                    player.getWorld().getBlockAt(pos.getBlockX(),pos.getBlockY(),pos.getBlockZ()).getFace(BlockFace.DOWN, 1).setType(Material.CLAY);
                    affected += 2;
                }
            }
        }
        else if (x < z) {
            for (int y = 0; y < height; y++) {
                for (int x2 = -x; x2 <= x; x2++) {
                    for (int z2 = -z; z2 <= z; z2++) {
                        pos=center.add(new Vector(x2,y,z2));
                        player.getWorld().getBlockAt(pos.getBlockX(),pos.getBlockY(),pos.getBlockZ()).getFace(BlockFace.DOWN, 1).setType(Material.CLAY);
                        affected++;
                    }
                    pos=center.add(new Vector(z,y,x2));
                    player.getWorld().getBlockAt(pos.getBlockX(),pos.getBlockY(),pos.getBlockZ()).getFace(BlockFace.DOWN, 1).setType(Material.CLAY);
                    pos=center.add(new Vector(-z,y,x2));
                    player.getWorld().getBlockAt(pos.getBlockX(),pos.getBlockY(),pos.getBlockZ()).getFace(BlockFace.DOWN, 1).setType(Material.CLAY);
                    affected += 2;
                }
            }
        }
        return affected;
      }
    Thats code i'm using, if some one cud give me some pointer's id appreciate it.

    I also tried to calculate what i should render in a square by applying some geometry but i din't get a good circle from that.
    Code:
    private void RenderCircle(int blockX, int blockZ, int Radian, Player player) {
            int startx,startz;
            player.sendMessage("in RenderCircle");
                for (int i = blockX-Radian; i <= Radian+blockX; i++) {
                    for (int j = blockZ-Radian; j < Radian+blockZ; j++) {
                        player.sendMessage("genChunk bool: "+Chunkgen.genchunk);
                           if (Chunkgen.genchunk==true) {
                               int hyp=(int) Math.rint(Math.sqrt(Math.pow(Math.abs(i-blockX), 2)+Math.pow(Math.abs(j-blockZ), 2)));
                               player.sendMessage("Radina: "+Radian+" Hyp:"+hyp);
                               player.sendMessage("Shuld generating chunk: "+i+":"+j);
                               if(hyp<=Radian)
                               {
                                   player.sendMessage("generating chunk: "+i+":"+j);
                                   player.getWorld().getBlockAt(i,player.getLocation().getBlockY(),j).getFace(BlockFace.DOWN, 1).setType(Material.BRICK);
                            }
                        }else{
                            lastPoint = new Point(i,j);
                            break;
                        }
                    }
                    if(Radian-blockX==i)
                        lastPoint=null;
                    if (Chunkgen.genchunk==false)
                        break;
                }
        }
     
Thread Status:
Not open for further replies.

Share This Page