javafx - Finite State Machine For Java-Based Crowd Simulation -


i building crowd simulation using java. have split application based on mvc framework. have used flocking algorithm model people's movements. need groups of people move along set pathway. attempting using fsm need guidance.

each group of passengers formed arraylist small triangular symbol representing each passenger.

import java.util.arraylist; import java.util.list; import java.util.random;  import utility.vector2d; import javafx.animation.pathtransition; import javafx.animation.timeline; import javafx.scene.image.image; import javafx.scene.image.imageview; import javafx.scene.shape.circle; import javafx.scene.shape.cubiccurveto; import javafx.scene.shape.moveto; import javafx.scene.shape.path; import javafx.scene.shape.rectangle; import javafx.util.duration;   public class flock2 { public arraylist<businesspersonboid> boids2; private double movementfactor = 1000;        private double boundingfactor = 10;          private int seperationdistance = 43;         private double seperationfactor = 50;      circle c = new circle(); circle c2 = new circle();   public flock2() {     boids2 = new arraylist<businesspersonboid>();       random randnum = new random();     randomname randname = new randomname();      for(int = 0; < 10; i++) {         int  x = randnum.nextint(1000) + 1;         int  y = randnum.nextint(400) + 1;          boids2.add(new businesspersonboid(x,y, randname.getname(), c ));     }   }    public void updateboidspostion() {     vector2d v1, v2, v3, v4, v5 = new vector2d();     (businesspersonboid cboid : boids2) {          path path = new path();         path.getelements().add(new moveto(-50,140));         path.getelements().add(new moveto(150,140));         path.getelements().add(new moveto(750,140));         path.getelements().add(new moveto(910,-40));          pathtransition pathtransition = new pathtransition();          pathtransition.setpath(path);         pathtransition.setnode(cboid);        v1 = groupflock(cboid);     v2 = collisionavoidance(cboid);     v3 = matchflockvelocity(cboid);     v4 = bounding(cboid);     v5 = positiontend(cboid);         vector2d sum = new vector2d();     sum = sum.add(v1);     sum = sum.add(v2);     sum = sum.add(v3);     sum = sum.add(v4);     sum = sum.add(v5);         cboid.setvelocity(cboid.getvelocity().add(sum));     vector2d next = new vector2d( cboid.getposition().add(cboid.getvelocity()) );     cboid.setposition(next);     vector2d next2 = new vector2d( cboid.getposition().add(cboid.getvelocity()) );          pathtransition.play();       } }   private vector2d groupflock(businesspersonboid cboid) {     vector2d center = new vector2d();      (businesspersonboid aboid : boids2) {         if(!aboid.equals(cboid)) {             center = center.add(aboid.getposition());         }     }     center = center.division(boids2.size() - 1 );     center = center.subtract(cboid.getposition());     center = center.division(movementfactor);      return center;    }   private vector2d collisionavoidance(businesspersonboid cboid) {     vector2d correction = new vector2d();     vector2d cposition = new vector2d(cboid.getposition());      (businesspersonboid aboid : boids2) {         if (!aboid.equals(cboid)) {             vector2d aposition = aboid.getposition();             vector2d xd = new vector2d(aposition.xpos - cposition.xpos, aposition.ypos - cposition.ypos);              if(math.abs(xd.xpos) < seperationdistance && math.abs(xd.ypos) < seperationdistance) {                   correction = correction.subtract(xd).division(seperationfactor);             }          } } return correction; }   private vector2d matchflockvelocity(businesspersonboid cboid) {     vector2d perceivedvelocity = new vector2d();      for(businesspersonboid aboid : boids2) {         if(!aboid.equals(cboid)) {             perceivedvelocity = perceivedvelocity.add(aboid.getvelocity());         }     }     perceivedvelocity = perceivedvelocity.division(boids2.size() - 1);     perceivedvelocity = perceivedvelocity.subtract(cboid.getvelocity());     perceivedvelocity = perceivedvelocity.division(8);     return perceivedvelocity; }   private vector2d bounding(businesspersonboid cboid) {     vector2d bound = new vector2d();      int xmin = 0, xmax = 1400, ymin = 0, ymax = 320;      vector2d cpos = cboid.getposition();      if (cpos.xpos < xmin) {          bound.xpos += 1;          cpos.xpos = bound.xpos;     } else if (cpos.xpos > xmax){         bound.xpos += -100;         cpos.xpos = bound.xpos;     }     if (cpos.ypos < ymin) {          bound.ypos += 1;          cpos.ypos = bound.ypos;     } else if (cpos.ypos > ymax){         bound.ypos += -100;         cpos.ypos = bound.ypos;     }      bound = bound.division(boundingfactor);      return bound; }   private vector2d positiontend(businesspersonboid cboid) {     vector2d place = new vector2d(900,600);      vector2d tend = new vector2d();      tend = new vector2d(place.subtract(cboid.getposition()));     tend.division(6000);             return tend; }   public list<imageview> getboidsrepresentation() {     list<imageview> circles = new arraylist<imageview>();     for(businesspersonboid aboid : boids2) {         circles.add( aboid.getdisplay() );     }     return circles; }   private vector2d bounding2(businesspersonboid cboid) {     vector2d bound = new vector2d();      int xmin = 0, xmax = 600, ymin = 0, ymax = 600;      vector2d cpos = cboid.getposition();            bound.xpos = 100;          cpos.xpos = bound.xpos;           bound.ypos = 100;          cpos.ypos = bound.ypos;       bound = bound.division(boundingfactor);      return bound; } 

this attempt @ changing pathway:

private vector2d pathway(businesspersonboid cboid) {     vector2d pathway = new vector2d();      path path = new path();     path.getelements().add(new moveto(20,20));     path.getelements().add(new cubiccurveto(380, 0, 380, 120, 200, 120));     path.getelements().add(new cubiccurveto(0, 120, 0, 240, 380, 240));     pathtransition pathtransition = new pathtransition();     pathtransition.setduration(duration.millis(4000));     pathtransition.setpath(path);     pathtransition.setnode(cboid);     return pathway; } 

currently, having no effect on overall pathway boids take. need move 1 area of screen group, retain random movements within group.

my question best method move boids 1 area of screen while retaining random movements within group of boids?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -