java - Objects Used In PathTransition In JavaFx Moving Too Fast -


i have group of triangles move around based on flocking algorithm. have used path transition javafx move along set pathway while retaining flocking behavior within pathway. however, when try slow down path transition setting duration in milliseconds, triangles either move or remain stuck in 1 place. have tried looking other solutions haven't been able find , posing here.

package model;  import utility.vector2d;  import java.util.random;  import javafx.animation.pathtransition; import javafx.scene.image.image; import javafx.scene.image.imageview; import javafx.scene.paint.color; import javafx.scene.shape.circle; import javafx.scene.shape.cubiccurveto; import javafx.scene.shape.lineto; import javafx.scene.shape.moveto; import javafx.scene.shape.path; import javafx.util.duration;   public class businesspersonboid extends circle{  public vector2d position; protected vector2d position2; protected vector2d position3; protected vector2d position4; protected vector2d position5; protected vector2d velocity; protected final int speedlimit = 2; protected string name; protected imageview display; protected circle circle; public lineto line1; public lineto line2; public lineto line3; public lineto line4;   public businesspersonboid(int x, int y, string n, circle c) {      this.display = new imageview();      this.display.setx(x);     this.display.sety(y);     this.display.setsmooth(true);     this.display.setcache(true);     this.display.setimage(new image("images2/boid-green.png"));      this.circle = new circle(15,color.blue);      this.position = new vector2d(x, y);      this.velocity = new vector2d(0,0);      if( n != null) {         this.name = n;     } }   public vector2d getposition() {     return new vector2d(position.xpos, position.ypos); }     public vector2d getvelocity() {     return velocity; }   public void setvelocity(vector2d velocity) {              if ( velocity.xpos > speedlimit) {         velocity.xpos = speedlimit;     }     if ( velocity.ypos > speedlimit) {         velocity.ypos = speedlimit;     }        this.velocity = velocity; }  public void setposition(vector2d pos) {     setangle(this.position, pos);     this.display.setx(pos.xpos);     this.display.sety(pos.ypos);     this.position = pos;   }  public void setposition2(vector2d pos, vector2d pos2) {     setangle(this.position, pos);     this.display.setx(pos.xpos);     this.display.sety(pos.ypos);     this.display.setx(pos.xpos);     this.display.sety(pos.ypos);     this.position = pos;   }  public void setpathway() {      random randnum = new random();          path path = new path();       moveto moveto = new moveto(108, 71);       lineto line1 = new lineto(150, 140);     lineto line2 = new lineto(550, 140);     lineto line3 = new lineto(750, 140);     lineto line4 = new lineto(910, -40);        path.getelements().add(moveto);     path.getelements().addall(line1, line2, line3, line4);           pathtransition pathtransition = new pathtransition();           pathtransition.setduration(duration.millis(100));          pathtransition.setnode(display);         pathtransition.setpath(path);           pathtransition.play();      }         public void setangle(vector2d current, vector2d next) {      double delta_x = next.xpos - current.xpos;     double delta_y = next.ypos - current.ypos;     double theta = math.atan2(delta_y, delta_x);           double angle = theta*180/math.pi;     this.display.setrotate(angle);  }  public string getname() {     return this.name; }   public imageview getdisplay() {     return this.display; }  } 

here flocking class:

package model;     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; public businesspersonboid cboid;  public vector2d checkin; public vector2d currencyexchange; public vector2d lounge; public vector2d shop; public vector2d boardinggate;    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(50) + 1;         int  y = randnum.nextint(140) + 1;          boids2.add(new businesspersonboid(x,y, randname.getname(), c ));       }   }    public void updateboidspostion() {     vector2d v1, v2, v3, v4, v5 = new vector2d();     (businesspersonboid cboid : boids2) {           v1 = groupflock(cboid);     v2 = collisionavoidance(cboid);     v3 = matchflockvelocity(cboid);     v4 = bounding(cboid);     v5 = positiontend(cboid);      vector2d v12 = new vector2d(-50,140);       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.setpathway();      cboid.setvelocity(cboid.getvelocity().add(sum));     vector2d next = new vector2d( cboid.getposition().add(cboid.getvelocity()) );     cboid.setposition(next);       }         }       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; }  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; }  public int tendtoplace(businesspersonboid cboid) {      vector2d place = new vector2d(-50,140);      return place.minus(cboid.position)/100;  } 

my question how slow triangles down speed can see them moving properly?

randomname class:  package model;  import java.util.arraylist; import java.util.random;   public class randomname { private random randomgenerator; private arraylist<integer> usedlist; private string[] namebank =  { "alpha",         "bravo",         "charlie",         "delta",         "echo",         "foxtrot",         "golf",         "hotel",         "india",         "juliet",         "kilo",         "lima",         "mike",         "november",         "oscar",         "papa",         "quebec",         "romeo",         "sierra",         "tango",         "uniform",         "victor",         "whiskey",         "x-ray",         "yankee",         "zulu" };  public randomname() {     randomgenerator = new random();     usedlist = new arraylist<integer>(); }   public string getname() {     return namebank[getindex()]; }   private int getindex() {     int = randomgenerator.nextint(namebank.length);      while(usedlist.contains(i)) {         if(usedlist.size() >= namebank.length ) {             usedlist.clear();         }          = randomgenerator.nextint(namebank.length);     }      usedlist.add(i);      return i; }   public void addname(string add) {     namebank[namebank.length+1+1] = add;     }   public void addname(string[] add) {     for(int = 0; < add.length; i++) {         namebank[namebank.length+1] = add[i];                }   } } 

vector2d class:

package utility;   public class vector2d { public double xpos;  public double ypos;   public vector2d(){     this.xpos = 0;     this.ypos = 0; }  public vector2d(vector2d v){     this.xpos = v.xpos;     this.ypos = v.ypos; }  public vector2d(double x, double y){     this.xpos = x;     this.ypos = y; }  public vector2d add(vector2d addvector){     return new vector2d(this.xpos += addvector.xpos, this.ypos += addvector.ypos ); }   public vector2d add(double x, double y){     return new vector2d(this.xpos += x, this.ypos += y ); }   public vector2d subtract(double x, double y){     return new vector2d(this.xpos += x, this.ypos += y ); }   public vector2d subtract(vector2d subvector){     return new vector2d(this.xpos = (this.xpos - subvector.xpos), this.ypos = (this.ypos - subvector.ypos)); }  public vector2d division(double divider) {     return new vector2d(this.xpos =( xpos / divider), this.ypos =( ypos / divider)); }  public double absx() {     return math.sqrt(math.pow(this.xpos, 2)); }  public double absy() {     return math.sqrt(math.pow(this.ypos, 2)); }  public double abs() {     return math.sqrt(math.pow(this.xpos, 2) + math.pow(this.ypos, 2)); }  public int minus(vector2d position) {     // todo auto-generated method stub     return 0; } } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -