Package org.lwjgl.util.vector

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


  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();

View Full Code Here


      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);
View Full Code Here

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

View Full Code Here

  public void serve() {
    if (attached) {
      // add random velocity away from paddle
      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();
View Full Code Here

      // add random velocity away from paddle
      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

 
  public void fire()
  {
    // Fire a bullet to player's ship
    Vector2f directionToplayer = new Vector2f(Prototyp.player1.position.x-this.position.x,Prototyp.player1.position.y-this.position.y);
    directionToplayer.normalise();
    directionToplayer.x *= 50;
    directionToplayer.y *= 50;
   
    EnemyBullet b = new EnemyBullet();
   
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.