Class VerletPhysics2D

java.lang.Object
toxi.physics2d.VerletPhysics2D

public class VerletPhysics2D extends Object
3D particle physics engine using Verlet integration based on: http://en.wikipedia.org/wiki/Verlet_integration http://www.teknikus.dk/tj/gdc2001.htm
  • Field Details

  • Constructor Details

    • VerletPhysics2D

      public VerletPhysics2D()
      Initializes a Verlet engine instance using the default values.
    • VerletPhysics2D

      public VerletPhysics2D(Vec2D gravity, int numIterations, float drag, float timeStep)
      Initializes an Verlet engine instance with the passed in configuration.
      Parameters:
      gravity - 3D gravity vector
      numIterations - iterations per time step for verlet solver
      drag - drag value 0...1
      timeStep - time step for calculating forces
  • Method Details

    • addConstraintToAll

      public static void addConstraintToAll(ParticleConstraint2D c, List<VerletParticle2D> list)
    • removeConstraintFromAll

      public static void removeConstraintFromAll(ParticleConstraint2D c, List<VerletParticle2D> list)
    • addBehavior

      public void addBehavior(ParticleBehavior2D behavior)
    • addConstraint

      public void addConstraint(ParticleConstraint2D constraint)
    • addParticle

      public VerletPhysics2D addParticle(VerletParticle2D p)
      Adds a particle to the list
      Parameters:
      p -
      Returns:
      itself
    • addSpring

      public VerletPhysics2D addSpring(VerletSpring2D s)
      Adds a spring connector
      Parameters:
      s -
      Returns:
      itself
    • clear

      public VerletPhysics2D clear()
    • getCurrentBounds

      public Rect getCurrentBounds()
    • getDrag

      public float getDrag()
    • getIndex

      public SpatialIndex<Vec2D> getIndex()
      Returns:
      the index
    • getNumIterations

      public int getNumIterations()
      Returns:
      the numIterations
    • getSpring

      public VerletSpring2D getSpring(Vec2D a, Vec2D b)
      Attempts to find the spring element between the 2 particles supplied
      Parameters:
      a - particle 1
      b - particle 2
      Returns:
      spring instance, or null if not found
    • getTimeStep

      public float getTimeStep()
      Returns:
      the timeStep
    • getWorldBounds

      public Rect getWorldBounds()
      Returns:
      the worldBounds
    • removeBehavior

      public boolean removeBehavior(ParticleBehavior2D c)
    • removeConstraint

      public boolean removeConstraint(ParticleConstraint2D c)
    • removeParticle

      public boolean removeParticle(VerletParticle2D p)
      Removes a particle from the simulation.
      Parameters:
      p - particle to remove
      Returns:
      true, if removed successfully
    • removeSpring

      public boolean removeSpring(VerletSpring2D s)
      Removes a spring connector from the simulation instance.
      Parameters:
      s - spring to remove
      Returns:
      true, if the spring has been removed
    • removeSpringElements

      public boolean removeSpringElements(VerletSpring2D s)
      Removes a spring connector and its both end point particles from the simulation
      Parameters:
      s - spring to remove
      Returns:
      true, only if spring AND particles have been removed successfully
    • setDrag

      public void setDrag(float drag)
    • setIndex

      public void setIndex(SpatialIndex<Vec2D> index)
      Parameters:
      index - the index to set
    • setNumIterations

      public void setNumIterations(int numIterations)
      Parameters:
      numIterations - the numIterations to set
    • setTimeStep

      public void setTimeStep(float timeStep)
      Parameters:
      timeStep - the timeStep to set
    • setWorldBounds

      public VerletPhysics2D setWorldBounds(Rect world)
      Sets bounding box
      Parameters:
      world -
      Returns:
      itself
    • update

      public VerletPhysics2D update()
      Progresses the physics simulation by 1 time step and updates all forces and particle positions accordingly
      Returns:
      itself