Package com.googlecode.jumpnevolve.math

Examples of com.googlecode.jumpnevolve.math.Vector


  }

  @Override
  public void setContent(String newContent) {
    try {
      Vector content = Vector.parseVector(newContent);
      this.xField.setContent("" + content.x);
      this.yField.setContent("" + content.y);
    } catch (NumberFormatException e) {
      Log.warn("VectorTextfield: Ungültiger Content: " + newContent);
    }
View Full Code Here


    // Ereignisse für verschiedene Objekttypen
    if (this instanceof Moving) {

      // Gewünschte Bewegunsrichtung
      Vector direction = ((Moving) this).getMovingDirection();

      if (direction.equals(0, 0)) {
        // Nichts tun
      } else {
        // Aktuelle Geschwindigkeit in die Bewegungsrichtung,
        // grundsätzlich ertmal 0
        float vel = 0.0f;

        if (!this.getVelocity().equals(0, 0)) {
          // Anteil der aktuellen Bewegung in die Bewegunsrichtung
          vel = (float) (Math.cos(this.getVelocity().ang(direction)) * this
              .getVelocity().abs());
        }

        // Gewünschte Geschwindigkeit in die Bewegunsrichtung
        float move = ((Moving) this).getMovingSpeed();

        // Multiplikator für die Kraft
        float mul = 1.0f;
        if (direction.x * direction.y != 0) {
          mul = 0.707f;
        }

        // Kraft hinzufügen, die in die gewünschte Bewegunsrichtung
        // zeigt
        // und entsprechend des Unterschieds zwischen Bewegung und
        // Wunsch
        // skaliert ist
        this.applyForce(direction.mul(mul * (move - vel) * 1.5f
            * this.getMass()));
      }

    }
    if (this instanceof Jumping) {
View Full Code Here

            if (colResult.isIntersecting()) {
              if (this instanceof ElasticBlockable) {
                if (other instanceof ElasticBlockable) {
                  // Berechnen der neuen Impulse durch
                  // entsprechende Addition der alten Impulse
                  Vector thisImpulse = this.onElasticCrash(
                      other, colResult.getIsOverlap()
                          .neg()), otherImpulse = other
                      .onElasticCrash(this,
                          colResult.getIsOverlap());

                  // Setzen der neuen Impulse, aber je mit
                  // halber Länge, da beide alten Impulse in
                  // den Rechnungen insgesamt doppelt
                  // vorkommen
                  this.setImpulse(thisImpulse.mul(0.5f));
                  other.setImpulse(otherImpulse.mul(0.5f));
                } else {
                  // Neuen Impuls für dieses Objekt setzen
                  this.setImpulse(this.onElasticCrash(other,
                      colResult.getIsOverlap()));
View Full Code Here

      this.shape = this.collision.correctPosition(this.shape);
      this.force = this.collision.correctForce(this.force);
      this.velocity = this.collision.correctVelocity(this.velocity);

      // Neue Geschwindigkeit bestimmen
      Vector acceleration = this.force.div(this.mass);
      Vector deltaVelocity = acceleration.mul(this.oldStep);
      this.velocity = this.velocity.add(deltaVelocity);

      // Begrenze die Geschwindigkeit
      if (this.velocity.x > AbstractObject.MAXIMUM_VELOCITY_ONE_WAY) {
        this.velocity = this.velocity
            .modifyX(AbstractObject.MAXIMUM_VELOCITY_ONE_WAY);
      } else if (this.velocity.x < -AbstractObject.MAXIMUM_VELOCITY_ONE_WAY) {
        this.velocity = this.velocity
            .modifyX(-AbstractObject.MAXIMUM_VELOCITY_ONE_WAY);
      }
      if (this.velocity.y > AbstractObject.MAXIMUM_VELOCITY_ONE_WAY) {
        this.velocity = this.velocity
            .modifyY(AbstractObject.MAXIMUM_VELOCITY_ONE_WAY);
      } else if (this.velocity.y < -AbstractObject.MAXIMUM_VELOCITY_ONE_WAY) {
        this.velocity = this.velocity
            .modifyY(-AbstractObject.MAXIMUM_VELOCITY_ONE_WAY);
      }

      // Entsprechend die neue Position berechnen
      Vector newPos = this.shape.getCenter().add(
          this.velocity.mul(this.oldStep));

      // Neues Shape bestimmen
      NextShape newShape = this.shape.modifyCenter(newPos);
      this.oldShape = this.shape;
View Full Code Here

  private void applyGravity() {
    this.applyForce(Vector.DOWN.mul(GRAVITY * this.mass));
  }

  private Vector onElasticCrash(AbstractObject other, Vector lot) {
    Vector thisNegImpulse = this.getImpulse().neg();
    Vector usedLot;
    if (!thisNegImpulse.isZero()) {
      if (lot.isZero()) {
        return this.getImpulse();
      } else {
        usedLot = lot;
      }
      float ang = usedLot.clockWiseAng(thisNegImpulse);
      if (ang < 3 * Math.PI / 2 && ang > Math.PI / 2) {
        return this.getImpulse();
      }
      Vector newImpulse = thisNegImpulse.rotate(-2 * ang)
          .add(other.getImpulse())
          .mul(((ElasticBlockable) this).getElasticityFactor());
      return newImpulse;
    } else {
      return Vector.ZERO;
View Full Code Here

    return "backgrounds/" + background;
  }

  protected void drawBackground(Graphics g) {
    GraphicUtils.drawImage(g, ShapeFactory
        .createRectangle(new Vector(this.width / 2.0f,
            this.height / 2.0f), this.width, this.height),
        ResourceManager.getInstance()
            .getImage(this.getBackgroundFile()));
  }
View Full Code Here

    // TODO: Zoom und Kameraeinstellungen prüfen
    g.scale(zoomX, zoomY);

    // Kameraeinstellung anwenden
    if (this.camera != null) {
      Vector cameraPosition = this.camera.getPosition();
      g.translate(Engine.getInstance().getWidth() / zoomX / 2.0f
          - cameraPosition.x, Engine.getInstance().getHeight()
          / zoomY / 2.0f - cameraPosition.y);
    }
    this.drawBackground(g);
View Full Code Here

  public Vector getPositionFor(InterfacePart object) {
    if (object instanceof InterfaceButton) {
      int listPos = this.invertList.get(object);
      if (listPos != BACK_POS && listPos != FORTH_POS) {
        if (listPos < this.curPos) {
          return new Vector(-InterfaceButton.BUTTON_DIMENSION * 10, 0);
        }
        if (listPos >= this.curPos + this.numberOfButtonsDisplayed) {
          return new Vector(-InterfaceButton.BUTTON_DIMENSION * 10, 0);
        }
      }
      listPos = listPos - this.curPos;
      return getPositionForListPos(listPos).add(
          this.parentContainer.getPositionFor(this));
View Full Code Here

    if (listPos + this.curPos == BACK_POS) {
      listPos = -1;
    } else if (listPos + this.curPos == FORTH_POS) {
      listPos = this.numberOfButtonsDisplayed;
    }
    return new Vector(
        (InterfaceButton.BUTTON_DIMENSION + this.distanceBetweenButtons)
            * (listPos + 1), 0.0f);

  }
View Full Code Here

   */
  public void add(InterfacePart adding, int row, int col, int modusX,
      int modusY) {
    this.modiX[col][row] = modusX;
    this.modiY[col][row] = modusY;
    super.add(adding, new Vector(col, row));
  }
View Full Code Here

TOP

Related Classes of com.googlecode.jumpnevolve.math.Vector

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.