Package pi.physics

Class BodyHandler

java.lang.Object
pi.physics.BodyHandler
All Implemented Interfaces:
pi.physics.PhysicsHandler

public class BodyHandler extends Object implements pi.physics.PhysicsHandler
Ein Body-Handler kümmert sich um die physikalische Darstellung eines Actor-Objekts.

Er übernimmt zwei wesentliche Aufgaben:

  • Die Kontrolle und Steuerung innerhalb der Physics-Engine aus Sicht des respektiven Actor-Objekts.
  • Die Speicherung der räumlichen Eigenschaften (Position und Rotation) des respektiven Actor-Objekts.
  • Method Details

    • body

      public de.pirckheimer_gymnasium.jbox2d.dynamics.Body body()
      Wird intern zum Debuggen benutzt. Gibt den korrespondierenden Body aus.
      Specified by:
      body in interface pi.physics.PhysicsHandler
      Returns:
      Der korrespondierende Body.
    • moveBy

      public void moveBy(Vector meters)
      Verschiebt das Ziel-Objekt um einen spezifischen Wert auf der Zeichenebene. Die Ausführung hat erst (ggf.) im kommenden Frame einfluss auf die Physics und ändert keine physikalischen Eigenschaften des Ziel-Objekts (außer dessen Ort).
      Specified by:
      moveBy in interface pi.physics.PhysicsHandler
      Parameters:
      meters - Ein Vector, um den das Ziel-Objekt verschoben werden soll. Dies ändert seine Position, jedoch sonst keine weiteren Eigenschaften.
    • center

      public Vector center()
      Gibt den Gewichtsmittelpunkt dieses Actor-Objekts aus.
      Specified by:
      center in interface pi.physics.PhysicsHandler
      Returns:
      der aktuelle Gewichtsmittelpunkt des Ziel-Objekts als Point auf der Zeichenebene.
    • contains

      public boolean contains(Vector vector)
      Gibt an, ob ein bestimmter Punkt auf der Zeichenebene innerhalb des Ziel-Objekts liegt.
      Specified by:
      contains in interface pi.physics.PhysicsHandler
      Parameters:
      vector - Ein Punkt auf der Zeichenebene.
      Returns:
      true, wenn der übergebene Punkt innerhalb des Ziel-Objekts liegt, sonst false. Das Ergebnis kann (abhängig von der implementierenden Klasse) verschieden sicher richtige Ergebnisse liefern.
    • anchor

      public Vector anchor()
      Gibt die aktuelle Anker-Position des Ziel-Objekts an.
      Specified by:
      anchor in interface pi.physics.PhysicsHandler
      Returns:
      Die aktuelle Anker-Position des Ziel-Objekts. Diese ist bei Erstellung des Objekts zunächst immer (0|0) und wird mit Rotation und Verschiebung verändert.
    • rotation

      public double rotation()
      Gibt die aktuelle Rotation des Ziel-Objekts in Grad an. Bei Erstellung eines Actor-Objekts ist seine Rotation stets 0.
      Specified by:
      rotation in interface pi.physics.PhysicsHandler
      Returns:
      die aktuelle Rotation des Ziel-Objekts in Grad.
    • rotateBy

      public void rotateBy(double degree)
      Rotiert das Ziel-Objekt um einen festen Winkel.
      Specified by:
      rotateBy in interface pi.physics.PhysicsHandler
      Parameters:
      degree - Der Winkel, um den das Ziel-Objekt gedreht werden soll (in Grad).
      • Werte > 0: Drehung gegen Uhrzeigersinn
      • Werte < 0: Drehung im Uhrzeigersinn
    • rotation

      public void rotation(double degree)
      Specified by:
      rotation in interface pi.physics.PhysicsHandler
    • density

      public void density(double density)
      Specified by:
      density in interface pi.physics.PhysicsHandler
    • density

      public double density()
      Specified by:
      density in interface pi.physics.PhysicsHandler
    • gravityScale

      public void gravityScale(double factor)
      Specified by:
      gravityScale in interface pi.physics.PhysicsHandler
    • gravityScale

      public double gravityScale()
      Specified by:
      gravityScale in interface pi.physics.PhysicsHandler
    • friction

      public void friction(double friction)
      Specified by:
      friction in interface pi.physics.PhysicsHandler
    • friction

      public double friction()
      Specified by:
      friction in interface pi.physics.PhysicsHandler
    • restitution

      public void restitution(double restitution)
      Specified by:
      restitution in interface pi.physics.PhysicsHandler
    • restitution

      public double restitution()
      Specified by:
      restitution in interface pi.physics.PhysicsHandler
    • linearDamping

      public void linearDamping(double damping)
      Specified by:
      linearDamping in interface pi.physics.PhysicsHandler
    • linearDamping

      public double linearDamping()
      Specified by:
      linearDamping in interface pi.physics.PhysicsHandler
    • angularDamping

      public void angularDamping(double damping)
      Specified by:
      angularDamping in interface pi.physics.PhysicsHandler
    • angularDamping

      public double angularDamping()
      Specified by:
      angularDamping in interface pi.physics.PhysicsHandler
    • mass

      public double mass()
      Gibt die Masse des Ziel-Objekts aus.
      Specified by:
      mass in interface pi.physics.PhysicsHandler
      Returns:
      Die Masse des Ziel-Objekts in [kg].
    • applyForce

      public void applyForce(Vector force)
      Übt eine Kraft auf das Ziel-Objekt (im Massenschwerpunkt) aus (sofern möglich).
      Specified by:
      applyForce in interface pi.physics.PhysicsHandler
      Parameters:
      force - Die Kraft, die auf den Massenschwerpunkt angewandt werden soll. Nicht in [px], sondern in [N] = [m / s^2].
    • applyTorque

      public void applyTorque(double torque)
      Wirkt einen Drehmoment auf das Ziel-Objekt.
      Specified by:
      applyTorque in interface pi.physics.PhysicsHandler
      Parameters:
      torque - der Drehmoment, der auf das Ziel-Objekt wirken soll. In [N*m]
    • applyRotationImpulse

      public void applyRotationImpulse(double rotationImpulse)
      Wirkt einen Drehimpuls auf das Ziel-Objekt.
      Specified by:
      applyRotationImpulse in interface pi.physics.PhysicsHandler
      Parameters:
      rotationImpulse - der Drehimpuls, der auf das Ziel-Objekt wirken soll. in [kg*m*m/s]
    • bodyType

      public void bodyType(BodyType type)
      Macht ein Type-Update für diesen Handler.
      Specified by:
      bodyType in interface pi.physics.PhysicsHandler
      Parameters:
      type - Der neue Type.
    • bodyType

      public BodyType bodyType()
      Specified by:
      bodyType in interface pi.physics.PhysicsHandler
    • applyForce

      public void applyForce(Vector forceInN, Vector globalLocation)
      Specified by:
      applyForce in interface pi.physics.PhysicsHandler
    • applyImpulse

      public void applyImpulse(Vector impulseInNs, Vector globalLocation)
      Wirkt einen Impuls auf einem Welt-Point.
      Specified by:
      applyImpulse in interface pi.physics.PhysicsHandler
      Parameters:
      impulseInNs - Ein Impuls (in [Ns]).
      globalLocation - TODO
    • resetMovement

      public void resetMovement()
      Setzt die Wirkung aller physikalischer Bewegungen (Geschwindigkeit und Drehung) zurück. Hiernach ist das Objekt in Ruhe.
      Specified by:
      resetMovement in interface pi.physics.PhysicsHandler
    • velocity

      public void velocity(Vector metersPerSecond)
      Setzt die Geschwindigkeit für das Handler-Objekt.
      Specified by:
      velocity in interface pi.physics.PhysicsHandler
      Parameters:
      metersPerSecond - Setzt die Geschwindigkeit, mit der sich das Zielobjekt bewegen soll.
    • velocity

      public Vector velocity()
      Gibt die aktuelle Geschwindigkeit aus.
      Specified by:
      velocity in interface pi.physics.PhysicsHandler
      Returns:
      Die aktuelle Geschwindigkeit.
    • angularVelocity

      public void angularVelocity(double rotationsPerSecond)
      Setzt die Drehgeschwindigkeit für das Handler-Objekt.
      Specified by:
      angularVelocity in interface pi.physics.PhysicsHandler
      Parameters:
      rotationsPerSecond - Setzt die Drehgeschwindigkeit, mit der sich das Zielobjekt bewegen soll.
    • angularVelocity

      public double angularVelocity()
      Gibt die aktuelle Drehgeschwindigkeit aus.
      Specified by:
      angularVelocity in interface pi.physics.PhysicsHandler
      Returns:
      Die aktuelle Drehgeschwindigkeit.
    • rotationLocked

      public void rotationLocked(boolean locked)
      Setzt, ob die Rotation blockiert sein soll.
      Specified by:
      rotationLocked in interface pi.physics.PhysicsHandler
    • isRotationLocked

      public boolean isRotationLocked()
      Specified by:
      isRotationLocked in interface pi.physics.PhysicsHandler
      Returns:
      Ob die Rotation des Objekts blockiert ist.
    • isGrounded

      public boolean isGrounded()
      Testet, ob das Objekt unter sich festen Boden hat. Dies ist der Fall, wenn direkt unter dem Objekt ein passives Objekt liegt.
      Diese Methode geht bei unten explizit von "unterhalb der Y-Achse" aus. Ein Objekt hat also Boden sich, wenn am "unteren" Ende seines Bodies (=höchster Y-Wert) in unmittelbarer Nähe (heuristisch getestet) ein passives Objekt anliegt.
      Specified by:
      isGrounded in interface pi.physics.PhysicsHandler
      Returns:
      true, wenn direkt unter dem Objekt ein passives Objekt ist. Sonst false.
    • fixtures

      public void fixtures(Supplier<List<FixtureData>> fixtures)
      Entfernt alle Fixtures/Collider am Actor und setzt alle Fixturs für dieses Objekt neu.
      Specified by:
      fixtures in interface pi.physics.PhysicsHandler
      Parameters:
      fixtures - Die neuen Fixtures als Supplier, der die Liste der Fixtures ausgibt.
    • applyMountCallbacks

      public void applyMountCallbacks(pi.physics.PhysicsHandler otherHandler)
      Specified by:
      applyMountCallbacks in interface pi.physics.PhysicsHandler
    • collisions

      public List<CollisionEvent<Actor>> collisions()
      Specified by:
      collisions in interface pi.physics.PhysicsHandler
    • worldHandler

      public WorldHandler worldHandler()
      Gibt den WorldHandler aus, der die Welt handelt, in der sich der Klient befindet.
      Specified by:
      worldHandler in interface pi.physics.PhysicsHandler
      Returns:
      Der World-Handler, der zu diesem Physics-Handler gehört.
    • awake

      public void awake(boolean value)
      Legt den Schlafzustand des Körpers fest. Ein schlafender Körper hat sehr geringe CPU-Kosten.

      Das Versetzen in den Schlafzustand setzt die Geschwindigkeit und den Impuls eines Körpers auf null.

      Specified by:
      awake in interface pi.physics.PhysicsHandler
      Parameters:
      value - Der Schlafzustand des Körpers.