Sphere Generation

Discussion in 'Plugin Development' started by EvilPeanut, Oct 20, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    mindless728

    considering he hasn't posted the code, i doubt he has it

    @EvilPeanut yeah, pics or it didn't happen (this includes code), and yes, i just called you out
     
  2. Offline

    thescreem

    If you can code a //set command with undo, maximum block changes and block placement ordering in 10 lines, then why would you need help to create sphere code?
     
    Quantum64 likes this.
  3. Offline

    EvilPeanut

    Look guys, theres a first for everything ok?
    Ive never had to learn how to do spheres before so stop whining.
    And:
    + Accept that sometimes people find faster ways of doing things
    + I did put debug speed testers into the worldedit code and my code to test them.
     
  4. Offline

    mindless728

    we can accept that algorithms can be sped up, we are just asking for proof and not just your word

    so all in all
    1) post your code
    2) post a diff or the modified world edit code

    then we can all test it and see if your claims are true, without doing this you just look like a dolt
     
    r3Fuze likes this.
  5. Offline

    fury

    this
     
  6. Offline

    thehutch

    Cant you just use the formula for the volume of a sphere?
    4/3 pi r^3
     
  7. He probably wont >.>
     
  8. Offline

    pyraetos

    Look, why not use my API for a sphere. It follows the 3D Function of a sphere in Discreet Mathematics.
    And the Region class is just a cuboid, which you apparently already have.
    Code:java
    1. package org.nerdycast.util;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.World;
    8. import org.bukkit.block.Block;
    9.  
    10. public class Sphere {
    11.  
    12. private int xx;
    13. private int yy;
    14. private int zz;
    15.  
    16. private HashMap<Integer,Block> set;
    17.  
    18. private int radius;
    19.  
    20. public Sphere(Location center, int radius){
    21. this.radius = radius;
    22. int xx = (int)Math.floor(center.getX());
    23. int yy = (int)Math.floor(center.getY());
    24. int zz = (int)Math.floor(center.getZ());
    25.  
    26. Region region = new Region(new Location(center.getWorld(),xx+radius,yy+radius,zz+radius),new Location(center.getWorld(),xx-radius,yy-radius,zz-radius));
    27. HashMap<Integer,Block> set = region.getVolume();
    28.  
    29. this.xx = xx;
    30. this.yy = yy;
    31. this.zz = zz;
    32. this.set = set;
    33.  
    34. }
    35.  
    36. public void set(int id){
    37. for(int counter = 0; counter <= set.size() - 1; counter++){
    38. int a = (set.get(counter).getX() - xx)*(set.get(counter).getX() - xx);
    39. int b = (set.get(counter).getY() - yy)*(set.get(counter).getY() - yy);
    40. int c = (set.get(counter).getZ() - zz)*(set.get(counter).getZ() - zz);
    41. if(a +b +c <= (radius*radius)) set.get(counter).setType(Material.getMaterial(id));
    42. }
    43. }
     
  9. Offline

    nisovin

    Look, nobody is blaming you for asking how to do something. Additionally, everyone here accepts that people can find faster ways of doing things. The issue is you.

    I suggested you look at WorldEdit's code, and you reply saying that the code is terrible and that you can do it much better. You obviously aren't aware, but the author of WorldEdit has been creating plugins a lot longer than you have, and is respected in the community.I believe his plugins are some of the most used of any Bukkit plugins. Your claims that you can do better only show how little understanding you have.

    Also, anyone can see by glancing at your plugins that you really don't know what you're doing. So when you say you can do better than WorldEdit, nobody believes you because it's obvious you can't.

    I am glad to see you've dropped the annoying habit of capitalizing every word.

    Now, there has been some help given in this thread. I posted the link to WorldEdit's sphere generation code, and some other people gave some general suggestions on how to do this. So, hopefully you'll be able to figure it out from here. Just don't go around insulting people, and don't assume you know better than others. The fact that you have to ask a question here means there are things you don't know. Which is fine! You have to learn somehow.
     
  10. Offline

    FearGrump

    oh god. i love this. a battle of the DEVs.
     
    Sayshal likes this.
  11. Offline

    przerwap

    I know right. Sadly noone's responded to my post here :'(

    Also, @pyraetos
    That code is sloppy, slow, and inefficient.

    Here is VoxelSniper's Ball brush code:

    Brush.java (open)

    This code is formatted with coordinate mirroring, which reduces the number of Trig calculations to 1/8 of what it would normally have to calculate. The code is formatted to avoid affecting any block twice due to the nature of mirroring a shape with a single block center.
    Code:
    package com.thevoxelbox.brush;
    
    import com.thevoxelbox.brush.perform.PerformBrush;
    import com.thevoxelbox.vMessage;
    import com.thevoxelbox.vSniper;
    import org.bukkit.ChatColor;
    
    /**
     *
     * @author Piotr
     */
    public class Ball extends PerformBrush {
    
        private double trueCircle = 0;
    
        @Override
        public void arrow(vSniper v) {
            bx = tb.getX();
            by = tb.getY();
            bz = tb.getZ();
            ball(v);
        }
    
        @Override
        public void powder(vSniper v) {
            arrow(v);
        }
    
        @Override
        public void info(vMessage vm) {
            vm.brushName("Ball");
            vm.size();
        }
    
        @Override
        public void parameters(String[] par, vSniper v) {
            if (par[1].equalsIgnoreCase("info")) {
                v.p.sendMessage(ChatColor.GOLD + "Ball Brush Parameters:");
                v.p.sendMessage(ChatColor.AQUA + "/b b true -- will use a true sphere algorithm instead of the skinnier version with classic sniper nubs. /b b false will switch back. (false is default)");
                return;
            }
            for (int x = 1; x < par.length; x++) {
                if (par[x].startsWith("true")) {
                    trueCircle = 0.5;
                    v.p.sendMessage(ChatColor.AQUA + "True circle mode ON.");
                    continue;
                } else if (par[x].startsWith("false")) {
                    trueCircle = 0;
                    v.p.sendMessage(ChatColor.AQUA + "True circle mode OFF.");
                    continue;
                } else {
                    v.p.sendMessage(ChatColor.RED + "Invalid brush parameters! use the info parameter to display parameter info.");
                }
            }
        }
    
        public void ball(vSniper v) {
            int bsize = v.brushSize;
    
            double bpow = Math.pow(bsize + trueCircle, 2);
            double zpow;
            double xpow;
    
            current.perform(s.getBlockAt(bx, by, bz));
    
            for (int i = 1; i <= bsize; i++) {
                current.perform(s.getBlockAt(bx + i, by, bz));
                current.perform(s.getBlockAt(bx - i, by, bz));
                current.perform(s.getBlockAt(bx, by + i, bz));
                current.perform(s.getBlockAt(bx, by - i, bz));
                current.perform(s.getBlockAt(bx, by, bz + i));
                current.perform(s.getBlockAt(bx, by, bz - i));
            }
    
            for (int i = 1; i <= bsize; i++) {
                zpow = Math.pow(i, 2);
                for (int j = 1; j <= bsize; j++) {
                    if (zpow + Math.pow(j, 2) <= bpow) {
                        current.perform(s.getBlockAt(bx + i, by, bz + j));
                        current.perform(s.getBlockAt(bx + i, by, bz - j));
                        current.perform(s.getBlockAt(bx - i, by, bz + j));
                        current.perform(s.getBlockAt(bx - i, by, bz - j));
                        current.perform(s.getBlockAt(bx + i, by + j, bz));
                        current.perform(s.getBlockAt(bx + i, by - j, bz));
                        current.perform(s.getBlockAt(bx - i, by + j, bz));
                        current.perform(s.getBlockAt(bx - i, by - j, bz));
                        current.perform(s.getBlockAt(bx, by + i, bz + j));
                        current.perform(s.getBlockAt(bx, by + i, bz - j));
                        current.perform(s.getBlockAt(bx, by - i, bz + j));
                        current.perform(s.getBlockAt(bx, by - i, bz - j));
                    }
                }
            }
    
            for (int z = 1; z <= bsize; z++) {
                zpow = Math.pow(z, 2);
                for (int x = 1; x <= bsize; x++) {
                    xpow = Math.pow(x, 2);
                    for (int y = 1; y <= bsize; y++) {
                        if ((xpow + Math.pow(y, 2) + zpow) <= bpow) {
                            current.perform(s.getBlockAt(bx + x, by + y, bz + z));
                            current.perform(s.getBlockAt(bx + x, by + y, bz - z));
                            current.perform(s.getBlockAt(bx - x, by + y, bz + z));
                            current.perform(s.getBlockAt(bx - x, by + y, bz - z));
                            current.perform(s.getBlockAt(bx + x, by - y, bz + z));
                            current.perform(s.getBlockAt(bx + x, by - y, bz - z));
                            current.perform(s.getBlockAt(bx - x, by - y, bz + z));
                            current.perform(s.getBlockAt(bx - x, by - y, bz - z));
                        }
                    }
                }
            }
    
            if (current.getUndo().getSize() > 0) {
                v.hashUndo.put(v.hashEn, current.getUndo());
                v.hashEn++;
            }
        }
    }
    
    


    If that's too confusing for you, or you simply don't care about affecting a block twice, than this would be all you would need:

    Does not care about affecting same block twice (open)

    Code:
          for (int z = 0; z <= bsize; z++) {
                zpow = Math.pow(z, 2);
                for (int x = 0; x <= bsize; x++) {
                    xpow = Math.pow(x, 2);
                    for (int y = 0; y <= bsize; y++) {
                        if ((xpow + Math.pow(y, 2) + zpow) <= bpow) {
                            current.perform(s.getBlockAt(bx + x, by + y, bz + z));
                            current.perform(s.getBlockAt(bx + x, by + y, bz - z));
                            current.perform(s.getBlockAt(bx - x, by + y, bz + z));
                            current.perform(s.getBlockAt(bx - x, by + y, bz - z));
                            current.perform(s.getBlockAt(bx + x, by - y, bz + z));
                            current.perform(s.getBlockAt(bx + x, by - y, bz - z));
                            current.perform(s.getBlockAt(bx - x, by - y, bz + z));
                            current.perform(s.getBlockAt(bx - x, by - y, bz - z));
                        }
                    }
                }
            }
    


    If still too confuzing, and all you care about is making a sphere:
    Does not care for mirroring (open)

    Code:
          for (int z = -bsize; z <= bsize; z++) {
                zpow = Math.pow(z, 2);
                for (int x = -bsize; x <= bsize; x++) {
                    xpow = Math.pow(x, 2);
                    for (int y = -bsize; y <= bsize; y++) {
                        if ((xpow + Math.pow(y, 2) + zpow) <= bpow) {
                            current.perform(s.getBlockAt(bx + x, by + y, bz + z));
                        }
                    }
                }
            }
    
     
    thehutch and r3Fuze like this.
  12. Offline

    thehutch

    You make it look sooo effortless when you post that :p May I ask if that is faster than SK89q's?
     
  13. Offline

    codename_B

    Who cares? The OP's code works instantly and also decreases ram usage for the whole server and provides a MySQL database in 10 lines or less.
     
  14. Offline

    przerwap

    Prolly, from what I can see at a glance he calculates the entire 3D distance (x^2+y^2+z^2) for every single coordinate, but in reality you only need to calculate x^2 once per loop of the x for loop. Same with y, and when it comes to z is just if(squaredX + squaredY + z^2 < squaredRadius) { block_Is_Within_Sphere(); }

    Let's just say that my code is made for Rapid firing, maaaany times. And Sq's code is made for .. iunno what... making a sphere I guess.
     
  15. Offline

    EvilPeanut

    but the author of WorldEdit has been creating plugins a lot longer than you have, doesnt meen there better!

    ** Cleared some of your post, Please don't post anything insulting :) - Silentspy **
     
  16. Offline

    przerwap

    Hey dawg, not only did I show multiple ways and explanations as to how to make a sphere, but I also told some other kid that his code sucked. While at that you still have yet to post any example of your code, nor any proof that you even can program at all.

    Step up to the plate and man up. Show us what you've got.
     
  17. Offline

    codename_B

    Can I have your code? I'm making a WorldEdit alternative and need to create spheres.
     
    p000ison, thehutch and r3Fuze like this.
  18. Offline

    nisovin

    Just because you told me not to, I'm going to reply. I'd like to point out that my response was much longer than four words, and that I said many things I hadn't said before. You, however, keep saying the same thing over and over. Perhaps it is you that is the robot.
     
    r3Fuze and thehutch like this.
  19. Offline

    thehutch

    /sarcasm?
     
  20. Offline

    tha d0ctor

    [​IMG]

    How can you even argue that your is better? First we don't have proof that it even exists (see above pic). Perhaps it is more efficient to create a simple sphere but WorldEdit's code has so many more features that aren't even comparable to what you are describing.

    There is no way your bare bones code checks for max blocks, has a certain build order,and has an //undo function that goes back several actions.

    I've heard enough. Your thread has turned into a immature and pointless rant. Obviously you don't want help. Flame on!
     
  21. Offline

    undeadmach1ne

    in this thread: we have a choice between ragequitting the forums or flaming stupid kids until we get banned.
     
  22. Offline

    Zaros

    I'm waiting on this. Sounds like a breakthrough for the sake of science. Does your code write itself as needed too?
     
    Sayshal, Slamakans and r3Fuze like this.
  23. Offline

    codename_B

  24. Offline

    Slamakans

    Sup dawg, I heard you like spoilers so I put a spoiler on yo spoiler so you can watch yo spoiler on yo spoiler while snape kills dumbledore.

    On-topic:
    I'd really be able to use that code of yours to implement in my alternative to WE, so far it does 80% of what WE does, but in 40 lines. I only need your 10 lines.
     
  25. Offline

    fury

    haha for some reason they wouldn't accept me to the forums at 12 (When I signed up) so I just went with a random birth year. XD Maybe I should update that now...

    "Once your birthday has been entered, it cannot be changed. Please contact an administrator if it is incorrect." Crap. Well there goes that idea for about two years... XD

    Sure, we could do that. I'm having more trouble with Eclipse than with Java itself though. XD I don't have Skype at the moment, but I do have a webcam so I could set it up... Idk pm me if you actually want to go through with this.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  26. Offline

    p000ison

    Hahaha this is funny to read xDD Soooooo where is your code now after a yeah? Did you ever finished it?
     
  27. I tried generating some sphere code but I went a little wrong and ended up creating a jagged cube :p. But it serves my purposes so I haven't bothered changing it, although I probably will want to.

     
  28. Offline

    XbannisherX

    one does not say worldedit code is bullshit
     
    Atomicbeast101 and bennie3211 like this.
  29. I also need an realy fast code for this, using the squared distance already, but it does take more than 30 to generate an world full of planets using my plugin (mutlwirodl), mayby its because of the light updates?
     
  30. Offline

    sn00pbom

    u all just butthurt

    my dogz cowd is best

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
Thread Status:
Not open for further replies.

Share This Page