//-------------------------------FLOCKING PROPERTIES------------------------------------------------------------------------- public override void calculateVelocity(BoidCollection boids, List <Obstaculo> c, List <Obstaculo> r, List <Obstaculo> l) { // if (Constantes.frenado) // calculateVelocityFrenado (boids, c, r, l); // else calculateVelocityNormal(boids, c, r, l); }
private Vector cohesion(BoidCollection boids) //promedio de las posiciones de los vecinos dentro del radio { Vector sum = new Vector(0, 0); int neighbors = 0; int n = 0; if (Logica.puntos_objetivo.Count > 0 && objetivo < Logica.puntos_objetivo.Count) { Vector nuevo = new Vector(intermedio.X, Logica.mapeo(intermedio.Y)); sum.add(nuevo); neighbors++; } else { foreach (Boid b in boids) { double d = Location.distance(b.Location); if ((Logica.mouse && n == 0) || (n != 0 && d > 0 && d < Logica.radioCoh)) { sum.add(b.Location); neighbors++; } n++; } } if (neighbors > 0) { sum.div(neighbors); return(seek(sum)); } return(sum); }
public override void calculateVelocity(BoidCollection s, DrawingArea area) { area.GetPointer(out x, out y); y = (int)Logica.mapeo(y); Velocity.X = x - Location.X; Velocity.Y = y - Location.Y; LocationNueva.X = x; LocationNueva.Y = y; }
public void AddBoids(BoidCollection c) { foreach (Boid b in c) { if (!List.Contains(b)) { List.Add(b); } } }
private Vector align(BoidCollection boids) //promedio de las velocidades de los vecinos { Vector sum = new Vector(0, 0); int neighbors = 0; int n = 0; if (Logica.puntos_objetivo.Count > 0 && objetivo < Logica.puntos_objetivo.Count) { Vector v; if (intermedio.X > Location.X) { v = new Vector(intermedio.X - Location.X, Logica.mapeo(intermedio.Y) - Location.Y); } else { v = new Vector(Location.X - intermedio.X, Location.Y - Logica.mapeo(intermedio.Y)); } v.normalize(); v.mult(0.5); sum.add(v); neighbors++; } else { foreach (Boid b in boids) { double d = Location.distance(b.Location); if ((Logica.mouse && n == 0) || (n != 0 && d > 0 && d < Logica.radioAli)) { sum.add(b.Velocity); neighbors++; } n++; } } if (neighbors > 0) { sum.div(neighbors); sum.normalize(); sum.mult(Logica.max_speed); Vector steer = sum.sub(sum, this.Velocity); steer.limit(Logica.max_force); return(steer); } else { return(new Vector(0, 0)); } }
public void reclasificar(BoidCollection coleccion) { limpiar_boids(); int n = 0; foreach (Boid b in coleccion) { if (n != 0) { ubicar_boid_casillero(b); } n++; } }
// private void calculateVelocityFrenado(BoidCollection boids, List<Obstaculo> c, List<Obstaculo> r, List<Obstaculo> l) // { // if (nro_iteracion == 50) { // // if (this.locacion_temp.distance (Location) > Constantes.zona_confort) { // mover = true; // locacion_temp.X = Location.X; // locacion_temp.Y = Location.Y; // } else { // mover = false; // // } // } // if (nro_iteracion == 100) { // nro_iteracion = 0; // mover = true; // } // // if (mover) { // update_objetivo (); // flock (boids); // update (boids, c, r, l, 1); // // } else { // if (nro_iteracion % 2 == 0) { // update_objetivo (); // flock (boids); // update (boids, c, r, l, 0.85); // } // } // nro_iteracion++; // } private void flock(BoidCollection boids) //Resultante de las 3 propiedades = Acceleration { Vector sep = separate(boids); Vector ali = align(boids); Vector coh = cohesion(boids); sep.mult(Logica.coefSep); ali.mult(Logica.coefAli); coh.mult(Logica.coefCoh); Acceleration.add(sep); Acceleration.add(ali); Acceleration.add(coh); if (Logica.play && Constantes.tiempo % 10 == 0) { trayectoria.Add(new Point((int)Location.X, (int)Location.Y)); } }
private Vector separate(BoidCollection boids) // promedio de las distancias del boid con sus vecinos { Vector sum = new Vector(0, 0); int neighbors = 0; vecinos = 0; int n = 0; foreach (Boid b in boids) { if (n != 0) { double d = Location.distance(b.Location); if (d > 0 && d < Logica.radioSep) { Vector diff = Location.sub(Location, b.Location); diff.normalize(); diff.div(d); sum.add(diff); neighbors++; vecinos++; } } n++; } if (neighbors > 0) { sum.div(neighbors); } if (sum.magnitude() > 0) { sum.normalize(); sum.mult(Logica.max_speed); sum.sub(sum, this.Velocity); sum.limit(Logica.max_force); } return(sum); }
private void calculateVelocityNormal(BoidCollection boids, List <Obstaculo> c, List <Obstaculo> r, List <Obstaculo> l) { update_objetivo(); flock(boids); update(boids, c, r, l, 1); }
private void update(BoidCollection boids, List <Obstaculo> C, List <Obstaculo> R, List <Obstaculo> L, double magnitud) //Revisa los limites y calcula los rebotes { Velocity.add(Acceleration); //Update velocity Velocity.limit(Logica.max_speed); double newx = this.Location.X + this.Velocity.X; double newy = this.Location.Y + this.Velocity.Y; double velOrigX = this.Velocity.X; double velOrigY = this.Velocity.Y; Constantes.reboto = false; for (int i = 0; i < C.Count() && !Constantes.reboto; i++) { if (C.ElementAt(i).enable) { Logica.avoid_circulo(newx, newy, this.Velocity, C.ElementAt(i).rectangle, this.Location); } } for (int i = 0; i < R.Count() && !Constantes.reboto; i++) { if (R.ElementAt(i).enable) { Logica.avoid_rectangulo(newx, newy, this.Velocity, R.ElementAt(i).rectangle, this.Location); } } for (int i = 0; i < L.Count() && !Constantes.reboto; i++) { if (L.ElementAt(i).enable) { Logica.avoid_linea(newx, newy, this.Velocity, L.ElementAt(i).rectangle, this.Location); } } //rebota o atraviesa los bordes de la pantalla if (Logica.rebotar) { if (newx > Constantes.limites.Right - 10 || newx < Constantes.limites.Left + 10) { this.Velocity.X = -1 * this.Velocity.X; } if (newy > Constantes.limites.Bottom - 40 || newy < Constantes.limites.Top + 20) { this.Velocity.Y = -1 * (this.Velocity.Y); } } else if (Logica.atravesar) { if (newx < 0) { LocationNueva.X = Constantes.limites.Width; } if (newy < 0) { LocationNueva.Y = Constantes.limites.Height; } if (newx > Constantes.limites.Width) { LocationNueva.X = 0; } if (newy > Constantes.limites.Height) { LocationNueva.Y = 0; } } Velocity.X *= magnitud; Velocity.Y *= magnitud; LocationNueva.add(Velocity); //Reset acceleration Acceleration.X = 0; Acceleration.Y = 0; }
public virtual void calculateVelocity(BoidCollection boids, List <Obstaculo> c, List <Obstaculo> r, List <Obstaculo> l) { }
public virtual void calculateVelocity(BoidCollection sc, DrawingArea area) { }