Ejemplo n.º 1
0
 /**
  * Has the car arrived at the end of its current edge?
  *
  * @param currentPosition
  * @return
  */
 public boolean arrivedAtEndOfEdge(Vector2f currentPosition) {
   float distance = currentPosition.distance(currentEdge.getDestinationNode().getPosition());
   if (distance < 0) {
     distance = distance * -1f;
   }
   if ((distance * 0.99999) >= lastDistance) { // Vermeidet Rundungsfehler
     return true;
   } else {
     this.lastDistance = distance;
     return false;
   }
 }
Ejemplo n.º 2
0
 private Vector2f getCurrentPosition() throws EndOfRoadException {
   if (this.arrivedAtEndOfEdge(lastKnownPosition)) {
     if (this.currentEdge.getDestinationNode().equals(this.destination)) {
       throw new EndOfRoadException();
     }
     Edge nextDestination =
         this.findNextDestination(currentEdge.getDestinationNode(), destination);
     if (nextDestination == null) {
       throw new EndOfRoadException();
     }
     this.setNextDestination(nextDestination);
     onRoadChange(nextDestination);
   }
   Vector2f direction =
       this.currentEdge.getDestinationNode().getPosition().sub(this.lastKnownPosition);
   direction.normalise();
   this.direction = direction.copy();
   direction.scale(this.getCurrentSpeed());
   return lastKnownPosition.copy().add(direction);
 }
Ejemplo n.º 3
0
 /**
  * Calculates the direction of the next turn.
  *
  * @return
  */
 protected Edge findNextDestination(Node currentNode, Node destinationNode) {
   return currentEdge.getDestinationNode().getRandomEdge();
 }