Package org.lwjgl.util.vector

Examples of org.lwjgl.util.vector.Vector2f


   *            a face to add
   */
  private void addFace(BlockFace face) {
    BlockFace[] extension = { null, null };

    Vector2f firstCorner = face.getFirstCorner();
    Vector2f secondCorner = face.getSecondCorner();

    switch (face.getFacePlace()) {
    case LEFT:
    case RIGHT:
      for (BlockFace face2 : blockFaces.get(face.getFacePlace().ordinal())) {
View Full Code Here


   * @return first time in the future the balls will collide or
   *         Float.POSITIVE_INFINITY if they won't
   */
  private float getCollisionTimeBall(Vector2f p1, Vector2f v1, float r1, Vector2f p2, Vector2f v2, float r2) {
    // change to system where p1 = 0 and v1 = 0
    Vector2f p = new Vector2f();
    Vector2f v = new Vector2f();
    Vector2f.sub(p2, p1, p);
    Vector2f.sub(v2, v1, v);

    // first check if potential collision is in the future
    if (Vector2f.angle(p, v) < Math.PI / 2.0f)
View Full Code Here

  public BlockGO(Block block, GraphicsObjectsManager goManager) {
    super(Material.getPresetMaterial(Material.PresetMaterial.GOLD), goManager);
    this.block = block;

    Vector2f topLeft = block.getCornerPos(Block.CornerPlace.TOP_LEFT);
    Vector2f bottomRight = block.getCornerPos(Block.CornerPlace.BOTTOM_RIGHT);

    float left = topLeft.x;
    float right = bottomRight.x;
    float top = topLeft.y;
    float bottom = bottomRight.y;
View Full Code Here

    Lighting.disable();
  }

  @Override
  public Vector3f getPosition() {
    Vector2f pos = block.getPosition();
    return new Vector3f(pos.x, pos.y, 0.0f);
  }
View Full Code Here

  /**
   * @return first time in the future the ball will collide with the cylinder
   *         of the paddle or Float.POSITIVE_INFINITY if it won't
   */
  private float getCollisionTimePaddleCylinder(Ball b, Paddle p) {
    Vector2f ballPos = b.getPosition();
    Vector2f ballVel = b.getVelocity();
    Vector2f paddlePos = p.getPosition();
    float pHalfLength = p.getLength() / 2.0f;
    float time = Float.POSITIVE_INFINITY;

    switch (p.getPlace()) {
    case LEFT:
View Full Code Here

   */
  private BlockFaceCollision getCollisionBlockFace(Ball ball) {
    float firstTime = Float.POSITIVE_INFINITY;
    BlockFace firstFace = null;

    Vector2f ballPos = ball.getPosition();
    Vector2f ballVel = ball.getVelocity();

    // left faces
    if (ballVel.x > EPS) {
      for (BlockFace face : leftBlockFaces) {
        Vector2f tlCornerPos = face.getFirstCorner();
        Vector2f blCornerPos = face.getSecondCorner();
        if (ballPos.x < tlCornerPos.x) {
          float time = (tlCornerPos.x - ballPos.x - ball.getRadius()) / ballVel.x;
          if (time < firstTime) {
            float newY = ballPos.y + time * ballVel.y;
            if (newY >= blCornerPos.y && newY <= tlCornerPos.y) {
              firstTime = time;
              firstFace = face;
            }
          }
        }
      }
    }

    // right faces
    if (ballVel.x < -EPS) {
      for (BlockFace face : rightBlockFaces) {
        Vector2f trCornerPos = face.getFirstCorner();
        Vector2f brCornerPos = face.getSecondCorner();
        if (ballPos.x > trCornerPos.x) {
          float time = (trCornerPos.x - ballPos.x + ball.getRadius()) / ballVel.x;
          if (time < firstTime) {
            float newY = ballPos.y + time * ballVel.y;
            if (newY >= brCornerPos.y && newY <= trCornerPos.y) {
              firstTime = time;
              firstFace = face;
            }
          }
        }
      }
    }

    // top faces
    if (ballVel.y < -EPS) {
      for (BlockFace face : topBlockFaces) {
        Vector2f tlCornerPos = face.getFirstCorner();
        Vector2f trCornerPos = face.getSecondCorner();
        if (ballPos.y > tlCornerPos.y) {
          float time = (tlCornerPos.y - ballPos.y + ball.getRadius()) / ballVel.y;
          if (time < firstTime) {
            float newX = ballPos.x + time * ballVel.x;
            if (newX >= tlCornerPos.x && newX <= trCornerPos.x) {
              firstTime = time;
              firstFace = face;
            }
          }
        }
      }
    }

    // bottom faces
    if (ballVel.y > EPS) {
      for (BlockFace face : bottomBlockFaces) {
        Vector2f blCornerPos = face.getFirstCorner();
        Vector2f brCornerPos = face.getSecondCorner();
        if (ballPos.y < blCornerPos.y) {
          float time = (blCornerPos.y - ballPos.y - ball.getRadius()) / ballVel.y;
          if (time < firstTime) {
            float newX = ballPos.x + time * ballVel.x;
            if (newX >= blCornerPos.x && newX <= brCornerPos.x) {
              firstTime = time;
              firstFace = face;
            }
          }
        }
      }
    }

    if (firstTime < Float.POSITIVE_INFINITY) {
      Vector2f pos = new Vector2f(ballPos.x + firstTime * ballVel.x, ballPos.y + firstTime * ballVel.y);
      Block block = firstFace.getBlockAt(pos);
      return new BlockFaceCollision(firstTime, ball, block, firstFace.getFacePlace());
    } else
      return null;
  }
View Full Code Here

   */
  private BlockCornerCollision getCollisionBlockCorner(Ball ball) {
    float firstTime = Float.POSITIVE_INFINITY;
    BlockFace firstFace = null;

    Vector2f ballPos = ball.getPosition();
    Vector2f ballVel = ball.getVelocity();
    float ballRadius = ball.getRadius();
    Vector2f blockVel = new Vector2f(0.0f, 0.0f);

    // test top corner of left face, bottom corner of right face, right
    // corner of top face and left corner of bottom face
    for (BlockFace face : leftBlockFaces) {
      float time = getCollisionTimeBall(ballPos, ballVel, ballRadius, face.getFirstCorner(), blockVel, 0.0f);
      if (time < firstTime) {
        firstTime = time;
        firstFace = face;
      }
    }
    for (BlockFace face : rightBlockFaces) {
      float time = getCollisionTimeBall(ballPos, ballVel, ballRadius, face.getSecondCorner(), blockVel, 0.0f);
      if (time < firstTime) {
        firstTime = time;
        firstFace = face;
      }
    }
    for (BlockFace face : topBlockFaces) {
      float time = getCollisionTimeBall(ballPos, ballVel, ballRadius, face.getSecondCorner(), blockVel, 0.0f);
      if (time < firstTime) {
        firstTime = time;
        firstFace = face;
      }
    }
    for (BlockFace face : bottomBlockFaces) {
      float time = getCollisionTimeBall(ballPos, ballVel, ballRadius, face.getFirstCorner(), blockVel, 0.0f);
      if (time < firstTime) {
        firstTime = time;
        firstFace = face;
      }
    }

    BlockCornerCollision firstCollision = null;
    if (firstTime < Float.POSITIVE_INFINITY) {
      Vector2f pos = new Vector2f(ballPos.x + firstTime * ballVel.x, ballPos.y + firstTime * ballVel.y);
      Block block = firstFace.getBlockAt(pos);
      switch (firstFace.getFacePlace()) {
      case LEFT:
        firstCollision = new BlockCornerCollision(firstTime, ball, block, firstFace.getFirstCorner());
        break;
View Full Code Here

  }

  @Override
  public void apply() {
    // just reflect velocity of ball
    Vector2f v1 = ball.getVelocity();
    switch (face) {
    case LEFT:
    case RIGHT:
      ball.setVelocity(new Vector2f(-v1.x, v1.y));
      break;

    case TOP:
    case BOTTOM:
      ball.setVelocity(new Vector2f(v1.x, -v1.y));
      break;
    }

    block.notifyHit(ball);
  }
View Full Code Here

   
    map = new Map();
    terrain = new Terrain(Map.mapWidth*10, Map.mapHeight*10);
    terrain.setPosition(0, -0.137f,0);
   
    gameCameraMultipliers = new Vector2f((float) (-Math.PI/4.0), 3f);

    passengerTimer = elapsedAppTime();
   
    this.generateMap();
    this.map.initializeStations();
View Full Code Here

   *
   * @param size
   * @return
   */
  public Vector2f findFreeSpace(int size) {
    Vector2f location = new Vector2f(0, 0);
   
    for(int rows = 5; rows < mapHeight-5; rows++) {
      for(int cols = 5; cols < mapWidth-5; cols++) {
        // current location is valid for use
        boolean valid = true;
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.