Package org.lwjgl.util.vector

Examples of org.lwjgl.util.vector.Vector2f


    this.length = length;
    this.radius = PonkOut.COMMON_RADIUS;

    switch (place) {
    case LEFT:
      setPosition(new Vector2f(-TOP_POS, 0.0f));
      break;

    case RIGHT:
      setPosition(new Vector2f(TOP_POS, 0.0f));
      break;

    case TOP:
      setPosition(new Vector2f(0.0f, TOP_POS));
      break;

    case BOTTOM:
      setPosition(new Vector2f(0.0f, -TOP_POS));
      break;
    }

    graphicsObject = new PaddleGO(this, material, goManager);
View Full Code Here


    // 3/(4pi) * (volume of the sphere + cylinder)
    return radius * radius * radius + 0.75f * radius * radius * length;
  }

  public Vector2f getHemispherePosition(HemispherePlace hemispherePlace) {
    Vector2f p = getPosition();
    switch (place) {
    case LEFT:
    case RIGHT:
      if (hemispherePlace == HemispherePlace.TOP_LEFT)
        return new Vector2f(p.x, p.y + length / 2.0f);
      else
        return new Vector2f(p.x, p.y - length / 2.0f);

    case TOP:
    case BOTTOM:
      if (hemispherePlace == HemispherePlace.TOP_LEFT)
        return new Vector2f(p.x - length / 2.0f, p.y);
      else
        return new Vector2f(p.x + length / 2.0f, p.y);
    }

    throw new IllegalStateException("Paddle in unspecified place");
  }
View Full Code Here

    attached = true;
    lastPaddle = paddleAttached;
    paddleAttached.attachBall(this);

    // 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 GameBall(Vector2f position, Vector2f velocity, GraphicsObjectsManager goManager) {
    this(position, velocity, PonkOut.COMMON_RADIUS, goManager);
  }

  public GameBall(Vector2f position, float radius, GraphicsObjectsManager goManager) {
    this(position, new Vector2f(0.0f, 0.0f), radius, goManager);
  }
View Full Code Here

  public GameBall(Vector2f position, float radius, GraphicsObjectsManager goManager) {
    this(position, new Vector2f(0.0f, 0.0f), radius, goManager);
  }

  public GameBall(Vector2f position, GraphicsObjectsManager goManager) {
    this(position, new Vector2f(0.0f, 0.0f), PonkOut.COMMON_RADIUS, goManager);
  }
View Full Code Here

  /** throws ball away from paddle */
  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();
      Vector2f.add(v, away, v);
      setVelocity(v);

      detach();
    }
View Full Code Here

    super(Material.getPresetMaterial(Material.PresetMaterial.PEWTER), goManager);

    this.place = place;
    switch (place) {
    case TOP_LEFT:
      setPosition(new Vector2f(-TOP_POS, TOP_POS));
      break;

    case TOP_RIGHT:
      setPosition(new Vector2f(TOP_POS, TOP_POS));
      break;

    case BOTTOM_LEFT:
      setPosition(new Vector2f(-TOP_POS, -TOP_POS));
      break;

    case BOTTOM_RIGHT:
      setPosition(new Vector2f(TOP_POS, -TOP_POS));
      break;
    }
  }
View Full Code Here

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

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

    // enable lighting
    Lighting.enable(false);
View Full Code Here

    BlockFace[] topExtension = { null, null };
    BlockFace[] bottomExtension = { null, null };

    for (int i = 0; i < 2; ++i) {
      for (BlockFace face : verticalFaces.get(i)) {
        Vector2f faceTop = face.getFirstCorner();
        Vector2f faceBottom = face.getSecondCorner();

        // find right/left neighbour
        if (Math.abs(faceTop.x - blockTop[(i + 1) % 2].x) < EPS && faceBottom.y < blockTop[i].y
            && faceTop.y > blockBottom[i].y)
          horizontalNeighbours.get((i + 1) % 2).add(face);

        // find top/bottom extension
        if (Math.abs(faceTop.x - blockTop[i].x) < EPS) {
          if (Math.abs(faceBottom.y - blockTop[i].y) < EPS)
            topExtension[i] = face;
          else if (Math.abs(faceTop.y - blockBottom[i].y) < EPS)
            bottomExtension[i] = face;
        }
      }
    }

    for (int i = 0; i < 2; ++i) {
      BlockFace face = null;

      // create a new face if no extension was found
      // add it to existing face if there is exactly one extension
      // merge to faces if two extensions were found
      if (topExtension[i] == null && bottomExtension[i] == null) {
        // only if block is not smaller than neighbour
        // if it has more than one neighbours it cannot be completely
        // hidden by them
        BlockFace neighbour = null;
        if (horizontalNeighbours.get(i).size() == 1)
          neighbour = horizontalNeighbours.get(i).getFirst();
        if (neighbour == null || neighbour.getFirstCorner().y < blockTop[i].y
            || neighbour.getSecondCorner().y > blockBottom[i].y) {
          face = new BlockFace(block, i == 0 ? FacePlace.LEFT : FacePlace.RIGHT);
          verticalFaces.get(i).add(face);
        }
      } else if (topExtension[i] != null && bottomExtension[i] == null) {
        face = topExtension[i];
        face.addBack(block);
      } else if (topExtension[i] == null && bottomExtension[i] != null) {
        face = bottomExtension[i];
        face.addFront(block);
      } else {
        face = topExtension[i];
        face.addBack(block);
        face.addBack(bottomExtension[i]);
        verticalFaces.get(i).remove(bottomExtension[i]);
      }

      for (BlockFace neighbour : horizontalNeighbours.get(i)) {
        float neighbourTop = neighbour.getFirstCorner().y;
        float neighbourBottom = neighbour.getSecondCorner().y;

        // adjust corners if exactly one overlaps neighbour
        // both cases cannot happen for more than one neighbour
        // it is not necessary to split face if there is a neighbour in
        // the middle
        if (face != null) {
          if (neighbourTop < face.getFirstCorner().y && neighbourBottom <= face.getSecondCorner().y)
            face.setSecondCorner(neighbour.getFirstCorner());
          else if (neighbourBottom > face.getSecondCorner().y && neighbourTop >= face.getFirstCorner().y)
            face.setFirstCorner(neighbour.getSecondCorner());
        }

        // delete neighbour if it is smaller
        // adjust corners if exactly one overlaps
        if (neighbourTop <= blockTop[i].y && neighbourBottom >= blockBottom[i].y)
          removeFace(neighbour);
        else if (neighbourTop > blockTop[i].y && neighbourBottom >= blockBottom[i].y) {
          // follow the block's face upwards
          Block lastBlock = block;
          boolean found;
          do {
            found = false;
            for (Block nextBlock : blocks) {
              Vector2f dv = new Vector2f();
              if (i == 0) // left face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.TOP_LEFT),
                    nextBlock.getCornerPos(CornerPlace.BOTTOM_LEFT), dv);
              else
                // right face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.TOP_RIGHT),
                    nextBlock.getCornerPos(CornerPlace.BOTTOM_RIGHT), dv);

              if (Math.abs(dv.x) < EPS && Math.abs(dv.y) < EPS) {
                lastBlock = nextBlock;
                found = true;
                break;
              }
            }
          } while (found);

          neighbour.setSecondCorner(lastBlock.getCornerPos((i == 0) ? CornerPlace.TOP_LEFT
              : CornerPlace.TOP_RIGHT));
        } else if (neighbourBottom < blockBottom[i].y && neighbourTop <= blockTop[i].y) {
          // follow the block's face downwards
          Block lastBlock = block;
          boolean found;
          do {
            found = false;
            for (Block nextBlock : blocks) {
              Vector2f dv = new Vector2f();
              if (i == 0) // left face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.BOTTOM_LEFT),
                    nextBlock.getCornerPos(CornerPlace.TOP_LEFT), dv);
              else
                // right face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.BOTTOM_RIGHT),
                    nextBlock.getCornerPos(CornerPlace.TOP_RIGHT), dv);

              if (Math.abs(dv.x) < EPS && Math.abs(dv.y) < EPS) {
                lastBlock = nextBlock;
                found = true;
                break;
              }
            }
          } while (found);

          neighbour.setFirstCorner(lastBlock.getCornerPos((i == 0) ? CornerPlace.BOTTOM_LEFT
              : CornerPlace.BOTTOM_RIGHT));
        }
      }
    }

    // update the horizontal block faces
    ArrayList<LinkedList<BlockFace>> horizontalFaces = new ArrayList<LinkedList<BlockFace>>();
    horizontalFaces.add(topBlockFaces);
    horizontalFaces.add(bottomBlockFaces);

    BlockFace[] leftExtension = { null, null };
    BlockFace[] rightExtension = { null, null };

    for (int i = 0; i < 2; ++i) {
      for (BlockFace face : horizontalFaces.get(i)) {
        Vector2f faceLeft = face.getFirstCorner();
        Vector2f faceRight = face.getSecondCorner();

        // find bottom/top neighbour
        if (Math.abs(faceLeft.y - blockLeft[(i + 1) % 2].y) < EPS && faceRight.x > blockLeft[i].x
            && faceLeft.x < blockRight[i].x)
          verticalNeighbours.get((i + 1) % 2).add(face);

        // find left/right extension
        if (Math.abs(faceLeft.y - blockLeft[i].y) < EPS) {
          if (Math.abs(faceRight.x - blockLeft[i].x) < EPS)
            leftExtension[i] = face;
          else if (Math.abs(faceLeft.x - blockRight[i].x) < EPS)
            rightExtension[i] = face;
        }
      }
    }

    for (int i = 0; i < 2; ++i) {
      BlockFace face = null;

      // create a new face if no extension was found
      // add it to existing face if there is exactly one extension
      // merge to faces if two extensions were found
      if (leftExtension[i] == null && rightExtension[i] == null) {
        // only if block is not smaller than neighbour
        // if it has more than one neighbours it cannot be completely
        // hidden by them
        BlockFace neighbour = null;
        if (verticalNeighbours.get(i).size() == 1)
          neighbour = verticalNeighbours.get(i).getFirst();
        if (neighbour == null || neighbour.getFirstCorner().x > blockLeft[i].x
            || neighbour.getSecondCorner().x < blockRight[i].x) {
          face = new BlockFace(block, i == 0 ? FacePlace.TOP : FacePlace.BOTTOM);
          horizontalFaces.get(i).add(face);
        }
      } else if (leftExtension[i] != null && rightExtension[i] == null) {
        face = leftExtension[i];
        face.addBack(block);
      } else if (leftExtension[i] == null && rightExtension[i] != null) {
        face = rightExtension[i];
        face.addFront(block);
      } else {
        face = leftExtension[i];
        face.addBack(block);
        face.addBack(rightExtension[i]);
        horizontalFaces.get(i).remove(rightExtension[i]);
      }

      for (BlockFace neighbour : verticalNeighbours.get(i)) {
        float neighbourLeft = neighbour.getFirstCorner().x;
        float neighbourRight = neighbour.getSecondCorner().x;

        // adjust corners if exactly one overlaps neighbour
        // both cases cannot happen for more than one neighbour
        // it is not necessary to split face if there is a neighbour in
        // the middle
        if (face != null) {
          if (neighbourLeft > face.getFirstCorner().x && neighbourRight >= face.getSecondCorner().x)
            face.setSecondCorner(neighbour.getFirstCorner());
          else if (neighbourRight < face.getSecondCorner().x && neighbourLeft <= face.getFirstCorner().x)
            face.setFirstCorner(neighbour.getSecondCorner());
        }

        // delete neighbour if it is smaller
        // adjust corners if exactly one overlaps
        if (neighbourLeft >= blockLeft[i].x && neighbourRight <= blockRight[i].x)
          removeFace(neighbour);
        else if (neighbourLeft < blockLeft[i].x && neighbourRight <= blockRight[i].x) {
          // follow the block's face leftwards
          Block lastBlock = block;
          boolean found;
          do {
            found = false;
            for (Block nextBlock : blocks) {
              Vector2f dv = new Vector2f();
              if (i == 0) // top face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.TOP_LEFT),
                    nextBlock.getCornerPos(CornerPlace.TOP_RIGHT), dv);
              else
                // bottom face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.BOTTOM_LEFT),
                    nextBlock.getCornerPos(CornerPlace.BOTTOM_RIGHT), dv);

              if (Math.abs(dv.x) < EPS && Math.abs(dv.y) < EPS) {
                lastBlock = nextBlock;
                found = true;
                break;
              }
            }
          } while (found);

          neighbour.setSecondCorner(lastBlock.getCornerPos((i == 0) ? CornerPlace.TOP_LEFT
              : CornerPlace.BOTTOM_LEFT));
        } else if (neighbourRight > blockRight[i].x && neighbourLeft >= blockLeft[i].x) {
          // follow the block's face rightwards
          Block lastBlock = block;
          boolean found;
          do {
            found = false;
            for (Block nextBlock : blocks) {
              Vector2f dv = new Vector2f();
              if (i == 0) // top face
                Vector2f.sub(lastBlock.getCornerPos(CornerPlace.TOP_RIGHT),
                    nextBlock.getCornerPos(CornerPlace.TOP_LEFT), dv);
              else
                // bottom face
View Full Code Here

    LinkedList<Block> leftNeighbours = new LinkedList<Block>();
    LinkedList<Block> rightNeighbours = new LinkedList<Block>();
    LinkedList<Block> topNeighbours = new LinkedList<Block>();
    LinkedList<Block> bottomNeighbours = new LinkedList<Block>();

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

    for (Block block2 : blocks) {
      Vector2f b2TopLeft = block2.getCornerPos(CornerPlace.TOP_LEFT);
      Vector2f b2BottomRight = block2.getCornerPos(CornerPlace.BOTTOM_RIGHT);

      if (Math.abs(topLeft.x - b2BottomRight.x) < EPS && b2BottomRight.y < topLeft.y
          && b2TopLeft.y > bottomRight.y)
        leftNeighbours.add(block2);
      else if (Math.abs(bottomRight.x - b2TopLeft.x) < EPS && b2BottomRight.y < topLeft.y
          && b2TopLeft.y > bottomRight.y)
        rightNeighbours.add(block2);
      else if (Math.abs(topLeft.y - b2BottomRight.y) < EPS && b2BottomRight.x > topLeft.x
          && b2TopLeft.x < bottomRight.x)
        topNeighbours.add(block2);
      else if (Math.abs(bottomRight.y - b2TopLeft.y) < EPS && b2BottomRight.x > topLeft.x
          && b2TopLeft.x < bottomRight.x)
        bottomNeighbours.add(block2);
    }

    // sort lists for easy creation of new faces
    Collections.sort(leftNeighbours, Block.verticalComparator);
    Collections.sort(rightNeighbours, Block.verticalComparator);
    Collections.sort(topNeighbours, Block.horizontalComperator);
    Collections.sort(bottomNeighbours, Block.horizontalComperator);

    // create new faces for the adjacent blocks if they do not already exist
    // create shortcuts here: left neighbour will get a right face etc.
    ArrayList<LinkedList<Block>> neighbours = new ArrayList<LinkedList<Block>>(Collections.nCopies(4,
        (LinkedList<Block>) null));
    neighbours.set(FacePlace.LEFT.ordinal(), rightNeighbours);
    neighbours.set(FacePlace.RIGHT.ordinal(), leftNeighbours);
    neighbours.set(FacePlace.TOP.ordinal(), bottomNeighbours);
    neighbours.set(FacePlace.BOTTOM.ordinal(), topNeighbours);

    for (FacePlace facePlace : FacePlace.values()) {
      BlockFace face = null;
      for (Block neighbour : neighbours.get(facePlace.ordinal())) {
        if (neighbour.getFace(facePlace) == null) {
          if (face == null) // first hit
            face = new BlockFace(neighbour, facePlace);
          else {
            // check if block extends old face
            Vector2f dv = new Vector2f();
            switch (facePlace) {
            case LEFT:
              Vector2f.sub(face.getSecondCorner(), neighbour.getCornerPos(CornerPlace.TOP_LEFT), dv);
              break;
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.