1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

[SOLVED] Create a sphere of particles.

Discussion in 'Development' started by Muqsit, Feb 12, 2017.

  1. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I guess the title says it all.
    PHP:
    /** @var Vector3 $center */
    $diameter 10;
    $radius $diameter 2;
    //π = M_PI;
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I had the same thoughts but the loop would consume a heavy amount of time.
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I finally managed to do it by converting this code I found on Bukkit Forums to PHP. Here's the code for future readers...
    PHP:
        /**
        * PMMP should add this to their
        * Position.php
        */
        
    private static function getDirection($pos) : Vector3
        
    {
            
    $y = -sin(deg2rad($pos->pitch));
            
    $xz cos(deg2rad($pos->pitch));
            
    $x = -$xz sin(deg2rad($pos->yaw));
            
    $z $xz cos(deg2rad($pos->yaw));
            return new 
    Vector3($x$y$z);
        }

        private static function 
    genCircle(int $radiusint $vertLinesint $dotsPerLine$center)
        {
            
    $pitchDelta = (float)180 $dotsPerLine;
            
    $yawDelta = (float)360 $vertLines;

            
    $results = [];
            for (
    $i 0$i $vertLines; ++$i) {
                for (
    $j 0$j $dotsPerLine; ++$j) {
                    
    $loc = clone($center);
                    
    $loc->yaw = -180 + ($i $yawDelta);
                    
    $loc->pitch = -90 + ($j $pitchDelta);
                    
    $v self::getDirection($loc)->normalize()->multiply($radius);
                    
    $results[] = $v;
                }
            }
            return 
    $results;
        }

        public static function 
    makeSphere($player$radius 5) {
            
    $data self::genCircle($radius2020$player->getLocation());
            foreach (
    $data as $pos$player->getLevel()->addParticle(new MobSpellParticle($player->add($pos->x$pos->y$pos->z), 255255255));
        }
    PHP:
    self::makeSphere($player);
     
    HimbeersaftLP and Awzaw like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.