Package org.lwjgl.util.vector

Examples of org.lwjgl.util.vector.Vector2f


   */
  public int Height;
  public int Width;

  public RigidBody() {
    rotation = new Vector2f();
  }
View Full Code Here


    goManager = new GraphicsObjectsManager();
    inputManager = InputManager.getInstance();
    currentState = new MenuState(this, null);
    currentState.init();

    fpsText = new HUDText("", 10.0f, 0.8f, 0.8f, 1.0f, 0.9f, new Vector2f(1.0f, 1.0f), showFPS, goManager);

    // use Gaussian function for weighting
    float sum = 0.0f;
    for (int i = 0; i < SMOOTHING_COUNT; ++i) {
      double x = i / (SMOOTHING_COUNT - 1.0);
View Full Code Here

    controllerFire = settings.getControllerFire(player);
  }

  @Override
  public Vector2f getMovement(float elapsedTime) {
    Vector2f v = new Vector2f(controllerRight.getAction(controller) - controllerLeft.getAction(controller),
        controllerUp.getAction(controller) - controllerDown.getAction(controller));
    v.scale(speed);

    return v;
  }
View Full Code Here

   */
  private InputManager() {
    settings = Settings.getInstance();
    device = new InputDevice[2];

    mouseD = new Vector2f(0.0f, 0.0f);

    // grab mouse
    Mouse.setGrabbed(true);

    // init controllers
View Full Code Here

    speed = settings.getMouseSpeed(player) * 0.007f;

    // init history
    for (int i = 0; i < SMOOTHING_COUNT; ++i)
      movementHistory.add(new Vector2f(0.0f, 0.0f));
  }
View Full Code Here

      movementHistory.add(new Vector2f(0.0f, 0.0f));
  }

  @Override
  public Vector2f getMovement(float elapsedTime) {
    Vector2f cur = new Vector2f(inputManager.getMouseMovementX(), inputManager.getMouseMovementY());

    // remove oldest element from list and add current
    movementHistory.remove();
    movementHistory.add(cur);

    // computed smoothed value
    Vector2f v = new Vector2f(0.0f, 0.0f);
    int i = 0;
    for (Vector2f vi : movementHistory) {
      v.x += vi.x * smoothingWeight[i];
      v.y += vi.y * smoothingWeight[i];
      ++i;
    }

    v.scale(speed / elapsedTime);
    return v;
  }
View Full Code Here

    keyFire = settings.getKeyFire(player);
  }

  @Override
  public Vector2f getMovement(float elapsedTime) {
    Vector2f v = new Vector2f(0.0f, 0.0f);

    if (Keyboard.isKeyDown(keyUp))
      v.y += speed;
    if (Keyboard.isKeyDown(keyDown))
      v.y -= speed;
View Full Code Here

  }

  @Override
  public void apply() {
    // just reflect velocity of ball
    Vector2f v1 = ball.getVelocity();
    switch (paddle.getPlace()) {
    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;
    }

    // update ball's last paddle
    if (paddle.isMovable()) {
View Full Code Here

  @Override
  public void apply() {
    if (!ball.isMovable()) {
      // collision with WallBall - stop paddle
      paddle.setVelocity(new Vector2f(0.0f, 0.0f));

      // stop attached ball
      if (paddle.isBallAttached()) {
        GameBall attachedBall = paddle.getAttachedBall();
        attachedBall.setVelocity(new Vector2f(0.0f, 0.0f));
      }
    } else { // ball is movable
      Vector2f hemispherePos;
      hemispherePos = paddle.getHemispherePosition(hemispherePlace);

      // if paddle is not movable, reflect ball at hemisphere
      if (!paddle.isMovable())
        reflectAtBall(ball, hemispherePos);
      else {
        // ball and paddle are movable
        // decompose the velocities of the balls into a component in the
        // direction of the line between the balls (normal) and a
        // perpendicular one (tangential)
        Vector2f v1 = paddle.getVelocity();
        Vector2f v2 = ball.getVelocity();
        float m1 = paddle.getMass();
        float m2 = ball.getMass();

        Vector2f n = new Vector2f();
        Vector2f.sub(ball.getPosition(), paddle.getHemispherePosition(hemispherePlace), n);
        n.normalise();
        Vector2f t = new Vector2f(n.y, -n.x);

        float v1_n = Vector2f.dot(v1, n);
        float v2_n = Vector2f.dot(v2, n);
        float v2_t = Vector2f.dot(v2, t);

        float u2_n;

        if (v1_n * v2_n <= 0.0f || Math.abs(v1_n) < Math.abs(v2_n)) {
          // directions are different or ball hits paddle
          // reflect ball and add some momentum of paddle to ball
          u2_n = 2.0f * m1 / (m1 + m2) * v1_n - v2_n;

          // stop paddle if directions are different
          if (v1_n * v2_n <= 0.0f)
            paddle.setVelocity(new Vector2f(0.0f, 0.0f));
        } else {
          // directions are the same and paddle hits ball
          // add some momentum of paddle to ball
          u2_n = 2.0f * m1 / (m1 + m2) * v1_n + v2_n;
        }
        // tangential components are not changed

        // transform to x- and y-components
        Vector2f n2 = new Vector2f(n.x, n.y);
        Vector2f t2 = new Vector2f(t.x, t.y);
        Vector2f.add((Vector2f) n2.scale(u2_n), (Vector2f) t2.scale(v2_t), v2);

        ball.setVelocity(v2);
      }

      // detach ball after collision
View Full Code Here

    PlayerPaddle p1 = new PlayerPaddle(0, Paddle.Place.BOTTOM, goManager);
    PlayerPaddle p2 = new PlayerPaddle(1, Paddle.Place.LEFT, goManager);
    new GameBall(p1, goManager);
    new GameBall(p2, goManager);

    new GameBall(new Vector2f(9.0f, 9.0f), 0.5f, goManager);

    for (int i = -5; i <= 4; ++i)
      for (int j = -5; j <= 4 && i + j <= 6 && (i + j <= 5 || i == 4 || j == 4); ++j)
        new Block(new Vector2f(5.0f + i, 5.0f + j), 1.0f, 1.0f, goManager);
  }
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.