コード例 #1
0
ファイル: Car.java プロジェクト: JonasHess/VS_Praktikum
 /**
  * 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;
   }
 }
コード例 #2
0
ファイル: Car.java プロジェクト: JonasHess/VS_Praktikum
 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);
 }
コード例 #3
0
ファイル: Car.java プロジェクト: JonasHess/VS_Praktikum
 /**
  * Calculates the direction of the next turn.
  *
  * @return
  */
 protected Edge findNextDestination(Node currentNode, Node destinationNode) {
   return currentEdge.getDestinationNode().getRandomEdge();
 }