Exemplo n.º 1
0
    public Vector3 bound_position(BoidParticles b)
    {
        int     Xmin = -50, Xmax = 50, Ymin = -20, Ymax = 20, Zmin = -20, Zmax = 20;
        Vector3 v = new Vector3();

        if (b.Position.x < Xmin)
        {
            v.x = 10;
        }
        else if (b.Position.x > Xmax)
        {
            v.x = -10;
        }

        if (b.Position.y < Ymin)
        {
            v.y = 10;
        }
        else if (b.Position.y > Ymax)
        {
            v.y = -10;
        }

        if (b.Position.z < Zmin)
        {
            v.z = 10;
        }
        else if (b.Position.z > Zmax)
        {
            v.z = -10;
        }

        return(v);
    }
Exemplo n.º 2
0
    public Vector3 rule3(BoidParticles bj)
    {
        //Rule 3: Boids try to match velocity with near boids.
        //This is similar to Rule 1, however instead of averaging the positions of the other boids we average the velocity.
        Vector3 pv = Vector3.zero;

        foreach (var boids in b)
        {
            if (boids != bj)
            {
                pv = pv + boids.Velocity;
            }
        }
        pv = pv / (b.Count - 1);

        return((pv - bj.Velocity) / align);
    }
Exemplo n.º 3
0
    public Vector3 rule2(BoidParticles bj)
    {
        //Rule 2: Boids try to keep a small distance away from other objects (including other boids).
        //The purpose of this rule is for boids to make sure they don't collide into each other.
        Vector3 c = Vector3.zero;

        foreach (var boids in b)
        {
            if (boids != bj)
            {
                if ((boids.Position - bj.Position).magnitude < lt)
                {
                    c = c - (boids.Position - bj.Position);
                }
            }
        }
        return(c);
    }
Exemplo n.º 4
0
    public Vector3 rule1(BoidParticles bj)
    {
        //Rule 1: Boids try to fly towards the centre of mass of neighboring boids.
        //The 'centre mass' is simplky the average position of all the boids.
        //Assume we have n boids.
        Vector3 pc = Vector3.zero;

        foreach (var boids in b)
        {
            if (boids != bj)
            {
                pc = pc + boids.Position;
            }
        }
        pc = pc / (b.Count - 1);

        return((pc - bj.Position) / mg);
    }