Package org.lwjgl.util.vector

Examples of org.lwjgl.util.vector.Vector2f


    this.capacity = 15*1000;
    this.addCoals(3*1000);
   
    this.setMap(map);
   
    this.setLocation(new Vector2f(10, 10));
  }
View Full Code Here


 
  public Station(){
    name = "null";
    tiles = new ArrayList<>();
    departingPassengers = new ArrayList();
    centerPosition = new Vector2f();
   
    this.generateName();
  }
View Full Code Here

  public ArrayList<Passenger> getPassengers() {
    return this.departingPassengers;
  }
 
  public Vector2f getCenterPosition(){
    return new Vector2f(this.centerPosition);

  }
View Full Code Here

    else if(type == Coach.COAL)
      that.coach = new CoalCoach(this.map);
     
    // set new position to new coach behind the previous.
    // TODO: make it direction-independent
    Vector2f newLoc = new Vector2f(that.getLocation());
    newLoc.x--;
   
    that.coach.setLocation(newLoc);
  }
View Full Code Here

  private int direction;
 
  protected Model model;

  public GameObject() {
    location = new Vector2f(0,0);
    direction = 0;
  }
View Full Code Here

    nextTurns = new ArrayDeque<>();
  }
 
  protected void updateModel() {
    // update model location and rotation
    Vector2f newLocation = new Vector2f(this.getLocation());
    if(oldAngle == 6 && newAngle == 0)
      newAngle = 8;
    else if(oldAngle == 0 && newAngle == 6){
      oldAngle = 8;
   
View Full Code Here

   
    /* Get how much to move without turning */
    double yVel = Math.sin(Math.toRadians(getDirection()*45))*movement;
    double xVel = Math.cos(Math.toRadians(getDirection()*45))*movement;
   
    Vector2f newLocation = new Vector2f(this.getLocation());
    newLocation.x += xVel;
    newLocation.y += yVel;
    Point newTile = new Point(Math.round(newLocation.x), Math.round(newLocation.y));
   
    /* Get how much we have moved in this tile (0.0 - 1.0) */
    float tileProgress = 0f;
    if(getDirection() == 0){
      tileProgress = newLocation.x - (float)oldTile.x + 0.5f;
    }
    else if(getDirection() == 2){
      tileProgress = newLocation.y - (float)oldTile.y + 0.5f;
    }
    else if(getDirection() == 4){
      tileProgress = (float)oldTile.x - newLocation.x + 0.5f;
    }
    else if(getDirection() == 6){
      tileProgress = (float)oldTile.y - newLocation.y + 0.5f;
    }
    this.tileProgress = tileProgress;
   
    if(prev == null){
      /* Currently the train is active */
     
      if(!oldTile.equals(newTile)){
        /* We have moved in to a new tile, so calculate next turn */
        this.mayTurn = true;
        int nextDirection = this.getDirection();

        boolean freeDirs[] = map.scanRideable(newTile.x, newTile.y);

        int right = (getDirection()+2)%8;
        int left = (getDirection()-2)%8;
        if(left < 0)
          left += 8;

        if((!freeDirs[getDirection()] && freeDirs[right] && !freeDirs[left])
          || (!freeDirs[getDirection()] && freeDirs[right] && freeDirs[left] && this.getInterSectionDirection() == 0)){
          /* Can only turn right */
          nextDirection = this.getTurnDirection(2);
          System.out.println("Forced right turn");
        }
        else if(!freeDirs[getDirection()] && !freeDirs[right] && freeDirs[left]){
          /* Can only turn left */
          nextDirection = this.getTurnDirection(-2);
          System.out.println("Forced left turn");
        }
        else if((!freeDirs[getDirection()] && !freeDirs[right] && !freeDirs[left])){
          /* Can only reverse */
          nextDirection = this.getTurnDirection(-4);
          System.out.println("Reversing");
        }
        else{
          if(this.getInterSectionDirection() == LEFT && freeDirs[left]){
            /* Can't go forward but can go right & left, left chosen */
            nextDirection = this.getTurnDirection(-2);
            this.intersectionControl = 0;
            System.out.println("Left turn");
          }
          else if(this.getInterSectionDirection() == RIGHT && freeDirs[right]){
            /* Can't go forward but can go right & left, right chosen */
            nextDirection = this.getTurnDirection(2);
            this.intersectionControl = 0;
            System.out.println("Right turn");
          }
        }
       
        /* Update model angles to have a smooth turn */
        oldAngle = this.getDirection();
        newAngle = nextDirection;
       
        /* We are starting a turn, so set lastTurn to this tile */
        if(this.getDirection() != nextDirection)
          this.nextTurnPoint = new TurnPoint(newTile, nextDirection);

        /* Adjust tileProgress, since we moved in to a new tile */
        this.tileProgress = tileProgress-1f;
      }
    }
    else{
      /* Currently a coach is active */
     
      if(prev.getNextTurnPoint() != null && (this.nextTurns.isEmpty() || !this.nextTurns.peekLast().getTile().equals(prev.getNextTurnPoint().getTile()))){   
        /* Query previous TrackRider's latest turn and compare it to the last one in this queue.
         * Add it to the end of queue, if it isn't already there.
         */
        this.nextTurns.add(prev.getNextTurnPoint());
      }

      if(!oldTile.equals(newTile)){
        if(!this.nextTurns.isEmpty()){
          /* There are turns queued */
          if(newTile.equals(this.nextTurns.peekFirst().getTile())){
            /* Current tile matches the tile at the front of turn queue, so execute a turn. */
            this.mayTurn = true;
            TurnPoint nextTurn = this.nextTurns.pollFirst();
            this.nextTurnPoint = new TurnPoint(nextTurn.getTile(), nextTurn.getDirection());
          }
        }
       
        /* Update model angles to have a smooth turn */
        oldAngle = this.getDirection();
        newAngle = (this.nextTurnPoint != null)?this.nextTurnPoint.getDirection():this.getDirection();
       
        /* Adjust tileProgress, since we moved in to a new tile */
        this.tileProgress = tileProgress-1f;
      }
    }
   
    if(this.mayTurn && this.tileProgress > 0.5f){
      /* Turn flag has been set and the TrackRider is over half way the current tile,
       * so try to turn to the next direction.
       */
     
      if(this.nextTurnPoint != null && this.getDirection() != this.nextTurnPoint.getDirection()){
        /* Current direction is different from next turn direction, so turn */
        this.setDirection(this.nextTurnPoint.getDirection());
       
        /* Set position to the center of current tile and add how much is
         * still needed to adjust position with the new direction in mind.
         */
        double overhead = tileProgress-0.5f;
        //System.out.println("Turn "+((prev==null)?"Train":"Coach")+" "+overhead);
        yVel = Math.sin(Math.toRadians(getDirection()*45))*overhead;
        xVel = Math.cos(Math.toRadians(getDirection()*45))*overhead;
        newLocation.set((float)(newTile.x+xVel), (float)(newTile.y+yVel));
       
        /* TrackRider has turned. Unset the turn point.  */
        this.nextTurnPoint = null;
      }
     
View Full Code Here

  private int getCorrectIndex(int index, int indexSize){
    return (index > 0)?--index:indexSize+index;
  }
 
  private Vector2f parseToVec2f(String str[]){
    Vector2f vec = new Vector2f();
    vec.set(Float.parseFloat(str[1]), 1.0f-Float.parseFloat(str[2]));
    return vec;
  }
View Full Code Here

    // 61 tons
    this.setWeight(61*1000);
   
    this.setMap(map);
   
    this.setLocation(new Vector2f(10, 10));
               
    // be default, train is loaded
    this.loaded = true;
  }
View Full Code Here

        aboutButton = Textures.loadTexture("res/menu/about.png");
        exitButton = Textures.loadTexture("res/menu/exit.png");
    }

    public void render() {
        Textures.drawTexture(playButton, new Vector2f(Display.getWidth() / 2 - playButton.getImageWidth() / 2, 300));
        Textures.drawTexture(aboutButton, new Vector2f(Display.getWidth() / 2 - playButton.getImageWidth() / 2, 150));
        Textures.drawTexture(exitButton, new Vector2f(Display.getWidth() / 2 - playButton.getImageWidth() / 2, 0));
    }
View Full Code Here

TOP

Related Classes of org.lwjgl.util.vector.Vector2f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.