Package org.lwjgl.util.vector

Examples of org.lwjgl.util.vector.Vector2f.scale()


  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;
  }

  public abstract boolean isMovable();
View Full Code Here


    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

      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

  @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;
  }

  @Override
View Full Code Here

      v.x += vi.x * smoothingWeight[i];
      v.y += vi.y * smoothingWeight[i];
      ++i;
    }

    v.scale(speed / elapsedTime);
    return v;
  }

  @Override
  public boolean isButtonDown() {
View Full Code Here

        // 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

    // place ball at a small distance from paddle
    Vector2f paddlePos = paddleAttached.getPosition();
    Vector2f dir = new Vector2f();
    paddlePos.negate(dir);
    dir.normalise();
    dir.scale(1.5f * radius + 1.5f * paddleAttached.getRadius());
    Vector2f.add(paddlePos, dir, dir);
    setPosition(dir);
  }

  public GameBall(Vector2f position, Vector2f velocity, float radius, GraphicsObjectsManager goManager) {
View Full Code Here

      Vector2f away = new Vector2f();
      Vector2f.sub(getPosition(), lastPaddle.getPosition(), away);
      away.normalise();
      Vector2f.add(away, new Vector2f((float) Math.random() - 0.5f, (float) Math.random() - 0.5f), away);
      away.normalise();
      away.scale(INITIAL_SPEED);

      Vector2f v = getVelocity();
      Vector2f.add(v, away, v);
      setVelocity(v);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.