Example #1
0
  public boolean equals(Object obj) {
    if (!obj.getClass().getName().endsWith("Vertex")) {
      return false;
    }

    Vertex otherVert = (Vertex) obj;
    // Compare position
    Vector3f otherPos = otherVert.getPosition();
    if (position.getX() != otherPos.getX()) {
      return false;
    }
    if (position.getY() != otherPos.getY()) {
      return false;
    }
    if (position.getZ() != otherPos.getZ()) {
      return false;
    }
    // Compare Unwrap
    Vector2f otherUnwrap = otherVert.getUnwrap();
    if (unwrap.getX() != otherUnwrap.getX()) {
      return false;
    }
    if (unwrap.getY() != otherUnwrap.getY()) {
      return false;
    }
    // Compare Normal
    boolean hasNormal = hasNormal();
    boolean otherHasNormal = otherVert.hasNormal();
    if (hasNormal != otherHasNormal) {
      return false;
    } // One has normal, the other one doesn't
    if (hasNormal == false) {
      return true;
    } // Since both are same, both don't have a normal
    Vector3f otherNormal = otherVert.getNormal();
    if (normal.getX() != otherNormal.getX()) {
      return false;
    }
    if (normal.getY() != otherNormal.getY()) {
      return false;
    }
    if (normal.getZ() != otherNormal.getZ()) {
      return false;
    }
    // All clear
    return true;
  }
Example #2
0
  private boolean bounceBall(BounceableControl control) {
    /*
    log.debug("Cheking...");
    log.debug("\tcontrol: "+control.getPosition().toString()+", ball: "+ball.getPosition().toString());
    log.debug("\tvector: x="+ballUnitVector.getX()+", y="+ballUnitVector.getY());
    */

    boolean isHit = false;
    if ((control.isVisible()) && (control.isHit(ball.getPosition()))) {
      log.debug("bounced!!!!!!!!!!!!!!");

      float angleDelta = 90.0f - control.getRotation();

      // get current angle of ball vector
      Point previousBallPosition = new Point(0.0f, 0.0f);
      Point currentBallPosition = new Point(ballUnitVector.getX(), ballUnitVector.getY());
      // float ballVectorMagnitude = PointUtility.getDistance(previousBallPosition,
      // currentBallPosition);
      float currentBallAngle = PointUtility.getAngle(previousBallPosition, currentBallPosition);
      log.debug("\t\tcurrentBallAngle=" + currentBallAngle);

      // get new vector
      float targetBallAngle = (currentBallAngle + angleDelta);
      float newX = (float) Math.cos(Math.toRadians(targetBallAngle));
      float newY = (float) Math.sin(Math.toRadians(targetBallAngle));
      log.debug("\t\tnew vector: x=" + newX + ", y=" + newY);
      newX = (-1 * newX);

      // back to original angle
      previousBallPosition.set(0.0f, 0.0f);
      currentBallPosition.set(newX, newY);
      log.debug("\t\tnewX=" + newX + ", newY=" + newY);
      float newAngle = PointUtility.getAngle(previousBallPosition, currentBallPosition);
      targetBallAngle = (newAngle - angleDelta);
      log.debug("\t\tnew angle=" + newAngle + ", targetBallAngle=" + targetBallAngle);

      newX = (float) Math.cos(Math.toRadians(targetBallAngle));
      newY = (float) Math.sin(Math.toRadians(targetBallAngle));
      ballUnitVector.set(newX, newY);
      ballUnitVector = ballUnitVector.normalise(null);
      log.debug("\t\tfinal: x=" + ballUnitVector.getX() + ", y=" + ballUnitVector.getY());

      isHit = true;
    }

    return isHit;
  }
Example #3
0
  private void onGameStatePlaying() {
    // ball
    Point position = ball.getPosition();
    if (shadowCount >= SHADOW_SKIP) {
      if (previousBallPositions.size() >= NUMBER_OF_BALL_SHADOWS) {
        previousBallPositions.removeLast();
      }
      previousBallPositions.addFirst(new Point(position));
      shadowCount = 0;
    } else {
      shadowCount += 1;
    }
    position.add((ballSpeed * ballUnitVector.getX()), -(ballSpeed * ballUnitVector.getY()));
    ball.setPosition(position);
    ball.setVisible(true);

    for (int i = 0; i < NUMBER_OF_BALL_SHADOWS; i++) {
      VisualControl visualControl = ballShadows.get(i);
      if (previousBallPositions.size() > i) {
        visualControl.setPosition(previousBallPositions.get(i));
        visualControl.setVisible(true);
      } else {
        visualControl.setVisible(false);
      }
    }

    // bounce
    if (bouncedControl != null) {
      if (!bouncedControl.isHit(ball.getPosition())) {
        bouncedControl = null;
      }
    } else {
      for (BounceableControl bounceableControl : paddles.values()) {
        bounceableControls.add(bounceableControl);
      }

      for (BounceableControl bounceableControl : bounceableControls) {
        if (bounceBall(bounceableControl)) {
          bouncedControl = bounceableControl;
          break;
        }
      }

      for (BounceableControl bounceableControl : paddles.values()) {
        bounceableControls.remove(bounceableControl);
      }
    }

    // goal
    if ((position.getX() <= 0.0f) || (position.getX() >= (float) displayMode.getWidth())) {
      gameState = GameState.End;
    }
  }
Example #4
0
  private void setupViewMatrix(boolean reverseY) {

    viewMatrix = new Matrix4f();

    Matrix4f.rotate(
        (reverseY ? -1 : 1) * cameraAngle.getY(), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);

    Matrix4f.rotate(cameraAngle.getX(), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);

    Matrix4f.translate(
        reverseY ? new Vector3f(cameraPos.getX(), -cameraPos.getY(), cameraPos.getZ()) : cameraPos,
        viewMatrix,
        viewMatrix);
  }
Example #5
0
  private void update() {
    float posDelta = 0.1f;

    if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
      Vector3f.add(
          cameraPos,
          new Vector3f(
              (float) (Math.cos(cameraAngle.getX() + Math.PI / 2) * posDelta),
              0,
              (float) (Math.sin(cameraAngle.getX() + Math.PI / 2) * posDelta)),
          cameraPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
      Vector3f.add(
          cameraPos,
          new Vector3f(
              (float) (Math.cos(cameraAngle.getX() + Math.PI) * posDelta),
              0,
              (float) (Math.sin(cameraAngle.getX() + Math.PI) * posDelta)),
          cameraPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
      Vector3f.add(
          cameraPos,
          new Vector3f(
              (float) (Math.cos(cameraAngle.getX() + Math.PI * 3 / 2) * posDelta),
              0,
              (float) (Math.sin(cameraAngle.getX() + Math.PI * 3 / 2) * posDelta)),
          cameraPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
      Vector3f.add(
          cameraPos,
          new Vector3f(
              (float) (Math.cos(cameraAngle.getX()) * posDelta),
              0,
              (float) (Math.sin(cameraAngle.getX()) * posDelta)),
          cameraPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_Q)) {
      Vector3f.add(cameraPos, new Vector3f(0, -1, 0), cameraPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_E)) {
      Vector3f.add(cameraPos, new Vector3f(0, 1, 0), cameraPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_R)) {
      Vector3f.add(modelAngle, new Vector3f(0, 0.05f, 0), modelAngle);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
      Vector3f.add(modelPos, new Vector3f(0.1f, 0, 0), modelPos);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
      Vector3f.add(modelPos, new Vector3f(-0.1f, 0, 0), modelPos);
    }

    Vector2f.add(cameraAngle, new Vector2f(Mouse.getDX() * 0.004f, 0), cameraAngle);
    Vector2f.add(cameraAngle, new Vector2f(0, -Mouse.getDY() * 0.004f), cameraAngle);

    if (cameraAngle.getY() > Math.PI / 2) cameraAngle.setY((float) Math.PI / 2);
    if (cameraAngle.getY() < -Math.PI / 2) cameraAngle.setY((float) -Math.PI / 2);
  }
Example #6
0
 public float[] getUVW() {
   return new float[] {unwrap.getX(), unwrap.getY(), 0f};
 }
Example #7
0
 public Vector2f getUnwrap() {
   return new Vector2f(unwrap.getX(), unwrap.getY());
 }