Package org.lwjgl.util.vector

Examples of org.lwjgl.util.vector.Vector2f


  public final Vector2f getVelocity() {
    return new Vector2f(velocity.x, velocity.y);
  }

  public final void setVelocity(Vector2f velocity) {
    Vector2f v = new Vector2f(velocity.x, velocity.y);
    float speed = v.length();
    if (speed > MAX_SPEED)
      v.scale(MAX_SPEED / speed);
    this.velocity = v;
  }
View Full Code Here


  public void draw() {
    // store current transformation matrix
    GL11.glPushMatrix();

    float length = paddle.getLength();
    Vector2f pos = paddle.getPosition();

    // move and rotate paddle
    switch (paddle.getPlace()) {
    case LEFT:
    case RIGHT:
View Full Code Here

    GL11.glPopMatrix();
  }

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

   *            position of the ball to reflect the ball on
   */
  protected void reflectAtBall(Ball ball, Vector2f fixedBallPosition) {
    // let n be the vector connecting the balls (n is orthogonal to
    // reflection line)
    Vector2f n = new Vector2f();
    Vector2f.sub(fixedBallPosition, ball.getPosition(), n);
    n.normalise();

    // project velocity onto n and scale by 2
    n.scale(2.0f * Vector2f.dot(ball.getVelocity(), n));
    Vector2f newVel = new Vector2f();

    // add -projected velocity to velocity
    Vector2f.sub(ball.getVelocity(), n, newVel);
    ball.setVelocity(newVel);
  }
View Full Code Here

    }
  }

  @Override
  public void applyInput(float elapsedTime) {
    Vector2f movement = InputManager.getInstance().getMovement(player, elapsedTime);

    switch (place) {
    case TOP:
    case BOTTOM:
      setVelocity(new Vector2f(movement.x, 0.0f));
      break;

    case LEFT:
    case RIGHT:
      setVelocity(new Vector2f(0.0f, movement.y));
      break;
    }

    if (isBallAttached) {
      attachedBall.setVelocity(getVelocity());
View Full Code Here

      // decompose the velocities of the balls into a component in the
      // direction of the line between the balls (normal) and a
      // perpendicular one (tangential)
      // apply a central elastic collision to the normal components
      // and let the tangential components be unchanged
      Vector2f v1 = ball.getVelocity();
      Vector2f v2 = ball2.getVelocity();
      float m1 = ball.getMass();
      float m2 = ball2.getMass();

      Vector2f n = new Vector2f();
      Vector2f.sub(ball2.getPosition(), ball.getPosition(), 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 v1_t = Vector2f.dot(v1, t);
      float v2_t = Vector2f.dot(v2, t);

      // calculate new velocities in normal direction
      float u1_n = (m1 * v1_n - m2 * v1_n + 2.0f * m2 * v2_n) / (m1 + m2);
      float u2_n = (m2 * v2_n - m1 * v2_n + 2.0f * m1 * v1_n) / (m1 + m2);

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

      ball.setVelocity(v1);
      ball2.setVelocity(v2);
    }

View Full Code Here

    this.size = size;
    this.font = new Font();

    // use negative y-value because y-axis points upwards and origin is in
    // the upper left corner
    this.position = new Vector2f(position.x, -position.y);
  }
View Full Code Here

    float length = size * font.getCharacterWidth() * string.length();
    float height = size * font.getCharacterHeight();

    // use negative y-value because y-axis points upwards and origin is in
    // the upper left corner
    this.position = new Vector2f((resX - length) / 2.0f, -(resY - height) / 2.0f);
  }
View Full Code Here

  public void draw() {
    // store current transformation matrix
    GL11.glPushMatrix();

    // translate to item position
    Vector2f pos = item.getPosition();
    GL11.glTranslatef(pos.x, pos.y, 0.0f);

    // enable lighting with texture
    Lighting.enable(true);
View Full Code Here

    GL11.glPopMatrix();
  }

  @Override
  public Vector3f getPosition() {
    Vector2f pos = item.getPosition();
    return new Vector3f(pos.x, pos.y, 0.0f);
  }
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.